diff options
author | alexvru <alexvru@ydb.tech> | 2023-05-11 22:04:47 +0300 |
---|---|---|
committer | alexvru <alexvru@ydb.tech> | 2023-05-11 22:04:47 +0300 |
commit | 5e0a5156b18c5dcc21eb2aa3cd53274135de124f (patch) | |
tree | e046120984bec2f5c80ec1b2071973ffd280aaaa | |
parent | 7df1977a606ccd826561ecb88ee0f35ddf92e0f9 (diff) | |
download | ydb-5e0a5156b18c5dcc21eb2aa3cd53274135de124f.tar.gz |
Remove counters upon VDisk destruction
-rw-r--r-- | library/cpp/monlib/dynamic_counters/counters.cpp | 18 | ||||
-rw-r--r-- | library/cpp/monlib/dynamic_counters/counters.h | 5 | ||||
-rw-r--r-- | ydb/core/blobstorage/vdisk/skeleton/blobstorage_skeletonfront.cpp | 33 |
3 files changed, 40 insertions, 16 deletions
diff --git a/library/cpp/monlib/dynamic_counters/counters.cpp b/library/cpp/monlib/dynamic_counters/counters.cpp index 3635d87d0d..8cc6f6e835 100644 --- a/library/cpp/monlib/dynamic_counters/counters.cpp +++ b/library/cpp/monlib/dynamic_counters/counters.cpp @@ -106,11 +106,24 @@ void TDynamicCounters::RemoveCounter(const TString &value) { RemoveNamedCounter("sensor", value); } -void TDynamicCounters::RemoveNamedCounter(const TString& name, const TString &value) { +bool TDynamicCounters::RemoveNamedCounter(const TString& name, const TString &value) { auto g = LockForUpdate("RemoveNamedCounter", name, value); if (const auto it = Counters.find({name, value}); it != Counters.end() && AsCounter(it->second)) { Counters.erase(it); } + return Counters.empty(); +} + +void TDynamicCounters::RemoveSubgroupChain(const std::vector<std::pair<TString, TString>>& chain) { + std::vector<TIntrusivePtr<TDynamicCounters>> basePointers; + basePointers.push_back(this); + for (size_t i = 0; i < chain.size() - 1; ++i) { + const auto& [name, value] = chain[i]; + auto& base = basePointers.back(); + basePointers.push_back(base->GetSubgroup(name, value)); + Y_VERIFY(basePointers.back()); + } + for (size_t i = chain.size(); i-- && basePointers[i]->RemoveSubgroup(chain[i].first, chain[i].second); ) {} } TIntrusivePtr<TDynamicCounters> TDynamicCounters::GetSubgroup(const TString& name, const TString& value) { @@ -134,11 +147,12 @@ TIntrusivePtr<TDynamicCounters> TDynamicCounters::FindSubgroup(const TString& na return it != Counters.end() ? AsDynamicCounters(it->second) : nullptr; } -void TDynamicCounters::RemoveSubgroup(const TString& name, const TString& value) { +bool TDynamicCounters::RemoveSubgroup(const TString& name, const TString& value) { auto g = LockForUpdate("RemoveSubgroup", name, value); if (const auto it = Counters.find({name, value}); it != Counters.end() && AsDynamicCounters(it->second)) { Counters.erase(it); } + return Counters.empty(); } void TDynamicCounters::ReplaceSubgroup(const TString& name, const TString& value, TIntrusivePtr<TDynamicCounters> subgroup) { diff --git a/library/cpp/monlib/dynamic_counters/counters.h b/library/cpp/monlib/dynamic_counters/counters.h index 3bf89c5098..b15566c034 100644 --- a/library/cpp/monlib/dynamic_counters/counters.h +++ b/library/cpp/monlib/dynamic_counters/counters.h @@ -327,11 +327,12 @@ namespace NMonitoring { THistogramPtr FindNamedHistogram(const TString& name,const TString& value) const; void RemoveCounter(const TString &value); - void RemoveNamedCounter(const TString& name, const TString &value); + bool RemoveNamedCounter(const TString& name, const TString &value); + void RemoveSubgroupChain(const std::vector<std::pair<TString, TString>>& chain); TIntrusivePtr<TDynamicCounters> GetSubgroup(const TString& name, const TString& value); TIntrusivePtr<TDynamicCounters> FindSubgroup(const TString& name, const TString& value) const; - void RemoveSubgroup(const TString& name, const TString& value); + bool RemoveSubgroup(const TString& name, const TString& value); void ReplaceSubgroup(const TString& name, const TString& value, TIntrusivePtr<TDynamicCounters> subgroup); // Move all counters from specified subgroup and remove the subgroup. diff --git a/ydb/core/blobstorage/vdisk/skeleton/blobstorage_skeletonfront.cpp b/ydb/core/blobstorage/vdisk/skeleton/blobstorage_skeletonfront.cpp index fd7a6bb18c..0e7bbca3a6 100644 --- a/ydb/core/blobstorage/vdisk/skeleton/blobstorage_skeletonfront.cpp +++ b/ydb/core/blobstorage/vdisk/skeleton/blobstorage_skeletonfront.cpp @@ -679,6 +679,8 @@ namespace NKikimr { std::shared_ptr<TBlobStorageGroupInfo::TTopology> Top; TVDiskID SelfVDiskId; TActorId SkeletonId; + std::vector<std::pair<TString, TString>> CountersChain; + TIntrusivePtr<::NMonitoring::TDynamicCounters> VDiskCountersBase; TIntrusivePtr<::NMonitoring::TDynamicCounters> VDiskCounters; TIntrusivePtr<::NMonitoring::TDynamicCounters> SkeletonFrontGroup; ::NMonitoring::TDynamicCounters::TCounterPtr AccessDeniedMessages; @@ -1992,31 +1994,32 @@ namespace NKikimr { static TIntrusivePtr<::NMonitoring::TDynamicCounters> CreateVDiskCounters( TIntrusivePtr<TVDiskConfig> cfg, TIntrusivePtr<TBlobStorageGroupInfo> info, - TIntrusivePtr<::NMonitoring::TDynamicCounters> counters) { - - // create 'vdisks' service counters - auto vdiskCounters = GetServiceCounters(counters, "vdisks"); - + TIntrusivePtr<::NMonitoring::TDynamicCounters> counters, + std::vector<std::pair<TString, TString>>& chain) { // add 'storagePool' label - vdiskCounters = vdiskCounters->GetSubgroup("storagePool", cfg->BaseInfo.StoragePoolName); + chain.emplace_back("storagePool", cfg->BaseInfo.StoragePoolName); // add 'group' label const ui32 blobstorageGroupId = info->GroupID; - vdiskCounters = vdiskCounters->GetSubgroup("group", Sprintf("%09" PRIu32, blobstorageGroupId)); + chain.emplace_back("group", Sprintf("%09" PRIu32, blobstorageGroupId)); // add 'orderNumber' label (VDisk order number in the group) const ui32 vdiskOrderNumber = info->GetOrderNumber(cfg->BaseInfo.VDiskIdShort); - vdiskCounters = vdiskCounters->GetSubgroup("orderNumber", Sprintf("%02" PRIu32, vdiskOrderNumber)); + chain.emplace_back("orderNumber", Sprintf("%02" PRIu32, vdiskOrderNumber)); // add 'pdisk' label as a local id of pdisk const ui32 pdiskId = cfg->BaseInfo.PDiskId; - vdiskCounters = vdiskCounters->GetSubgroup("pdisk", Sprintf("%09" PRIu32, pdiskId)); + chain.emplace_back("pdisk", Sprintf("%09" PRIu32, pdiskId)); // add 'media' const auto media = cfg->BaseInfo.DeviceType; - vdiskCounters = vdiskCounters->GetSubgroup("media", to_lower(NPDisk::DeviceTypeStr(media, true))); + chain.emplace_back("media", to_lower(NPDisk::DeviceTypeStr(media, true))); + + for (const auto& [name, value] : chain) { + counters = counters->GetSubgroup(name, value); + } - return vdiskCounters; + return counters; } TSkeletonFront(TIntrusivePtr<TVDiskConfig> cfg, TIntrusivePtr<TBlobStorageGroupInfo> info, @@ -2028,7 +2031,8 @@ namespace NKikimr { , Top(GInfo->PickTopology()) , SelfVDiskId(GInfo->GetVDiskId(Config->BaseInfo.VDiskIdShort)) , SkeletonId() - , VDiskCounters(CreateVDiskCounters(cfg, info, counters)) + , VDiskCountersBase(GetServiceCounters(counters, "vdisks")) + , VDiskCounters(CreateVDiskCounters(Config, GInfo, VDiskCountersBase, CountersChain)) , SkeletonFrontGroup(VDiskCounters->GetSubgroup("subsystem", "skeletonfront")) , AccessDeniedMessages(SkeletonFrontGroup->GetCounter("AccessDeniedMessages", true)) @@ -2082,6 +2086,11 @@ namespace NKikimr { ReplMonGroup.ReplUnreplicatedVDisks() = 1; VDiskMonGroup.VDiskState(NKikimrWhiteboard::EVDiskState::Initial); } + + void PassAway() override { + VDiskCountersBase->RemoveSubgroupChain(CountersChain); + TActorBootstrapped::PassAway(); + } }; //////////////////////////////////////////////////////////////////////////// |