From 900ca7436f810a2c4e59bc63d867e731148d976c Mon Sep 17 00:00:00 2001 From: Semyon Danilov Date: Thu, 1 Aug 2024 17:33:10 +0400 Subject: [PATCH] YDB-7262 Add default permille ICB configuration for vdisk garbage compaction threshold (#7319) --- .../blobstorage/nodewarden/node_warden_impl.cpp | 1 + .../blobstorage/nodewarden/node_warden_impl.h | 2 ++ .../nodewarden/node_warden_vdisk.cpp | 1 + .../blobstorage/vdisk/common/vdisk_config.h | 1 + .../blobstorage/vdisk/defrag/defrag_actor.cpp | 17 ++++++++++++----- .../blobstorage/vdisk/defrag/defrag_actor.h | 5 ++++- .../vdisk/defrag/defrag_actor_ut.cpp | 6 +++--- .../blobstorage/vdisk/defrag/defrag_quantum.cpp | 2 +- .../vdisk/skeleton/blobstorage_skeleton.cpp | 2 +- ydb/core/protos/config.proto | 5 +++++ 10 files changed, 31 insertions(+), 11 deletions(-) diff --git a/ydb/core/blobstorage/nodewarden/node_warden_impl.cpp b/ydb/core/blobstorage/nodewarden/node_warden_impl.cpp index 754d0924d1b9..f2995a5b441f 100644 --- a/ydb/core/blobstorage/nodewarden/node_warden_impl.cpp +++ b/ydb/core/blobstorage/nodewarden/node_warden_impl.cpp @@ -179,6 +179,7 @@ void TNodeWarden::Bootstrap() { icb->RegisterSharedControl(EnableSyncLogChunkCompressionSSD, "VDiskControls.EnableSyncLogChunkCompressionSSD"); icb->RegisterSharedControl(MaxSyncLogChunksInFlightHDD, "VDiskControls.MaxSyncLogChunksInFlightHDD"); icb->RegisterSharedControl(MaxSyncLogChunksInFlightSSD, "VDiskControls.MaxSyncLogChunksInFlightSSD"); + icb->RegisterSharedControl(DefaultHugeGarbagePerMille, "VDiskControls.DefaultHugeGarbagePerMille"); icb->RegisterSharedControl(CostMetricsParametersByMedia[NPDisk::DEVICE_TYPE_ROT].BurstThresholdNs, "VDiskControls.BurstThresholdNsHDD"); diff --git a/ydb/core/blobstorage/nodewarden/node_warden_impl.h b/ydb/core/blobstorage/nodewarden/node_warden_impl.h index 3d77ae4f1c7e..3a141f3b113c 100644 --- a/ydb/core/blobstorage/nodewarden/node_warden_impl.h +++ b/ydb/core/blobstorage/nodewarden/node_warden_impl.h @@ -139,6 +139,7 @@ namespace NKikimr::NStorage { TControlWrapper EnableSyncLogChunkCompressionSSD; TControlWrapper MaxSyncLogChunksInFlightHDD; TControlWrapper MaxSyncLogChunksInFlightSSD; + TControlWrapper DefaultHugeGarbagePerMille; TReplQuoter::TPtr ReplNodeRequestQuoter; TReplQuoter::TPtr ReplNodeResponseQuoter; @@ -162,6 +163,7 @@ namespace NKikimr::NStorage { , EnableSyncLogChunkCompressionSSD(0, 0, 1) , MaxSyncLogChunksInFlightHDD(10, 1, 1024) , MaxSyncLogChunksInFlightSSD(10, 1, 1024) + , DefaultHugeGarbagePerMille(300, 1, 1000) , CostMetricsParametersByMedia({ TCostMetricsParameters{200}, TCostMetricsParameters{50}, diff --git a/ydb/core/blobstorage/nodewarden/node_warden_vdisk.cpp b/ydb/core/blobstorage/nodewarden/node_warden_vdisk.cpp index 0497406a1332..75061a6bcc90 100644 --- a/ydb/core/blobstorage/nodewarden/node_warden_vdisk.cpp +++ b/ydb/core/blobstorage/nodewarden/node_warden_vdisk.cpp @@ -179,6 +179,7 @@ namespace NKikimr::NStorage { vdiskConfig->EnableVDiskCooldownTimeout = Cfg->EnableVDiskCooldownTimeout; vdiskConfig->ReplPausedAtStart = Cfg->VDiskReplPausedAtStart; vdiskConfig->EnableVPatch = EnableVPatch; + vdiskConfig->DefaultHugeGarbagePerMille = DefaultHugeGarbagePerMille; vdiskConfig->EnableLocalSyncLogDataCutting = EnableLocalSyncLogDataCutting; if (deviceType == NPDisk::EDeviceType::DEVICE_TYPE_ROT) { diff --git a/ydb/core/blobstorage/vdisk/common/vdisk_config.h b/ydb/core/blobstorage/vdisk/common/vdisk_config.h index 31e30788eeb1..73b1d27daaa1 100644 --- a/ydb/core/blobstorage/vdisk/common/vdisk_config.h +++ b/ydb/core/blobstorage/vdisk/common/vdisk_config.h @@ -218,6 +218,7 @@ namespace NKikimr { TDuration WhiteboardUpdateInterval; bool EnableVDiskCooldownTimeout; TControlWrapper EnableVPatch = true; + TControlWrapper DefaultHugeGarbagePerMille; ///////////// COST METRICS SETTINGS //////////////// bool UseCostTracker = true; diff --git a/ydb/core/blobstorage/vdisk/defrag/defrag_actor.cpp b/ydb/core/blobstorage/vdisk/defrag/defrag_actor.cpp index fa7014b64837..54a7d2cfaf53 100644 --- a/ydb/core/blobstorage/vdisk/defrag/defrag_actor.cpp +++ b/ydb/core/blobstorage/vdisk/defrag/defrag_actor.cpp @@ -16,12 +16,14 @@ namespace NKikimr { //////////////////////////////////////////////////////////////////////////// TDefragCtx::TDefragCtx( const TIntrusivePtr &vctx, + const TIntrusivePtr &vconfig, const std::shared_ptr &hugeBlobCtx, const TPDiskCtxPtr &pdiskCtx, const TActorId &skeletonId, const TActorId &hugeKeeperId, bool runDefrageBySchedule) : VCtx(vctx) + , VCfg(vconfig) , HugeBlobCtx(hugeBlobCtx) , PDiskCtx(pdiskCtx) , SkeletonId(skeletonId) @@ -48,7 +50,8 @@ namespace NKikimr { bool HugeHeapDefragmentationRequired( const TOutOfSpaceState& oos, ui32 hugeCanBeFreedChunks, - ui32 hugeTotalChunks) { + ui32 hugeTotalChunks, + double defaultPercent) { if (hugeCanBeFreedChunks < 10) return false; @@ -56,11 +59,14 @@ namespace NKikimr { double percentOfGarbage = static_cast(hugeCanBeFreedChunks) / hugeTotalChunks; if (oos.GetLocalColor() > TSpaceColor::CYAN) { - return percentOfGarbage >= 0.02; + // For anything worse than CYAN + return percentOfGarbage >= Min(0.02, defaultPercent); } else if (oos.GetLocalColor() > TSpaceColor::GREEN) { - return percentOfGarbage >= 0.15; + // For CYAN + return percentOfGarbage >= Min(0.15, defaultPercent); } else { - return percentOfGarbage >= 0.30; + // For GREEN + return percentOfGarbage >= Min(0.30, defaultPercent); } } @@ -113,7 +119,8 @@ namespace NKikimr { const auto& oos = DCtx->VCtx->GetOutOfSpaceState(); Y_ABORT_UNLESS(usefulChunks <= totalChunks); const ui32 canBeFreedChunks = totalChunks - usefulChunks; - if (HugeHeapDefragmentationRequired(oos, canBeFreedChunks, totalChunks)) { + double defaultPercent = DCtx->VCfg->DefaultHugeGarbagePerMille / 1000.0; + if (HugeHeapDefragmentationRequired(oos, canBeFreedChunks, totalChunks, defaultPercent)) { TChunksToDefrag chunksToDefrag = calcStat.GetChunksToDefrag(DCtx->MaxChunksToDefrag); Y_ABORT_UNLESS(chunksToDefrag); STLOG(PRI_INFO, BS_VDISK_DEFRAG, BSVDD03, VDISKP(DCtx->VCtx->VDiskLogPrefix, "scan finished"), diff --git a/ydb/core/blobstorage/vdisk/defrag/defrag_actor.h b/ydb/core/blobstorage/vdisk/defrag/defrag_actor.h index f59ecee374c6..08c451b094e7 100644 --- a/ydb/core/blobstorage/vdisk/defrag/defrag_actor.h +++ b/ydb/core/blobstorage/vdisk/defrag/defrag_actor.h @@ -18,6 +18,7 @@ namespace NKikimr { //////////////////////////////////////////////////////////////////////////// struct TDefragCtx { const TIntrusivePtr VCtx; + const TIntrusivePtr VCfg; const std::shared_ptr HugeBlobCtx; const TPDiskCtxPtr PDiskCtx; const TActorId SkeletonId; @@ -30,6 +31,7 @@ namespace NKikimr { TDefragCtx( const TIntrusivePtr &vctx, + const TIntrusivePtr &vconfig, const std::shared_ptr &hugeBlobCtx, const TPDiskCtxPtr &pdiskCtx, const TActorId &skeletonId, @@ -45,7 +47,8 @@ namespace NKikimr { bool HugeHeapDefragmentationRequired( const TOutOfSpaceState& oos, ui32 hugeCanBeFreedChunks, - ui32 hugeTotalChunks); + ui32 hugeTotalChunks, + double defaultPercent); //////////////////////////////////////////////////////////////////////////// // VDISK DEFRAG ACTOR CREATOR diff --git a/ydb/core/blobstorage/vdisk/defrag/defrag_actor_ut.cpp b/ydb/core/blobstorage/vdisk/defrag/defrag_actor_ut.cpp index ebcfec56195b..fa059a1d2c8e 100644 --- a/ydb/core/blobstorage/vdisk/defrag/defrag_actor_ut.cpp +++ b/ydb/core/blobstorage/vdisk/defrag/defrag_actor_ut.cpp @@ -15,21 +15,21 @@ namespace NKikimr { TOutOfSpaceState oos(1, 0); ui32 hugeCanBeFreedChunks = 9; ui32 hugeUsedChunks = 20; - bool defrag = HugeHeapDefragmentationRequired(oos, hugeCanBeFreedChunks, hugeUsedChunks); + bool defrag = HugeHeapDefragmentationRequired(oos, hugeCanBeFreedChunks, hugeUsedChunks, 0.30); UNIT_ASSERT(!defrag); } { TOutOfSpaceState oos(1, 0); ui32 hugeCanBeFreedChunks = 200; ui32 hugeUsedChunks = 1000; - bool defrag = HugeHeapDefragmentationRequired(oos, hugeCanBeFreedChunks, hugeUsedChunks); + bool defrag = HugeHeapDefragmentationRequired(oos, hugeCanBeFreedChunks, hugeUsedChunks, 0.30); UNIT_ASSERT(!defrag); } { TOutOfSpaceState oos(1, 0); ui32 hugeCanBeFreedChunks = 301; ui32 hugeUsedChunks = 1000; - bool defrag = HugeHeapDefragmentationRequired(oos, hugeCanBeFreedChunks, hugeUsedChunks); + bool defrag = HugeHeapDefragmentationRequired(oos, hugeCanBeFreedChunks, hugeUsedChunks, 0.30); UNIT_ASSERT(defrag); } } diff --git a/ydb/core/blobstorage/vdisk/defrag/defrag_quantum.cpp b/ydb/core/blobstorage/vdisk/defrag/defrag_quantum.cpp index 1e1753bf6a99..9f3cb4006e1b 100644 --- a/ydb/core/blobstorage/vdisk/defrag/defrag_quantum.cpp +++ b/ydb/core/blobstorage/vdisk/defrag/defrag_quantum.cpp @@ -95,7 +95,7 @@ namespace NKikimr { Compact(); auto hugeStat = GetHugeStat(); - Y_ABORT_UNLESS(hugeStat.LockedChunks.size() < 100); + Y_DEBUG_ABORT_UNLESS(hugeStat.LockedChunks.size() < 100); } Send(ParentActorId, new TEvDefragQuantumResult(std::move(stat))); diff --git a/ydb/core/blobstorage/vdisk/skeleton/blobstorage_skeleton.cpp b/ydb/core/blobstorage/vdisk/skeleton/blobstorage_skeleton.cpp index 043b5300e308..9d0cf4f4d95b 100644 --- a/ydb/core/blobstorage/vdisk/skeleton/blobstorage_skeleton.cpp +++ b/ydb/core/blobstorage/vdisk/skeleton/blobstorage_skeleton.cpp @@ -1789,7 +1789,7 @@ namespace NKikimr { } void StartDefrag(const TActorContext &ctx) { - auto defragCtx = std::make_shared(VCtx, HugeBlobCtx, PDiskCtx, ctx.SelfID, + auto defragCtx = std::make_shared(VCtx, Config, HugeBlobCtx, PDiskCtx, ctx.SelfID, Db->HugeKeeperID, true); DefragId = ctx.Register(CreateDefragActor(defragCtx, GInfo)); ActiveActors.Insert(DefragId, __FILE__, __LINE__, ctx, NKikimrServices::BLOBSTORAGE); // keep forever diff --git a/ydb/core/protos/config.proto b/ydb/core/protos/config.proto index c782f69d1e72..ef31dde885bb 100644 --- a/ydb/core/protos/config.proto +++ b/ydb/core/protos/config.proto @@ -1287,6 +1287,11 @@ message TImmediateControlsConfig { MinValue: 1, MaxValue: 1000000, DefaultValue: 1000 }]; + optional uint64 DefaultHugeGarbagePerMille = 12 [(ControlOptions) = { + Description: "Default threshold of huge chunk garbage per mille which triggers huge chunk defragmentation", + MinValue: 1, + MaxValue: 1000, + DefaultValue: 300 }]; } message TTabletControls {