Skip to content

Commit

Permalink
gc simplification and avoid race with reduce barrier for cleanup (#5175)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmorozov333 authored Jun 5, 2024
1 parent 7fc48b8 commit fea1683
Show file tree
Hide file tree
Showing 21 changed files with 309 additions and 152 deletions.
1 change: 1 addition & 0 deletions ydb/core/protos/counters_columnshard.proto
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,5 @@ enum ETxTypes {
TXTYPE_ADD_BACKGROUND_SESSION = 31 [(TxTypeOpts) = {Name: "TxAddBackgroundSession"}];
TXTYPE_SAVE_BACKGROUND_SESSION_PROGRESS = 32 [(TxTypeOpts) = {Name: "TxSaveBackgroundSessionProgress"}];
TXTYPE_SAVE_BACKGROUND_SESSION_STATE = 33 [(TxTypeOpts) = {Name: "TxSaveBackgroundSessionState"}];
TXTYPE_GC_START = 34 [(TxTypeOpts) = {Name: "TxGarbageCollectionStart"}];
}
14 changes: 14 additions & 0 deletions ydb/core/tx/columnshard/blobs_action/abstract/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ void IBlobsGCAction::OnExecuteTxAfterCleaning(NColumnShard::TColumnShard& self,
}
}

void IBlobsGCAction::OnCompleteTxBeforeCleaning(NColumnShard::TColumnShard& self, const std::shared_ptr<IBlobsGCAction>& taskAction) {
if (!AbortedFlag) {
if (!DoOnCompleteTxAfterCleaning(self, taskAction)) {
return;
}
}
}

void IBlobsGCAction::OnExecuteTxBeforeCleaning(NColumnShard::TColumnShard& self, TBlobManagerDb& dbBlobs) {
if (!AbortedFlag) {
return DoOnExecuteTxAfterCleaning(self, dbBlobs);
}
}

void IBlobsGCAction::Abort() {
Y_ABORT_UNLESS(IsInProgress());
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "gc_aborted")("action_guid", GetActionGuid());
Expand Down
7 changes: 7 additions & 0 deletions ydb/core/tx/columnshard/blobs_action/abstract/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ class IBlobsGCAction: public ICommonBlobsAction {

virtual void DoOnExecuteTxAfterCleaning(NColumnShard::TColumnShard& self, TBlobManagerDb& dbBlobs) = 0;
virtual bool DoOnCompleteTxAfterCleaning(NColumnShard::TColumnShard& self, const std::shared_ptr<IBlobsGCAction>& taskAction) = 0;

virtual void DoOnExecuteTxBeforeCleaning(NColumnShard::TColumnShard& self, TBlobManagerDb& dbBlobs) = 0;
virtual bool DoOnCompleteTxBeforeCleaning(NColumnShard::TColumnShard& self, const std::shared_ptr<IBlobsGCAction>& taskAction) = 0;

virtual void RemoveBlobIdFromDB(const TTabletId tabletId, const TUnifiedBlobId& blobId, TBlobManagerDb& dbBlobs) = 0;
virtual bool DoIsEmpty() const = 0;
public:
void OnExecuteTxAfterCleaning(NColumnShard::TColumnShard& self, TBlobManagerDb& dbBlobs);
void OnCompleteTxAfterCleaning(NColumnShard::TColumnShard& self, const std::shared_ptr<IBlobsGCAction>& taskAction);

void OnExecuteTxBeforeCleaning(NColumnShard::TColumnShard& self, TBlobManagerDb& dbBlobs);
void OnCompleteTxBeforeCleaning(NColumnShard::TColumnShard& self, const std::shared_ptr<IBlobsGCAction>& taskAction);

const TBlobsCategories& GetBlobsToRemove() const {
return BlobsToRemove;
}
Expand Down
32 changes: 21 additions & 11 deletions ydb/core/tx/columnshard/blobs_action/abstract/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ class IBlobsStorageOperator {
return "";
}

virtual std::shared_ptr<IBlobsGCAction> DoStartGCAction(const std::shared_ptr<NBlobOperations::TRemoveGCCounters>& counters) const = 0;
std::shared_ptr<IBlobsGCAction> StartGCAction(const std::shared_ptr<NBlobOperations::TRemoveGCCounters>& counters) const {
return DoStartGCAction(counters);
virtual void DoStartGCAction(const std::shared_ptr<IBlobsGCAction>& counters) const = 0;

void StartGCAction(const std::shared_ptr<IBlobsGCAction>& action) const {
return DoStartGCAction(action);
}

virtual std::shared_ptr<IBlobsGCAction> DoCreateGCAction(const std::shared_ptr<NBlobOperations::TRemoveGCCounters>& counters) const = 0;
std::shared_ptr<IBlobsGCAction> CreateGCAction(const std::shared_ptr<NBlobOperations::TRemoveGCCounters>& counters) const {
return DoCreateGCAction(counters);
}

public:
Expand Down Expand Up @@ -101,22 +107,26 @@ class IBlobsStorageOperator {
result->SetCounters(Counters->GetConsumerCounter(consumerId)->GetReadCounters());
return result;
}
bool StartGC() {

void StartGC(const std::shared_ptr<IBlobsGCAction>& action) {
AFL_VERIFY(CurrentGCAction == action);
AFL_VERIFY(!!action && action->IsInProgress());
StartGCAction(action);
}

[[nodiscard]] std::shared_ptr<IBlobsGCAction> CreateGC() {
NActors::TLogContextGuard gLogging = NActors::TLogContextBuilder::Build(NKikimrServices::TX_COLUMNSHARD)("storage_id", GetStorageId())("tablet_id", GetSelfTabletId());
if (CurrentGCAction && CurrentGCAction->IsInProgress()) {
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "gc_in_progress");
return false;
return nullptr;
}
if (Stopped) {
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "stopped_on_gc");
return false;
}
auto task = StartGCAction(Counters->GetConsumerCounter(NBlobOperations::EConsumer::GC)->GetRemoveGCCounters());
if (!task) {
return false;
return nullptr;
}
auto task = CreateGCAction(Counters->GetConsumerCounter(NBlobOperations::EConsumer::GC)->GetRemoveGCCounters());
CurrentGCAction = task;
return true;
return CurrentGCAction;
}
};

Expand Down
24 changes: 21 additions & 3 deletions ydb/core/tx/columnshard/blobs_action/blob_manager_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,34 @@ namespace NKikimr::NOlap {

using namespace NKikimr::NColumnShard;

bool TBlobManagerDb::LoadGCBarrierPreparation(TGenStep& genStep) {
ui64 gen = 0;
ui64 step = 0;
NIceDb::TNiceDb db(Database);
if (!Schema::GetSpecialValueOpt(db, Schema::EValueIds::GCBarrierPreparationGen, gen) ||
!Schema::GetSpecialValueOpt(db, Schema::EValueIds::GCBarrierPreparationStep, step))
{
return false;
}
genStep = TGenStep(gen, step);
return true;
}

void TBlobManagerDb::SaveGCBarrierPreparation(const TGenStep& genStep) {
NIceDb::TNiceDb db(Database);
Schema::SaveSpecialValue(db, Schema::EValueIds::GCBarrierPreparationGen, std::get<0>(genStep));
Schema::SaveSpecialValue(db, Schema::EValueIds::GCBarrierPreparationStep, std::get<1>(genStep));
}

bool TBlobManagerDb::LoadLastGcBarrier(TGenStep& lastCollectedGenStep) {
NIceDb::TNiceDb db(Database);
ui64 gen = 0;
ui64 step = 0;
if (!Schema::GetSpecialValueOpt(db, Schema::EValueIds::LastGcBarrierGen, gen) ||
!Schema::GetSpecialValueOpt(db, Schema::EValueIds::LastGcBarrierStep, step))
{
!Schema::GetSpecialValueOpt(db, Schema::EValueIds::LastGcBarrierStep, step)) {
return false;
}
lastCollectedGenStep = {gen, step};
lastCollectedGenStep = { gen, step };
return true;
}

Expand Down
5 changes: 5 additions & 0 deletions ydb/core/tx/columnshard/blobs_action/blob_manager_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class IBlobManagerDb {
public:
virtual ~IBlobManagerDb() = default;

[[nodiscard]] virtual bool LoadGCBarrierPreparation(TGenStep& genStep) = 0;
virtual void SaveGCBarrierPreparation(const TGenStep& genStep) = 0;
[[nodiscard]] virtual bool LoadLastGcBarrier(TGenStep& lastCollectedGenStep) = 0;
virtual void SaveLastGcBarrier(const TGenStep& lastCollectedGenStep) = 0;

Expand Down Expand Up @@ -54,6 +56,9 @@ class TBlobManagerDb : public IBlobManagerDb {
[[nodiscard]] bool LoadLastGcBarrier(TGenStep& lastCollectedGenStep) override;
void SaveLastGcBarrier(const TGenStep& lastCollectedGenStep) override;

[[nodiscard]] bool LoadGCBarrierPreparation(TGenStep& genStep) override;
void SaveGCBarrierPreparation(const TGenStep& genStep) override;

[[nodiscard]] bool LoadLists(std::vector<TUnifiedBlobId>& blobsToKeep, TTabletsByBlob& blobsToDelete,
const IBlobGroupSelector* dsGroupSelector, const TTabletId selfTabletId) override;

Expand Down
Loading

0 comments on commit fea1683

Please sign in to comment.