diff --git a/ydb/core/tx/columnshard/blobs_action/bs/blob_manager.cpp b/ydb/core/tx/columnshard/blobs_action/bs/blob_manager.cpp index fbb94f9dfe9f..0cfd793300fb 100644 --- a/ydb/core/tx/columnshard/blobs_action/bs/blob_manager.cpp +++ b/ydb/core/tx/columnshard/blobs_action/bs/blob_manager.cpp @@ -237,7 +237,6 @@ class TBlobManager::TGCContext { // TODO: we need only actual channel history here for (ui32 channelIdx = 2; channelIdx < tabletInfo->Channels.size(); ++channelIdx) { const auto& channelHistory = tabletInfo->ChannelInfo(channelIdx)->History; - for (auto it = channelHistory.begin(); it != channelHistory.end(); ++it) { PerGroupGCListsInFlight[TBlobAddress(it->GroupID, channelIdx)]; } @@ -330,11 +329,6 @@ std::shared_ptr TBlobManager::BuildGCTas PreviousGCTime = AppData()->TimeProvider->Now(); TGCContext gcContext(sharedBlobsInfo); - if (FirstGC) { - gcContext.InitializeFirst(TabletInfo); - FirstGC = false; - } - NActors::TLogContextGuard lGuard = NActors::TLogContextBuilder::Build()("action_id", TGUID::CreateTimebased().AsGuidString()); const std::deque newCollectGenSteps = FindNewGCBarriers(); AFL_VERIFY(newCollectGenSteps.size()); @@ -345,7 +339,9 @@ std::shared_ptr TBlobManager::BuildGCTas if (!DrainKeepTo(newCollectGenStep, gcContext)) { break; } - CollectGenStepInFlight = std::max(CollectGenStepInFlight.value_or(newCollectGenStep), newCollectGenStep); + if (newCollectGenStep.Generation() == CurrentGen) { + CollectGenStepInFlight = std::max(CollectGenStepInFlight.value_or(newCollectGenStep), newCollectGenStep); + } } AFL_VERIFY(LastCollectedGenStep <= CollectGenStepInFlight)("last", LastCollectedGenStep)("collect", CollectGenStepInFlight); } else { @@ -361,22 +357,27 @@ std::shared_ptr TBlobManager::BuildGCTas if (!DrainKeepTo(newCollectGenStep, gcContext)) { break; } - CollectGenStepInFlight = std::max(CollectGenStepInFlight.value_or(newCollectGenStep), newCollectGenStep); + if (newCollectGenStep.Generation() == CurrentGen) { + CollectGenStepInFlight = std::max(CollectGenStepInFlight.value_or(newCollectGenStep), newCollectGenStep); + } } - if (!CollectGenStepInFlight) { - CollectGenStepInFlight = LastCollectedGenStep; + if (CollectGenStepInFlight) { + PopGCBarriers(*CollectGenStepInFlight); + if (FirstGC) { + gcContext.InitializeFirst(TabletInfo); + FirstGC = false; + } } - PopGCBarriers(*CollectGenStepInFlight); AFL_VERIFY(LastCollectedGenStep <= *CollectGenStepInFlight); - AFL_INFO(NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)("notice", "collect_gen_step")("value", *CollectGenStepInFlight)("current_gen", CurrentGen); + AFL_INFO(NKikimrServices::TX_COLUMNSHARD_BLOBS_BS)("notice", "collect_gen_step")("value", CollectGenStepInFlight)("current_gen", CurrentGen); const bool isFull = gcContext.IsFull(); auto removeCategories = sharedBlobsInfo->BuildRemoveCategories(std::move(gcContext.MutableExtractedToRemoveFromDB())); - auto result = std::make_shared(storageId, std::move(gcContext.MutablePerGroupGCListsInFlight()), *CollectGenStepInFlight, - std::move(gcContext.MutableKeepsToErase()), manager, std::move(removeCategories), counters, TabletInfo->TabletID, CurrentGen); + auto result = std::make_shared(storageId, std::move(gcContext.MutablePerGroupGCListsInFlight()), + CollectGenStepInFlight, std::move(gcContext.MutableKeepsToErase()), manager, std::move(removeCategories), counters, TabletInfo->TabletID, CurrentGen); if (result->IsEmpty()) { CollectGenStepInFlight = {}; return nullptr; @@ -467,24 +468,34 @@ void TBlobManager::DeleteBlobOnComplete(const TTabletId tabletId, const TUnified } } -void TBlobManager::OnGCFinishedOnExecute(const TGenStep& genStep, IBlobManagerDb& db) { - db.SaveLastGcBarrier(genStep); +void TBlobManager::OnGCFinishedOnExecute(const std::optional& genStep, IBlobManagerDb& db) { + if (genStep) { + db.SaveLastGcBarrier(*genStep); + } } -void TBlobManager::OnGCFinishedOnComplete(const TGenStep& genStep) { - LastCollectedGenStep = genStep; - AFL_VERIFY(GCBarrierPreparation == LastCollectedGenStep)("prepare", GCBarrierPreparation)("last", LastCollectedGenStep); - CollectGenStepInFlight.reset(); +void TBlobManager::OnGCFinishedOnComplete(const std::optional& genStep) { + if (genStep) { + LastCollectedGenStep = *genStep; + AFL_VERIFY(GCBarrierPreparation == LastCollectedGenStep)("prepare", GCBarrierPreparation)("last", LastCollectedGenStep); + CollectGenStepInFlight.reset(); + } else { + AFL_VERIFY(!CollectGenStepInFlight); + } } -void TBlobManager::OnGCStartOnExecute(const TGenStep& genStep, IBlobManagerDb& db) { - AFL_VERIFY(LastCollectedGenStep <= genStep)("last", LastCollectedGenStep)("prepared", genStep); - db.SaveGCBarrierPreparation(genStep); +void TBlobManager::OnGCStartOnExecute(const std::optional& genStep, IBlobManagerDb& db) { + if (genStep) { + AFL_VERIFY(LastCollectedGenStep <= *genStep)("last", LastCollectedGenStep)("prepared", genStep); + db.SaveGCBarrierPreparation(*genStep); + } } -void TBlobManager::OnGCStartOnComplete(const TGenStep& genStep) { - AFL_VERIFY(GCBarrierPreparation <= genStep)("last", GCBarrierPreparation)("prepared", genStep); - GCBarrierPreparation = genStep; +void TBlobManager::OnGCStartOnComplete(const std::optional& genStep) { + if (genStep) { + AFL_VERIFY(GCBarrierPreparation <= *genStep)("last", GCBarrierPreparation)("prepared", genStep); + GCBarrierPreparation = *genStep; + } } void TBlobManager::OnBlobFree(const TUnifiedBlobId& blobId) { diff --git a/ydb/core/tx/columnshard/blobs_action/bs/blob_manager.h b/ydb/core/tx/columnshard/blobs_action/bs/blob_manager.h index c7a507553c24..a5592d48c76e 100644 --- a/ydb/core/tx/columnshard/blobs_action/bs/blob_manager.h +++ b/ydb/core/tx/columnshard/blobs_action/bs/blob_manager.h @@ -215,11 +215,11 @@ class TBlobManager : public IBlobManager, public TCommonBlobsTracker { const std::shared_ptr& manager, const std::shared_ptr& sharedBlobsInfo, const std::shared_ptr& counters) noexcept; - void OnGCFinishedOnExecute(const TGenStep& genStep, IBlobManagerDb& db); - void OnGCFinishedOnComplete(const TGenStep& genStep); + void OnGCFinishedOnExecute(const std::optional& genStep, IBlobManagerDb& db); + void OnGCFinishedOnComplete(const std::optional& genStep); - void OnGCStartOnExecute(const TGenStep& genStep, IBlobManagerDb& db); - void OnGCStartOnComplete(const TGenStep& genStep); + void OnGCStartOnExecute(const std::optional& genStep, IBlobManagerDb& db); + void OnGCStartOnComplete(const std::optional& genStep); TBlobManagerCounters GetCountersUpdate() { TBlobManagerCounters res = CountersUpdate; diff --git a/ydb/core/tx/columnshard/blobs_action/bs/gc.cpp b/ydb/core/tx/columnshard/blobs_action/bs/gc.cpp index ca22c12bd968..a72c6fb413de 100644 --- a/ydb/core/tx/columnshard/blobs_action/bs/gc.cpp +++ b/ydb/core/tx/columnshard/blobs_action/bs/gc.cpp @@ -31,7 +31,7 @@ bool TGCTask::DoOnCompleteTxBeforeCleaning(NColumnShard::TColumnShard& /*self*/, return true; } -TGCTask::TGCTask(const TString& storageId, TGCListsByGroup&& listsByGroupId, const TGenStep& collectGenStepInFlight, std::deque&& keepsToErase, +TGCTask::TGCTask(const TString& storageId, TGCListsByGroup&& listsByGroupId, const std::optional& collectGenStepInFlight, std::deque&& keepsToErase, const std::shared_ptr& manager, TBlobsCategories&& blobsToRemove, const std::shared_ptr& counters, const ui64 tabletId, const ui64 currentGen) : TBase(storageId, std::move(blobsToRemove), counters) @@ -65,8 +65,8 @@ std::unique_ptr TGCTask::BuildRequest(const T ("count", it->second.RequestsCount); auto result = std::make_unique( TabletId, CurrentGen, PerGenerationCounter.Val(), - address.GetChannelId(), true, - CollectGenStepInFlight.Generation(), CollectGenStepInFlight.Step(), + address.GetChannelId(), !!CollectGenStepInFlight, + CollectGenStepInFlight ? CollectGenStepInFlight->Generation() : 0, CollectGenStepInFlight ? CollectGenStepInFlight->Step() : 0, new TVector(it->second.KeepList.begin(), it->second.KeepList.end()), new TVector(it->second.DontKeepList.begin(), it->second.DontKeepList.end()), TInstant::Max(), true); diff --git a/ydb/core/tx/columnshard/blobs_action/bs/gc.h b/ydb/core/tx/columnshard/blobs_action/bs/gc.h index a8f334780417..5471fc04c0dd 100644 --- a/ydb/core/tx/columnshard/blobs_action/bs/gc.h +++ b/ydb/core/tx/columnshard/blobs_action/bs/gc.h @@ -21,7 +21,7 @@ class TGCTask: public IBlobsGCAction { using TGCListsByGroup = THashMap; private: TGCListsByGroup ListsByGroupId; - const TGenStep CollectGenStepInFlight; + const std::optional CollectGenStepInFlight; const ui64 TabletId; const ui64 CurrentGen; std::deque KeepsToErase; @@ -35,11 +35,11 @@ class TGCTask: public IBlobsGCAction { virtual bool DoOnCompleteTxBeforeCleaning(NColumnShard::TColumnShard& self, const std::shared_ptr& taskAction) override; virtual bool DoIsEmpty() const override { - return false; + return !CollectGenStepInFlight && KeepsToErase.empty(); } public: - TGCTask(const TString& storageId, TGCListsByGroup&& listsByGroupId, const TGenStep& collectGenStepInFlight, std::deque&& keepsToErase, + TGCTask(const TString& storageId, TGCListsByGroup&& listsByGroupId, const std::optional& collectGenStepInFlight, std::deque&& keepsToErase, const std::shared_ptr& manager, TBlobsCategories&& blobsToRemove, const std::shared_ptr& counters, const ui64 tabletId, const ui64 currentGen); const TGCListsByGroup& GetListsByGroupId() const {