Skip to content

Commit 8e785a7

Browse files
author
Matveev Sergei
committed
remove race
1 parent eb9430d commit 8e785a7

File tree

2 files changed

+64
-11
lines changed

2 files changed

+64
-11
lines changed

ydb/core/tx/columnshard/engines/portions/portion_info.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ TString TPortionInfo::DebugString(const bool withDetails) const {
3838
sb << "column_size:" << GetColumnBlobBytes() << ";"
3939
<< "index_size:" << GetIndexBlobBytes() << ";"
4040
<< "meta:(" << Meta.DebugString() << ");";
41-
if (RemoveSnapshot.Valid()) {
41+
if (HasRemoveSnapshot()) {
4242
sb << "remove_snapshot:(" << RemoveSnapshot.DebugString() << ");";
4343
}
4444
return sb << ")";
@@ -56,7 +56,7 @@ void TPortionInfo::SerializeToProto(const std::vector<TUnifiedBlobId>& blobIds,
5656
PathId.ToProto(proto);
5757
proto.SetPortionId(PortionId);
5858
proto.SetSchemaVersion(GetSchemaVersionVerified());
59-
if (!RemoveSnapshot.IsZero()) {
59+
if (HasRemoveSnapshot()) {
6060
*proto.MutableRemoveSnapshot() = RemoveSnapshot.SerializeToProto();
6161
}
6262

@@ -75,6 +75,7 @@ TConclusionStatus TPortionInfo::DeserializeFromProto(const NKikimrColumnShardDat
7575
if (!parse) {
7676
return parse;
7777
}
78+
RemoveSnapshotDefined.store(true, std::memory_order_release);
7879
}
7980
return TConclusionStatus::Success();
8081
}

ydb/core/tx/columnshard/engines/portions/portion_info.h

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <ydb/library/formats/arrow/replace_key.h>
1414

1515
#include <util/generic/hash_set.h>
16+
#include <atomic>
1617

1718
namespace NKikimrColumnShardDataSharingProto {
1819
class TPortionInfo;
@@ -84,12 +85,37 @@ class TPortionInfo {
8485
friend class TCompactedPortionInfo;
8586
friend class TWrittenPortionInfo;
8687

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+
}
89114

90115
TInternalPathId PathId;
91116
ui64 PortionId = 0; // Id of independent (overlayed by PK) portion of data in pathId
92117
TSnapshot RemoveSnapshot = TSnapshot::Zero();
118+
std::atomic<bool> RemoveSnapshotDefined = false;
93119
ui64 SchemaVersion = 0;
94120
std::optional<ui64> ShardingVersion;
95121

@@ -167,8 +193,33 @@ class TPortionInfo {
167193
TPortionInfo(TPortionMeta&& meta)
168194
: Meta(std::move(meta)) {
169195
}
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+
}
172223

173224
virtual void FillDefaultColumn(NAssembling::TColumnAssemblingInfo& column, const std::optional<TSnapshot>& defaultSnapshot) const = 0;
174225

@@ -213,8 +264,9 @@ class TPortionInfo {
213264
}
214265

215266
void SetRemoveSnapshot(const TSnapshot& snap) {
216-
AFL_VERIFY(!RemoveSnapshot.Valid());
267+
AFL_VERIFY(!RemoveSnapshotDefined.load());
217268
RemoveSnapshot = snap;
269+
RemoveSnapshotDefined.store(true, std::memory_order_release);
218270
}
219271

220272
void SetRemoveSnapshot(const ui64 planStep, const ui64 txId) {
@@ -339,7 +391,7 @@ class TPortionInfo {
339391
TString DebugString(const bool withDetails = false) const;
340392

341393
bool HasRemoveSnapshot() const {
342-
return RemoveSnapshot.Valid();
394+
return RemoveSnapshotDefined.load(std::memory_order_acquire);
343395
}
344396

345397
bool IsRemovedFor(const TSnapshot& snapshot) const {
@@ -375,12 +427,12 @@ class TPortionInfo {
375427
}
376428

377429
const TSnapshot& GetRemoveSnapshotVerified() const {
378-
AFL_VERIFY(HasRemoveSnapshot());
430+
AFL_VERIFY(RemoveSnapshotDefined.load(std::memory_order_acquire));
379431
return RemoveSnapshot;
380432
}
381433

382434
std::optional<TSnapshot> GetRemoveSnapshotOptional() const {
383-
if (RemoveSnapshot.Valid()) {
435+
if (RemoveSnapshotDefined.load(std::memory_order_acquire)) {
384436
return RemoveSnapshot;
385437
} else {
386438
return {};
@@ -393,7 +445,7 @@ class TPortionInfo {
393445
}
394446

395447
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);
397449

398450
AFL_TRACE(NKikimrServices::TX_COLUMNSHARD)("event", "IsVisible")("analyze_portion", DebugString())("visible", visible)(
399451
"snapshot", snapshot.DebugString());

0 commit comments

Comments
 (0)