diff options
author | ivanmorozov <ivanmorozov@yandex-team.com> | 2023-07-25 13:24:05 +0300 |
---|---|---|
committer | root <root@qavm-2ed34686.qemu> | 2023-07-25 13:24:05 +0300 |
commit | caf4520026f5517ea48ecde3467e195dc7981b7c (patch) | |
tree | eba55b63634774f34ac91eb733aad84b6de90d49 | |
parent | 22d9f8e8361fb30d4a132e3fe8536550b13d0628 (diff) | |
download | ydb-caf4520026f5517ea48ecde3467e195dc7981b7c.tar.gz |
use guards for guarantee refresh counters on granule info modification
-rw-r--r-- | ydb/core/tx/columnshard/engines/storage/granule.cpp | 27 | ||||
-rw-r--r-- | ydb/core/tx/columnshard/engines/storage/granule.h | 47 | ||||
-rw-r--r-- | ydb/core/tx/columnshard/engines/storage/storage.h | 2 |
3 files changed, 47 insertions, 29 deletions
diff --git a/ydb/core/tx/columnshard/engines/storage/granule.cpp b/ydb/core/tx/columnshard/engines/storage/granule.cpp index ac141373219..5d0a614ec58 100644 --- a/ydb/core/tx/columnshard/engines/storage/granule.cpp +++ b/ydb/core/tx/columnshard/engines/storage/granule.cpp @@ -67,13 +67,13 @@ void TGranuleMeta::OnAfterChangePortion() { void TGranuleMeta::OnBeforeChangePortion(const TPortionInfo* portionBefore, const TPortionInfo* portionAfter) { HardSummaryCache = {}; if (!!AdditiveSummaryCache) { + auto g = AdditiveSummaryCache->StartEdit(Counters); if (portionBefore && portionBefore->IsActive()) { - AdditiveSummaryCache->RemovePortion(*portionBefore); + g.RemovePortion(*portionBefore); } if (portionAfter && portionAfter->IsActive()) { - AdditiveSummaryCache->AddPortion(*portionAfter); + g.AddPortion(*portionAfter); } - OnAdditiveSummaryChange(); } } @@ -152,12 +152,14 @@ void TGranuleMeta::RebuildHardMetrics() const { void TGranuleMeta::RebuildAdditiveMetrics() const { TGranuleAdditiveSummary result; - - for (auto&& i : Portions) { - if (!i.second.IsActive()) { - continue; + { + auto g = result.StartEdit(Counters); + for (auto&& i : Portions) { + if (!i.second.IsActive()) { + continue; + } + g.AddPortion(i.second); } - result.AddPortion(i.second); } AdditiveSummaryCache = result; } @@ -165,17 +167,8 @@ void TGranuleMeta::RebuildAdditiveMetrics() const { const NKikimr::NOlap::TGranuleAdditiveSummary& TGranuleMeta::GetAdditiveSummary() const { if (!AdditiveSummaryCache) { RebuildAdditiveMetrics(); - OnAdditiveSummaryChange(); } return *AdditiveSummaryCache; } -void TGranuleMeta::OnAdditiveSummaryChange() const { - if (AdditiveSummaryCache) { - Counters.OnCompactedData(AdditiveSummaryCache->GetOther()); - Counters.OnInsertedData(AdditiveSummaryCache->GetInserted()); - Counters.OnFullData(AdditiveSummaryCache->GetOther() + AdditiveSummaryCache->GetInserted()); - } -} - } // namespace NKikimr::NOlap diff --git a/ydb/core/tx/columnshard/engines/storage/granule.h b/ydb/core/tx/columnshard/engines/storage/granule.h index d886e03715d..84b24ec82ef 100644 --- a/ydb/core/tx/columnshard/engines/storage/granule.h +++ b/ydb/core/tx/columnshard/engines/storage/granule.h @@ -181,20 +181,45 @@ public: ui64 GetMaxColumnsSize() const { return (Inserted + Other).GetMaxColumnsSize(); } - void AddPortion(const TPortionInfo& info) { - if (info.IsInserted()) { - Inserted.AddPortion(info); - } else { - Other.AddPortion(info); + + class TEditGuard: TNonCopyable { + private: + const NColumnShard::TGranuleDataCounters& Counters; + TGranuleAdditiveSummary& Owner; + public: + TEditGuard(const NColumnShard::TGranuleDataCounters& counters, TGranuleAdditiveSummary& owner) + : Counters(counters) + , Owner(owner) + { + } - } - void RemovePortion(const TPortionInfo& info) { - if (info.IsInserted()) { - Inserted.RemovePortion(info); - } else { - Other.RemovePortion(info); + + ~TEditGuard() { + Counters.OnCompactedData(Owner.GetOther()); + Counters.OnInsertedData(Owner.GetInserted()); + Counters.OnFullData(Owner.GetOther() + Owner.GetInserted()); } + + void AddPortion(const TPortionInfo& info) { + if (info.IsInserted()) { + Owner.Inserted.AddPortion(info); + } else { + Owner.Other.AddPortion(info); + } + } + void RemovePortion(const TPortionInfo& info) { + if (info.IsInserted()) { + Owner.Inserted.RemovePortion(info); + } else { + Owner.Other.RemovePortion(info); + } + } + }; + + TEditGuard StartEdit(const NColumnShard::TGranuleDataCounters& counters) { + return TEditGuard(counters, *this); } + TString DebugString() const { return TStringBuilder() << "inserted:(" << Inserted.DebugString() << ");other:(" << Other.DebugString() << "); "; } diff --git a/ydb/core/tx/columnshard/engines/storage/storage.h b/ydb/core/tx/columnshard/engines/storage/storage.h index 4cb7dde076c..83e10713dfc 100644 --- a/ydb/core/tx/columnshard/engines/storage/storage.h +++ b/ydb/core/tx/columnshard/engines/storage/storage.h @@ -34,7 +34,7 @@ public: } - class TModificationGuard { + class TModificationGuard: TNonCopyable { private: TGranulesStorage& Owner; public: |