Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fexolm committed Nov 5, 2024
1 parent cfce444 commit 7522317
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion ydb/core/tx/columnshard/engines/column_engine_logs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,17 @@ void TColumnEngineForLogs::RegisterSchemaVersion(const TSnapshot& snapshot, cons
void TColumnEngineForLogs::RegisterOldSchemaVersion(const TSnapshot& snapshot, const TSchemaInitializationData& schema) {
AFL_VERIFY(!VersionedIndex.IsEmpty());

ISnapshotSchema::TPtr prevSchema = VersionedIndex.GetLastSchemaBeforeSnapshot(snapshot);
ISnapshotSchema::TPtr prevSchema = VersionedIndex.GetLastSchemaBeforeOrEqualSnapshotOptional(snapshot);

if (prevSchema && snapshot == prevSchema->GetSnapshot()) {
// skip already registered snapshot
return;
}

ISnapshotSchema::TPtr secondLast = VersionedIndex.GetSecondLastSchemaOptional();

AFL_VERIFY(!secondLast || secondLast->GetSnapshot() < snapshot)("reason", "incorrect schema registration order");

std::optional<NOlap::TIndexInfo> indexInfoOptional;
if (schema.GetDiff()) {
AFL_VERIFY(prevSchema)("reason", "no base schema to apply diff for");
Expand Down
13 changes: 11 additions & 2 deletions ydb/core/tx/columnshard/engines/scheme/versions/versioned_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ class TVersionedIndex {

ISnapshotSchema::TPtr GetSchema(const TSnapshot& version) const {
Y_ABORT_UNLESS(!Snapshots.empty());
ISnapshotSchema::TPtr res = GetLastSchemaBeforeSnapshot(version);
ISnapshotSchema::TPtr res = GetLastSchemaBeforeOrEqualSnapshotOptional(version);
if (!res) {
return Snapshots.begin()->second;
}
return res;
}

ISnapshotSchema::TPtr GetLastSchemaBeforeSnapshot(const TSnapshot& version) const {
ISnapshotSchema::TPtr GetLastSchemaBeforeOrEqualSnapshotOptional(const TSnapshot& version) const {
ISnapshotSchema::TPtr res = nullptr;
for (auto it = Snapshots.begin(); it != Snapshots.end(); ++it) {
if (it->first <= version) {
Expand All @@ -108,6 +108,15 @@ class TVersionedIndex {
return Snapshots.rbegin()->second;
}

ISnapshotSchema::TPtr GetSecondLastSchemaOptional() const {
if (Snapshots.size() < 2) {
return nullptr;
}
auto i = Snapshots.rbegin();
++i;
return i->second;
}

bool IsEmpty() const {
return Snapshots.empty();
}
Expand Down

0 comments on commit 7522317

Please sign in to comment.