Skip to content

Commit

Permalink
fix validation in case removed table indexation (#12541)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmorozov333 authored Dec 12, 2024
1 parent 5dba14e commit cd3d76a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions ydb/core/tx/columnshard/engines/changes/indexation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ TConclusionStatus TInsertColumnEngineChanges::DoConstructBlobs(TConstructionCont
}
pathBatches.AddChunkInfo(inserted, context);
}
NoAppendIsCorrect = pathBatches.GetData().empty();

pathBatches.FinishChunksInfo();

Expand Down
2 changes: 1 addition & 1 deletion ydb/core/tx/columnshard/engines/changes/with_appended.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void TChangesWithAppend::DoWriteIndexOnComplete(NColumnShard::TColumnShard* self
}

void TChangesWithAppend::DoCompile(TFinalizationContext& context) {
AFL_VERIFY(PortionsToRemove.size() + PortionsToMove.size() + AppendedPortions.size());
AFL_VERIFY(PortionsToRemove.size() + PortionsToMove.size() + AppendedPortions.size() || NoAppendIsCorrect);
for (auto&& i : AppendedPortions) {
i.GetPortionConstructor().MutablePortionConstructor().SetPortionId(context.NextPortionId());
i.GetPortionConstructor().MutablePortionConstructor().MutableMeta().SetCompactionLevel(TargetCompactionLevel.value_or(0));
Expand Down
12 changes: 11 additions & 1 deletion ydb/core/tx/columnshard/engines/changes/with_appended.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ class TChangesWithAppend: public TColumnEngineChanges {
THashMap<TPortionAddress, std::shared_ptr<const TPortionInfo>> PortionsToMove;

protected:
std::vector<TWritePortionInfoWithBlobsResult> AppendedPortions;
std::optional<ui64> TargetCompactionLevel;
TSaverContext SaverContext;
bool NoAppendIsCorrect = false;

virtual void OnDataAccessorsInitialized(const TDataAccessorsInitializationContext& /*context*/) override {

}
Expand Down Expand Up @@ -58,6 +61,14 @@ class TChangesWithAppend: public TColumnEngineChanges {

}

const std::vector<TWritePortionInfoWithBlobsResult>& GetAppendedPortions() const {
return AppendedPortions;
}

std::vector<TWritePortionInfoWithBlobsResult>& MutableAppendedPortions() {
return AppendedPortions;
}

void AddMovePortions(const std::vector<std::shared_ptr<TPortionInfo>>& portions) {
for (auto&& i : portions) {
AFL_VERIFY(i);
Expand Down Expand Up @@ -90,7 +101,6 @@ class TChangesWithAppend: public TColumnEngineChanges {
}
}

std::vector<TWritePortionInfoWithBlobsResult> AppendedPortions;
virtual ui32 GetWritePortionsCount() const override {
return AppendedPortions.size();
}
Expand Down
10 changes: 5 additions & 5 deletions ydb/core/tx/columnshard/engines/ut/ut_logs_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,14 @@ bool Insert(TColumnEngineForLogs& engine, TTestDbWrapper& db, TSnapshot snap, st
NOlap::TConstructionContext context(engine.GetVersionedIndex(), NColumnShard::TIndexationCounters("Indexation"), snap);
Y_ABORT_UNLESS(changes->ConstructBlobs(context).Ok());

UNIT_ASSERT_VALUES_EQUAL(changes->AppendedPortions.size(), 1);
UNIT_ASSERT_VALUES_EQUAL(changes->GetAppendedPortions().size(), 1);
ui32 blobsCount = 0;
for (auto&& i : changes->AppendedPortions) {
for (auto&& i : changes->GetAppendedPortions()) {
blobsCount += i.GetBlobs().size();
}
UNIT_ASSERT_VALUES_EQUAL(blobsCount, 1); // add 2 columns: planStep, txId

AddIdsToBlobs(changes->AppendedPortions, blobs, step);
AddIdsToBlobs(changes->MutableAppendedPortions(), blobs, step);

const bool result = engine.ApplyChangesOnTxCreate(changes, snap) && engine.ApplyChangesOnExecute(db, changes, snap);

Expand Down Expand Up @@ -390,7 +390,7 @@ bool Compact(TColumnEngineForLogs& engine, TTestDbWrapper& db, TSnapshot snap, N
Y_ABORT_UNLESS(changes->ConstructBlobs(context).Ok());

// UNIT_ASSERT_VALUES_EQUAL(changes->AppendedPortions.size(), expected.NewPortions);
AddIdsToBlobs(changes->AppendedPortions, changes->Blobs, step);
AddIdsToBlobs(changes->MutableAppendedPortions(), changes->Blobs, step);

// UNIT_ASSERT_VALUES_EQUAL(changes->GetTmpGranuleIds().size(), expected.NewGranules);

Expand All @@ -400,7 +400,7 @@ bool Compact(TColumnEngineForLogs& engine, TTestDbWrapper& db, TSnapshot snap, N
NOlap::TWriteIndexCompleteContext contextComplete(NActors::TActivationContext::AsActorContext(), 0, 0, TDuration::Zero(), engine, snap);
changes->WriteIndexOnComplete(nullptr, contextComplete);
if (blobsPool) {
for (auto&& i : changes->AppendedPortions) {
for (auto&& i : changes->GetAppendedPortions()) {
for (auto&& r : i.GetPortionResult().TestGetRecords()) {
Y_ABORT_UNLESS(blobsPool
->emplace(i.GetPortionResult().GetPortionInfo().RestoreBlobRange(r.BlobRange),
Expand Down
4 changes: 2 additions & 2 deletions ydb/core/tx/columnshard/ut_rw/ut_columnshard_read_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2462,10 +2462,10 @@ Y_UNIT_TEST_SUITE(TColumnShardTestReadWrite) {
// Cerr << "EvWriteIndex" << Endl << *msg->IndexChanges << Endl;

if (auto append = dynamic_pointer_cast<NOlap::TChangesWithAppend>(msg->IndexChanges)) {
Y_ABORT_UNLESS(append->AppendedPortions.size());
Y_ABORT_UNLESS(append->GetAppendedPortions().size());
TStringBuilder sb;
sb << "Added portions:";
for (const auto& portion : append->AppendedPortions) {
for (const auto& portion : append->GetAppendedPortions()) {
Y_UNUSED(portion);
++addedPortions;
sb << " " << addedPortions;
Expand Down

0 comments on commit cd3d76a

Please sign in to comment.