aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Common/TransactionID.cpp
blob: 8a9894fbe53e2797a5a6095525ff18bf21c4720c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <Common/TransactionID.h>
#include <Common/SipHash.h>
#include <IO/ReadHelpers.h>
#include <IO/WriteHelpers.h>

namespace DB
{

TIDHash TransactionID::getHash() const
{
    SipHash hash;
    hash.update(start_csn);
    hash.update(local_tid);
    hash.update(host_id);
    return hash.get64();
}


void TransactionID::write(const TransactionID & tid, WriteBuffer & buf)
{
    writeChar('(', buf);
    writeText(tid.start_csn, buf);
    writeCString(", ", buf);
    writeText(tid.local_tid, buf);
    writeCString(", ", buf);
    writeText(tid.host_id, buf);
    writeChar(')', buf);
}

TransactionID TransactionID::read(ReadBuffer & buf)
{
    TransactionID tid = Tx::EmptyTID;
    assertChar('(', buf);
    readText(tid.start_csn, buf);
    assertString(", ", buf);
    readText(tid.local_tid, buf);
    assertString(", ", buf);
    readText(tid.host_id, buf);
    assertChar(')', buf);
    return tid;
}

}