11#pragma once
22
3- #include " datashard_user_table.h"
4-
5- #include < ydb/core/scheme/scheme_pathid.h>
63#include < ydb/core/scheme/scheme_tablecell.h>
74
85#include < util/generic/maybe.h>
@@ -12,12 +9,12 @@ namespace NKikimrChangeExchange {
129 class TChangeRecord ;
1310}
1411
15- namespace NKikimr ::NDataShard {
12+ namespace NKikimr ::NChangeExchange {
1613
17- class TChangeRecordBuilder ;
14+ template < typename T, typename TDerived> class TChangeRecordBuilder ;
1815
1916class TChangeRecord {
20- friend class TChangeRecordBuilder ;
17+ template < typename T, typename TDerived> friend class TChangeRecordBuilder ;
2118
2219public:
2320 enum class ESource : ui8 {
@@ -36,50 +33,37 @@ class TChangeRecord {
3633 ui64 GetGroup () const { return Group; }
3734 ui64 GetStep () const { return Step; }
3835 ui64 GetTxId () const { return TxId; }
39- ui64 GetLockId () const { return LockId; }
40- ui64 GetLockOffset () const { return LockOffset; }
41- const TPathId& GetPathId () const { return PathId; }
4236 EKind GetKind () const { return Kind; }
4337 const TString& GetBody () const { return Body; }
4438 ESource GetSource () const { return Source; }
4539
46- const TPathId& GetTableId () const { return TableId; }
47- ui64 GetSchemaVersion () const { return SchemaVersion; }
48- TUserTable::TCPtr GetSchema () const { return Schema; }
49-
5040 void Serialize (NKikimrChangeExchange::TChangeRecord& record) const ;
5141
5242 TConstArrayRef<TCell> GetKey () const ;
5343 i64 GetSeqNo () const ;
54- TString GetPartitionKey () const ;
5544 TInstant GetApproximateCreationDateTime () const ;
56- bool IsBroadcast () const ;
5745
5846 TString ToString () const ;
5947 void Out (IOutputStream& out) const ;
6048
61- private :
49+ protected :
6250 ui64 Order = Max<ui64>();
6351 ui64 Group = 0 ;
6452 ui64 Step = 0 ;
6553 ui64 TxId = 0 ;
66- ui64 LockId = 0 ;
67- ui64 LockOffset = 0 ;
68- TPathId PathId;
6954 EKind Kind;
7055 TString Body;
7156 ESource Source = ESource::Unspecified;
7257
73- ui64 SchemaVersion;
74- TPathId TableId;
75- TUserTable::TCPtr Schema;
76-
7758 mutable TMaybe<TOwnedCellVec> Key;
7859 mutable TMaybe<TString> PartitionKey;
7960
8061}; // TChangeRecord
8162
63+ template <typename T, typename TDerived>
8264class TChangeRecordBuilder {
65+ protected:
66+ using TSelf = TDerived;
8367 using EKind = TChangeRecord::EKind;
8468 using ESource = TChangeRecord::ESource;
8569
@@ -88,87 +72,56 @@ class TChangeRecordBuilder {
8872 Record.Kind = kind;
8973 }
9074
91- explicit TChangeRecordBuilder (TChangeRecord&& record)
92- : Record(std::move(record))
93- {
94- }
95-
96- TChangeRecordBuilder& WithLockId (ui64 lockId) {
97- Record.LockId = lockId;
98- return *this ;
99- }
100-
101- TChangeRecordBuilder& WithLockOffset (ui64 lockOffset) {
102- Record.LockOffset = lockOffset;
103- return *this ;
75+ explicit TChangeRecordBuilder (T&& record) {
76+ Record = std::move (record);
10477 }
10578
106- TChangeRecordBuilder & WithOrder (ui64 order) {
79+ TSelf & WithOrder (ui64 order) {
10780 Record.Order = order;
108- return *this ;
81+ return static_cast <TSelf&>( *this ) ;
10982 }
11083
111- TChangeRecordBuilder & WithGroup (ui64 group) {
84+ TSelf & WithGroup (ui64 group) {
11285 Record.Group = group;
113- return *this ;
86+ return static_cast <TSelf&>( *this ) ;
11487 }
11588
116- TChangeRecordBuilder & WithStep (ui64 step) {
89+ TSelf & WithStep (ui64 step) {
11790 Record.Step = step;
118- return *this ;
91+ return static_cast <TSelf&>( *this ) ;
11992 }
12093
121- TChangeRecordBuilder & WithTxId (ui64 txId) {
94+ TSelf & WithTxId (ui64 txId) {
12295 Record.TxId = txId;
123- return *this ;
124- }
125-
126- TChangeRecordBuilder& WithPathId (const TPathId& pathId) {
127- Record.PathId = pathId;
128- return *this ;
129- }
130-
131- TChangeRecordBuilder& WithTableId (const TPathId& tableId) {
132- Record.TableId = tableId;
133- return *this ;
134- }
135-
136- TChangeRecordBuilder& WithSchemaVersion (ui64 version) {
137- Record.SchemaVersion = version;
138- return *this ;
139- }
140-
141- TChangeRecordBuilder& WithSchema (TUserTable::TCPtr schema) {
142- Record.Schema = schema;
143- return *this ;
96+ return static_cast <TSelf&>(*this );
14497 }
14598
146- TChangeRecordBuilder & WithBody (const TString& body) {
99+ TSelf & WithBody (const TString& body) {
147100 Record.Body = body;
148- return *this ;
101+ return static_cast <TSelf&>( *this ) ;
149102 }
150103
151- TChangeRecordBuilder & WithBody (TString&& body) {
104+ TSelf & WithBody (TString&& body) {
152105 Record.Body = std::move (body);
153- return *this ;
106+ return static_cast <TSelf&>( *this ) ;
154107 }
155108
156- TChangeRecordBuilder & WithSource (ESource source) {
109+ TSelf & WithSource (ESource source) {
157110 Record.Source = source;
158- return *this ;
111+ return static_cast <TSelf&>( *this ) ;
159112 }
160113
161- TChangeRecord && Build() {
114+ T && Build() {
162115 return std::move (Record);
163116 }
164117
165- private :
166- TChangeRecord Record;
118+ protected :
119+ T Record;
167120
168121}; // TChangeRecordBuilder
169122
170123}
171124
172- Y_DECLARE_OUT_SPEC (inline , NKikimr::NDataShard ::TChangeRecord, out, value) {
125+ Y_DECLARE_OUT_SPEC (inline , NKikimr::NChangeExchange ::TChangeRecord, out, value) {
173126 return value.Out (out);
174127}
0 commit comments