aboutsummaryrefslogtreecommitdiffstats
path: root/ydb/core/tx/datashard/change_record.h
blob: 7c88bb8b6636ea94316bbd2cb38e5e24383586b4 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once

#include <ydb/core/base/pathid.h>
#include <ydb/core/scheme/scheme_tablecell.h>

#include <util/generic/maybe.h>
#include <util/generic/string.h>

namespace NKikimrChangeExchange {
    class TChangeRecord;
}

namespace NKikimr {
namespace NDataShard {

class TChangeRecordBuilder;

class TChangeRecord {
    friend class TChangeRecordBuilder;

public:
    enum class EKind: ui8 {
        AsyncIndex,
        CdcDataChange,
    };

public:
    ui64 GetOrder() const { return Order; }
    ui64 GetGroup() const { return Group; }
    ui64 GetStep() const { return Step; }
    ui64 GetTxId() const { return TxId; }
    const TPathId& GetPathId() const { return PathId; }
    EKind GetKind() const { return Kind; }
    const TString& GetBody() const { return Body; }
    i64 GetSeqNo() const;
    TConstArrayRef<TCell> GetKey() const;

    void SerializeTo(NKikimrChangeExchange::TChangeRecord& record) const;

    TString ToString() const;
    void Out(IOutputStream& out) const;

private:
    ui64 Order;
    ui64 Group;
    ui64 Step;
    ui64 TxId;
    TPathId PathId;
    EKind Kind;
    TString Body;

    mutable TMaybe<TOwnedCellVec> Key;

}; // TChangeRecord

class TChangeRecordBuilder {
    using EKind = TChangeRecord::EKind;

public:
    explicit TChangeRecordBuilder(EKind kind);

    TChangeRecordBuilder& WithOrder(ui64 order);
    TChangeRecordBuilder& WithGroup(ui64 group);
    TChangeRecordBuilder& WithStep(ui64 step);
    TChangeRecordBuilder& WithTxId(ui64 txId);
    TChangeRecordBuilder& WithPathId(const TPathId& pathId);

    TChangeRecordBuilder& WithBody(const TString& body);
    TChangeRecordBuilder& WithBody(TString&& body);

    TChangeRecord&& Build();

private:
    TChangeRecord Record;

}; // TChangeRecordBuilder

} // NDataShard
} // NKikimr

Y_DECLARE_OUT_SPEC(inline, NKikimr::NDataShard::TChangeRecord, out, value) {
    return value.Out(out);
}