From 40591525964ba52785897479c3976c097d209cc8 Mon Sep 17 00:00:00 2001 From: Andrei Strelkovskii Date: Sat, 28 Sep 2024 15:32:17 +0300 Subject: [PATCH] issue-1795: LargeDeletionMarkers backpressure - some fixes and cleanup (#2160) --- .../libs/storage/tablet/tablet_actor.cpp | 28 ++++++++++++++++--- .../libs/storage/tablet/tablet_actor.h | 1 + .../storage/tablet/tablet_actor_cleanup.cpp | 3 +- .../tablet/tablet_actor_compaction.cpp | 8 +----- .../storage/tablet/tablet_actor_truncate.cpp | 10 ++----- .../storage/tablet/tablet_actor_zerorange.cpp | 4 +-- .../libs/storage/tablet/tablet_state_data.cpp | 14 +++++----- 7 files changed, 39 insertions(+), 29 deletions(-) diff --git a/cloud/filestore/libs/storage/tablet/tablet_actor.cpp b/cloud/filestore/libs/storage/tablet/tablet_actor.cpp index 5328753650d..e2ebdc42f06 100644 --- a/cloud/filestore/libs/storage/tablet/tablet_actor.cpp +++ b/cloud/filestore/libs/storage/tablet/tablet_actor.cpp @@ -509,10 +509,19 @@ TCleanupInfo TIndexTabletActor::GetCleanupInfo() const avgCleanupScore >= Config->GetCleanupThresholdAverage(); bool isPriority = false; - if (auto priorityRange = NextPriorityRangeForCleanup()) { - cleanupRangeId = priorityRange->RangeId; - cleanupScore = Max(); - isPriority = true; + TString dummy; + // if we are close to our write backpressure thresholds, it's better to + // clean up normal deletion markers first in order not to freeze write + // requests + // + // large deletion marker cleanup is a slower process and having too many + // large deletion markers affects a much smaller percentage of workloads + if (!IsCloseToBackpressureThresholds(&dummy)) { + if (auto priorityRange = NextPriorityRangeForCleanup()) { + cleanupRangeId = priorityRange->RangeId; + cleanupScore = Max(); + isPriority = true; + } } return { @@ -532,6 +541,17 @@ TCleanupInfo TIndexTabletActor::GetCleanupInfo() const || isPriority}; } +bool TIndexTabletActor::IsCloseToBackpressureThresholds(TString* message) const +{ + auto bpThresholds = BuildBackpressureThresholds(); + const double scale = + Config->GetBackpressurePercentageForFairBlobIndexOpsPriority() + / 100.; + bpThresholds.CompactionScore *= scale; + bpThresholds.CleanupScore *= scale; + return !IsWriteAllowed(bpThresholds, GetBackpressureValues(), message); +} + //////////////////////////////////////////////////////////////////////////////// void TIndexTabletActor::HandleWakeup( diff --git a/cloud/filestore/libs/storage/tablet/tablet_actor.h b/cloud/filestore/libs/storage/tablet/tablet_actor.h index cfd56ed595c..ed9ea194d02 100644 --- a/cloud/filestore/libs/storage/tablet/tablet_actor.h +++ b/cloud/filestore/libs/storage/tablet/tablet_actor.h @@ -526,6 +526,7 @@ class TIndexTabletActor final ui32 ScaleCompactionThreshold(ui32 t) const; TCompactionInfo GetCompactionInfo() const; TCleanupInfo GetCleanupInfo() const; + bool IsCloseToBackpressureThresholds(TString* message) const; void HandleWakeup( const NActors::TEvents::TEvWakeup::TPtr& ev, diff --git a/cloud/filestore/libs/storage/tablet/tablet_actor_cleanup.cpp b/cloud/filestore/libs/storage/tablet/tablet_actor_cleanup.cpp index 2ea823b6427..617668a84cb 100644 --- a/cloud/filestore/libs/storage/tablet/tablet_actor_cleanup.cpp +++ b/cloud/filestore/libs/storage/tablet/tablet_actor_cleanup.cpp @@ -36,7 +36,8 @@ void TIndexTabletActor::HandleCleanup( return; } - auto response = std::make_unique(error); + auto response = + std::make_unique(error); NCloud::Reply(ctx, *ev, std::move(response)); }; diff --git a/cloud/filestore/libs/storage/tablet/tablet_actor_compaction.cpp b/cloud/filestore/libs/storage/tablet/tablet_actor_compaction.cpp index 1f32510ce0c..b5badc4a970 100644 --- a/cloud/filestore/libs/storage/tablet/tablet_actor_compaction.cpp +++ b/cloud/filestore/libs/storage/tablet/tablet_actor_compaction.cpp @@ -326,14 +326,8 @@ void TIndexTabletActor::EnqueueBlobIndexOpIfNeeded(const TActorContext& ctx) if (IsBlobIndexOpsQueueEmpty()) { auto blobIndexOpsPriority = Config->GetBlobIndexOpsPriority(); - auto bpThresholds = BuildBackpressureThresholds(); - const double scale = - Config->GetBackpressurePercentageForFairBlobIndexOpsPriority() - / 100.; - bpThresholds.CompactionScore *= scale; - bpThresholds.CleanupScore *= scale; TString message; - if (!IsWriteAllowed(bpThresholds, GetBackpressureValues(), &message)) { + if (IsCloseToBackpressureThresholds(&message)) { // if we are close to our backpressure thresholds, we should fall // back to fair scheduling so that all operations show some progress blobIndexOpsPriority = NProto::BIOP_FAIR; diff --git a/cloud/filestore/libs/storage/tablet/tablet_actor_truncate.cpp b/cloud/filestore/libs/storage/tablet/tablet_actor_truncate.cpp index c97e78dcbec..f19b44227f4 100644 --- a/cloud/filestore/libs/storage/tablet/tablet_actor_truncate.cpp +++ b/cloud/filestore/libs/storage/tablet/tablet_actor_truncate.cpp @@ -316,17 +316,13 @@ void TIndexTabletActor::ExecuteTx_TruncateRange( return RebootTabletOnCommitOverflow(ctx, "TruncateRange"); } - auto e = TruncateRange(db, args.NodeId, commitId, args.Range); - if (HasError(e)) { - args.Error = std::move(e); - return; - } - AddRange( args.NodeId, args.Range.Offset, args.Range.Length, args.ProfileLogRequest); + + args.Error = TruncateRange(db, args.NodeId, commitId, args.Range); } void TIndexTabletActor::CompleteTx_TruncateRange( @@ -338,7 +334,7 @@ void TIndexTabletActor::CompleteTx_TruncateRange( std::move(args.ProfileLogRequest), ctx.Now(), GetFileSystemId(), - {}, + args.Error, ProfileLog); LOG_DEBUG(ctx, TFileStoreComponents::TABLET, diff --git a/cloud/filestore/libs/storage/tablet/tablet_actor_zerorange.cpp b/cloud/filestore/libs/storage/tablet/tablet_actor_zerorange.cpp index f296b96ff6a..6574e32caf2 100644 --- a/cloud/filestore/libs/storage/tablet/tablet_actor_zerorange.cpp +++ b/cloud/filestore/libs/storage/tablet/tablet_actor_zerorange.cpp @@ -69,8 +69,6 @@ void TIndexTabletActor::ExecuteTx_ZeroRange( TTransactionContext& tx, TTxIndexTablet::TZeroRange& args) { - Y_UNUSED(ctx); - TIndexTabletDatabase db(tx.DB); ui64 commitId = GenerateCommitId(); @@ -96,7 +94,7 @@ void TIndexTabletActor::CompleteTx_ZeroRange( std::move(args.ProfileLogRequest), ctx.Now(), GetFileSystemId(), - {}, + args.Error, ProfileLog); LOG_DEBUG(ctx, TFileStoreComponents::TABLET, diff --git a/cloud/filestore/libs/storage/tablet/tablet_state_data.cpp b/cloud/filestore/libs/storage/tablet/tablet_state_data.cpp index d8acdc4d9de..cf2c6cc8290 100644 --- a/cloud/filestore/libs/storage/tablet/tablet_state_data.cpp +++ b/cloud/filestore/libs/storage/tablet/tablet_state_data.cpp @@ -180,13 +180,6 @@ NProto::TError TIndexTabletState::DeleteRange( { const ui64 deletedBlockCount = range.AlignedBlockCount(); if (deletedBlockCount) { - MarkFreshBlocksDeleted( - db, - nodeId, - commitId, - range.FirstAlignedBlock(), - deletedBlockCount); - const bool useLargeDeletionMarkers = LargeDeletionMarkersEnabled && deletedBlockCount >= LargeDeletionMarkersThreshold; if (useLargeDeletionMarkers) { @@ -230,6 +223,13 @@ NProto::TError TIndexTabletState::DeleteRange( blocksCount); }); } + + MarkFreshBlocksDeleted( + db, + nodeId, + commitId, + range.FirstAlignedBlock(), + deletedBlockCount); } WriteFreshBytesDeletionMarker(