13
13
#include < ydb/library/formats/arrow/replace_key.h>
14
14
15
15
#include < util/generic/hash_set.h>
16
+ #include < atomic>
16
17
17
18
namespace NKikimrColumnShardDataSharingProto {
18
19
class TPortionInfo ;
@@ -84,12 +85,37 @@ class TPortionInfo {
84
85
friend class TCompactedPortionInfo ;
85
86
friend class TWrittenPortionInfo ;
86
87
87
- TPortionInfo (const TPortionInfo&) = default ;
88
- TPortionInfo& operator =(const TPortionInfo&) = default ;
88
+ TPortionInfo (const TPortionInfo& other)
89
+ : PathId(other.PathId)
90
+ , PortionId(other.PortionId)
91
+ , RemoveSnapshot(other.RemoveSnapshot)
92
+ , RemoveSnapshotDefined(other.RemoveSnapshotDefined.load(std::memory_order_acquire))
93
+ , SchemaVersion(other.SchemaVersion)
94
+ , ShardingVersion(other.ShardingVersion)
95
+ , Meta(other.Meta)
96
+ , RuntimeFeatures(other.RuntimeFeatures) {
97
+ }
98
+
99
+ TPortionInfo& operator =(const TPortionInfo& other) {
100
+ if (this == &other) {
101
+ return *this ;
102
+ }
103
+
104
+ PathId = other.PathId ;
105
+ PortionId = other.PortionId ;
106
+ RemoveSnapshot = other.RemoveSnapshot ;
107
+ RemoveSnapshotDefined.store (other.RemoveSnapshotDefined .load (std::memory_order_acquire), std::memory_order_release);
108
+ SchemaVersion = other.SchemaVersion ;
109
+ ShardingVersion = other.ShardingVersion ;
110
+ Meta = other.Meta ;
111
+ RuntimeFeatures = other.RuntimeFeatures ;
112
+ return *this ;
113
+ }
89
114
90
115
TInternalPathId PathId;
91
116
ui64 PortionId = 0 ; // Id of independent (overlayed by PK) portion of data in pathId
92
117
TSnapshot RemoveSnapshot = TSnapshot::Zero();
118
+ std::atomic<bool > RemoveSnapshotDefined = false ;
93
119
ui64 SchemaVersion = 0 ;
94
120
std::optional<ui64> ShardingVersion;
95
121
@@ -167,8 +193,33 @@ class TPortionInfo {
167
193
TPortionInfo (TPortionMeta&& meta)
168
194
: Meta(std::move(meta)) {
169
195
}
170
- TPortionInfo (TPortionInfo&&) = default;
171
- TPortionInfo& operator =(TPortionInfo&&) = default ;
196
+
197
+ TPortionInfo (TPortionInfo&& other) noexcept
198
+ : PathId(std::move(other.PathId))
199
+ , PortionId(other.PortionId)
200
+ , RemoveSnapshot(std::move(other.RemoveSnapshot))
201
+ , RemoveSnapshotDefined(other.RemoveSnapshotDefined.load(std::memory_order_acquire))
202
+ , SchemaVersion(other.SchemaVersion)
203
+ , ShardingVersion(std::move(other.ShardingVersion))
204
+ , Meta(std::move(other.Meta))
205
+ , RuntimeFeatures(other.RuntimeFeatures) {
206
+ }
207
+
208
+ TPortionInfo& operator =(TPortionInfo&& other) noexcept {
209
+ if (this == &other) {
210
+ return *this ;
211
+ }
212
+
213
+ PathId = std::move (other.PathId );
214
+ PortionId = other.PortionId ;
215
+ RemoveSnapshot = std::move (other.RemoveSnapshot );
216
+ RemoveSnapshotDefined.store (other.RemoveSnapshotDefined .load (std::memory_order_acquire), std::memory_order_release);
217
+ SchemaVersion = other.SchemaVersion ;
218
+ ShardingVersion = std::move (other.ShardingVersion );
219
+ Meta = std::move (other.Meta );
220
+ RuntimeFeatures = other.RuntimeFeatures ;
221
+ return *this ;
222
+ }
172
223
173
224
virtual void FillDefaultColumn (NAssembling::TColumnAssemblingInfo& column, const std::optional<TSnapshot>& defaultSnapshot) const = 0;
174
225
@@ -213,8 +264,9 @@ class TPortionInfo {
213
264
}
214
265
215
266
void SetRemoveSnapshot (const TSnapshot& snap) {
216
- AFL_VERIFY (!RemoveSnapshot. Valid ());
267
+ AFL_VERIFY (!RemoveSnapshotDefined. load ());
217
268
RemoveSnapshot = snap;
269
+ RemoveSnapshotDefined.store (true , std::memory_order_release);
218
270
}
219
271
220
272
void SetRemoveSnapshot (const ui64 planStep, const ui64 txId) {
@@ -339,7 +391,7 @@ class TPortionInfo {
339
391
TString DebugString (const bool withDetails = false ) const ;
340
392
341
393
bool HasRemoveSnapshot () const {
342
- return RemoveSnapshot. Valid ( );
394
+ return RemoveSnapshotDefined. load (std::memory_order_acquire );
343
395
}
344
396
345
397
bool IsRemovedFor (const TSnapshot& snapshot) const {
@@ -375,12 +427,12 @@ class TPortionInfo {
375
427
}
376
428
377
429
const TSnapshot& GetRemoveSnapshotVerified () const {
378
- AFL_VERIFY (HasRemoveSnapshot ( ));
430
+ AFL_VERIFY (RemoveSnapshotDefined. load (std::memory_order_acquire ));
379
431
return RemoveSnapshot;
380
432
}
381
433
382
434
std::optional<TSnapshot> GetRemoveSnapshotOptional () const {
383
- if (RemoveSnapshot. Valid ( )) {
435
+ if (RemoveSnapshotDefined. load (std::memory_order_acquire )) {
384
436
return RemoveSnapshot;
385
437
} else {
386
438
return {};
@@ -393,7 +445,7 @@ class TPortionInfo {
393
445
}
394
446
395
447
bool IsVisible (const TSnapshot& snapshot, const bool checkCommitSnapshot = true ) const {
396
- const bool visible = (!RemoveSnapshot. Valid ( ) || snapshot < RemoveSnapshot ) && DoIsVisible (snapshot, checkCommitSnapshot);
448
+ const bool visible = (!RemoveSnapshotDefined. load (std::memory_order_acquire ) || snapshot < GetRemoveSnapshotVerified () ) && DoIsVisible (snapshot, checkCommitSnapshot);
397
449
398
450
AFL_TRACE (NKikimrServices::TX_COLUMNSHARD)(" event" , " IsVisible" )(" analyze_portion" , DebugString ())(" visible" , visible)(
399
451
" snapshot" , snapshot.DebugString ());
0 commit comments