Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gc simplification and avoid race with reduce barrier for cleanup #5175

Merged
merged 7 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading