diff options
author | alexvru <alexvru@ydb.tech> | 2022-10-25 19:04:17 +0300 |
---|---|---|
committer | alexvru <alexvru@ydb.tech> | 2022-10-25 19:04:17 +0300 |
commit | 763101f49e6c3b2a99037f15c4dfe94d80725f62 (patch) | |
tree | b055ce09405d80e37e8021680d989a344e56ce38 | |
parent | c344a5dab84fef5b7925b0c8d52779af2c1f7cea (diff) | |
download | ydb-763101f49e6c3b2a99037f15c4dfe94d80725f62.tar.gz |
Improve ApproximateFreeSpaceShare calculation
6 files changed, 16 insertions, 9 deletions
diff --git a/ydb/core/blobstorage/pdisk/blobstorage_pdisk.h b/ydb/core/blobstorage/pdisk/blobstorage_pdisk.h index aed3d485e0..8692fcf926 100644 --- a/ydb/core/blobstorage/pdisk/blobstorage_pdisk.h +++ b/ydb/core/blobstorage/pdisk/blobstorage_pdisk.h @@ -1302,15 +1302,17 @@ struct TEvCheckSpaceResult : public TEventLocal<TEvCheckSpaceResult, TEvBlobStor ui32 FreeChunks; ui32 TotalChunks; // contains common limit in shared free space mode, Total != Free + Used ui32 UsedChunks; // number of chunks allocated by requesting owner + ui32 NumSlots; // number of VSlots over PDisk TString ErrorReason; TEvCheckSpaceResult(NKikimrProto::EReplyStatus status, TStatusFlags statusFlags, ui32 freeChunks, - ui32 totalChunks, ui32 usedChunks, const TString &errorReason) + ui32 totalChunks, ui32 usedChunks, ui32 numSlots, const TString &errorReason) : Status(status) , StatusFlags(statusFlags) , FreeChunks(freeChunks) , TotalChunks(totalChunks) , UsedChunks(usedChunks) + , NumSlots(numSlots) , ErrorReason(errorReason) {} @@ -1321,6 +1323,7 @@ struct TEvCheckSpaceResult : public TEventLocal<TEvCheckSpaceResult, TEvBlobStor str << " FreeChunks# " << FreeChunks; str << " TotalChunks# " << TotalChunks; str << " UsedChunks# " << UsedChunks; + str << " NumSlots# " << NumSlots; str << " ErrorReason# \"" << ErrorReason << "\""; str << "}"; return str.Str(); diff --git a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_actor.cpp b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_actor.cpp index b3d89908b2..3e35c8b6e9 100644 --- a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_actor.cpp +++ b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_actor.cpp @@ -596,7 +596,7 @@ public: void ErrorHandle(NPDisk::TEvCheckSpace::TPtr &ev) { PDisk->Mon.CheckSpace.CountRequest(); - Send(ev->Sender, new NPDisk::TEvCheckSpaceResult(NKikimrProto::CORRUPTED, 0, 0, 0, 0, StateErrorReason)); + Send(ev->Sender, new NPDisk::TEvCheckSpaceResult(NKikimrProto::CORRUPTED, 0, 0, 0, 0, 0, StateErrorReason)); PDisk->Mon.CheckSpace.CountResponse(); } diff --git a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl.cpp b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl.cpp index 3732fb1479..fffa12c539 100644 --- a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl.cpp +++ b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_impl.cpp @@ -1911,6 +1911,7 @@ void TPDisk::CheckSpace(TCheckSpace &evCheckSpace) { GetFreeChunks(evCheckSpace.Owner, evCheckSpace.OwnerGroupType), GetTotalChunks(evCheckSpace.Owner, evCheckSpace.OwnerGroupType), GetUsedChunks(evCheckSpace.Owner, evCheckSpace.OwnerGroupType), + AtomicGet(TotalOwners), TString())); ActorSystem->Send(evCheckSpace.Sender, result.Release()); Mon.CheckSpace.CountResponse(); @@ -2883,7 +2884,7 @@ bool TPDisk::PreprocessRequest(TRequestBase *request) { if (errStatus != NKikimrProto::OK) { LOG_ERROR_S(*ActorSystem, NKikimrServices::BS_PDISK, err.Str()); THolder<NPDisk::TEvCheckSpaceResult> result(new NPDisk::TEvCheckSpaceResult(errStatus, - GetStatusFlags(ev.Owner, ev.OwnerGroupType), 0, 0, 0, err.Str())); + GetStatusFlags(ev.Owner, ev.OwnerGroupType), 0, 0, 0, 0, err.Str())); ActorSystem->Send(ev.Sender, result.Release()); Mon.CheckSpace.CountResponse(); delete request; diff --git a/ydb/core/blobstorage/pdisk/mock/pdisk_mock.cpp b/ydb/core/blobstorage/pdisk/mock/pdisk_mock.cpp index 6e549edd20..ce4fef136b 100644 --- a/ydb/core/blobstorage/pdisk/mock/pdisk_mock.cpp +++ b/ydb/core/blobstorage/pdisk/mock/pdisk_mock.cpp @@ -756,7 +756,8 @@ public: void Handle(NPDisk::TEvCheckSpace::TPtr ev) { auto *msg = ev->Get(); auto res = std::make_unique<NPDisk::TEvCheckSpaceResult>(NKikimrProto::OK, GetStatusFlags(), - Impl.GetNumFreeChunks(), Impl.TotalChunks, Impl.TotalChunks - Impl.GetNumFreeChunks(), TString()); + Impl.GetNumFreeChunks(), Impl.TotalChunks, Impl.TotalChunks - Impl.GetNumFreeChunks(), + Impl.Owners.size(), TString()); Impl.FindOwner(msg, res); // to ensure correct owner/round Send(ev->Sender, res.release()); } diff --git a/ydb/core/blobstorage/vdisk/common/vdisk_outofspace.h b/ydb/core/blobstorage/vdisk/common/vdisk_outofspace.h index 28c351b5c7..9e20f1a00e 100644 --- a/ydb/core/blobstorage/vdisk/common/vdisk_outofspace.h +++ b/ydb/core/blobstorage/vdisk/common/vdisk_outofspace.h @@ -44,8 +44,8 @@ namespace NKikimr { Update(SelfOrderNum, flags); } - void UpdateLocalFreeSpaceShare(ui64 freeSpaceShareMult1000) { - AtomicSet(ApproximateFreeSpaceShareMult1000, static_cast<TAtomicBase>(freeSpaceShareMult1000)); + void UpdateLocalFreeSpaceShare(ui64 freeSpaceShare24bit) { + AtomicSet(ApproximateFreeSpaceShare24bit, freeSpaceShare24bit); } void UpdateLocalUsedChunks(ui32 usedChunks) { @@ -62,7 +62,7 @@ namespace NKikimr { // free space share as a fraction of 1 -- [0, 1) float GetFreeSpaceShare() const { - return static_cast<float>(AtomicGet(ApproximateFreeSpaceShareMult1000)) / static_cast<float>(1000); + return static_cast<float>(AtomicGet(ApproximateFreeSpaceShare24bit)) / 16'777'216.0f; } ui32 GetLocalUsedChunks() const { @@ -75,7 +75,7 @@ namespace NKikimr { // Cached global flags (obtained by merging AllVDiskFlags) TAtomic GlobalFlags = 0; // Approximate free space share (to calculate percentage of free/used space) - TAtomic ApproximateFreeSpaceShareMult1000 = 0; + TAtomic ApproximateFreeSpaceShare24bit = 0; // Total VDisks in the group const ui32 TotalVDisks; // VDisk order number for self diff --git a/ydb/core/blobstorage/vdisk/skeleton/skeleton_oos_tracker.cpp b/ydb/core/blobstorage/vdisk/skeleton/skeleton_oos_tracker.cpp index 8af5bd8dc2..9a5b692796 100644 --- a/ydb/core/blobstorage/vdisk/skeleton/skeleton_oos_tracker.cpp +++ b/ydb/core/blobstorage/vdisk/skeleton/skeleton_oos_tracker.cpp @@ -85,7 +85,9 @@ namespace NKikimr { TotalChunks = msg->TotalChunks; FreeChunks = msg->FreeChunks; - const ui64 freeSpaceShareMult1000 = ui64(1000) * FreeChunks / Max(ui64(1), TotalChunks); + const ui64 a = Min(msg->TotalChunks, msg->FreeChunks / Min(1u, msg->NumSlots)); + const ui64 b = msg->UsedChunks; + const ui64 freeSpaceShareMult1000 = ui64(1 << 24) * a / (a + b); VCtx->OutOfSpaceState.UpdateLocal(msg->StatusFlags); VCtx->OutOfSpaceState.UpdateLocalFreeSpaceShare(freeSpaceShareMult1000); VCtx->OutOfSpaceState.UpdateLocalUsedChunks(msg->UsedChunks); |