From 26bd5fe50273266dbec8183f1dc45d8d3fb99532 Mon Sep 17 00:00:00 2001 From: ivanmorozov333 Date: Fri, 27 Dec 2024 10:11:31 +0300 Subject: [PATCH] reuse code for portion meta --- .../engines/portions/constructor_meta.cpp | 2 +- .../engines/portions/constructor_meta.h | 32 +------ .../tx/columnshard/engines/portions/meta.cpp | 2 +- .../tx/columnshard/engines/portions/meta.h | 85 +++++++++++-------- 4 files changed, 55 insertions(+), 66 deletions(-) diff --git a/ydb/core/tx/columnshard/engines/portions/constructor_meta.cpp b/ydb/core/tx/columnshard/engines/portions/constructor_meta.cpp index 6b71280c8f21..3667049a77df 100644 --- a/ydb/core/tx/columnshard/engines/portions/constructor_meta.cpp +++ b/ydb/core/tx/columnshard/engines/portions/constructor_meta.cpp @@ -49,7 +49,7 @@ TPortionMeta TPortionMetaConstructor::Build() { if (TierName) { result.TierName = *TierName; } - AFL_VERIFY(BlobIds.size()); + TBase::FullValidation(); result.BlobIds = BlobIds; result.BlobIds.shrink_to_fit(); result.CompactionLevel = *TValidator::CheckNotNull(CompactionLevel); diff --git a/ydb/core/tx/columnshard/engines/portions/constructor_meta.h b/ydb/core/tx/columnshard/engines/portions/constructor_meta.h index 71f7ae692501..ab222ed7e964 100644 --- a/ydb/core/tx/columnshard/engines/portions/constructor_meta.h +++ b/ydb/core/tx/columnshard/engines/portions/constructor_meta.h @@ -10,8 +10,9 @@ namespace NKikimr::NOlap { class TPortionInfoConstructor; struct TIndexInfo; -class TPortionMetaConstructor { +class TPortionMetaConstructor: public TPortionMetaBase { private: + using TBase = TPortionMetaBase; std::optional FirstAndLastPK; std::optional TierName; std::optional RecordSnapshotMin; @@ -27,8 +28,6 @@ class TPortionMetaConstructor { std::optional DeletionsCount; - std::vector BlobIds; - friend class TPortionInfoConstructor; friend class TPortionAccessorConstructor; void FillMetaInfo(const NArrow::TFirstLastSpecialKeys& primaryKeys, const ui32 deletionsCount, @@ -42,15 +41,6 @@ class TPortionMetaConstructor { return linkRange.RestoreRange(GetBlobId(linkRange.GetBlobIdxVerified())); } - ui32 GetBlobIdsCount() const { - return BlobIds.size(); - } - - const TUnifiedBlobId& GetBlobId(const TBlobRangeLink16::TLinkId linkId) const { - AFL_VERIFY(linkId < BlobIds.size()); - return BlobIds[linkId]; - } - TBlobRangeLink16::TLinkId RegisterBlobId(const TUnifiedBlobId& blobId) { AFL_VERIFY(blobId.IsValid()); TBlobRangeLink16::TLinkId idx = 0; @@ -64,24 +54,6 @@ class TPortionMetaConstructor { return idx; } - std::optional GetBlobIdxOptional(const TUnifiedBlobId& blobId) const { - AFL_VERIFY(blobId.IsValid()); - TBlobRangeLink16::TLinkId idx = 0; - for (auto&& i : BlobIds) { - if (i == blobId) { - return idx; - } - ++idx; - } - return std::nullopt; - } - - TBlobRangeLink16::TLinkId GetBlobIdxVerified(const TUnifiedBlobId& blobId) const { - auto result = GetBlobIdxOptional(blobId); - AFL_VERIFY(result); - return *result; - } - void SetCompactionLevel(const ui64 level) { CompactionLevel = level; } diff --git a/ydb/core/tx/columnshard/engines/portions/meta.cpp b/ydb/core/tx/columnshard/engines/portions/meta.cpp index 693e6b7367e4..802648f03306 100644 --- a/ydb/core/tx/columnshard/engines/portions/meta.cpp +++ b/ydb/core/tx/columnshard/engines/portions/meta.cpp @@ -44,7 +44,7 @@ NKikimrTxColumnShard::TIndexPortionMeta TPortionMeta::SerializeToProto() const { RecordSnapshotMin.SerializeToProto(*portionMeta.MutableRecordSnapshotMin()); RecordSnapshotMax.SerializeToProto(*portionMeta.MutableRecordSnapshotMax()); - for (auto&& i : BlobIds) { + for (auto&& i : GetBlobIds()) { *portionMeta.AddBlobIds() = i.GetLogoBlobId().AsBinaryString(); } return portionMeta; diff --git a/ydb/core/tx/columnshard/engines/portions/meta.h b/ydb/core/tx/columnshard/engines/portions/meta.h index 7c212fdf00c1..f0d915e14c73 100644 --- a/ydb/core/tx/columnshard/engines/portions/meta.h +++ b/ydb/core/tx/columnshard/engines/portions/meta.h @@ -14,8 +14,56 @@ namespace NKikimr::NOlap { struct TIndexInfo; -struct TPortionMeta { +class TPortionMetaBase { +protected: + std::vector BlobIds; +public: + const std::vector& GetBlobIds() const { + return BlobIds; + } + + const TUnifiedBlobId& GetBlobId(const TBlobRangeLink16::TLinkId linkId) const { + AFL_VERIFY(linkId < GetBlobIds().size()); + return BlobIds[linkId]; + } + + ui32 GetBlobIdsCount() const { + return BlobIds.size(); + } + + void FullValidation() const { + for (auto&& i : BlobIds) { + AFL_VERIFY(i.BlobSize()); + } + AFL_VERIFY(BlobIds.size()); + } + + std::optional GetBlobIdxOptional(const TUnifiedBlobId& blobId) const { + AFL_VERIFY(blobId.IsValid()); + TBlobRangeLink16::TLinkId idx = 0; + for (auto&& i : BlobIds) { + if (i == blobId) { + return idx; + } + ++idx; + } + return std::nullopt; + } + + ui64 GetMetadataMemorySize() const { + return GetBlobIds().size() * sizeof(TUnifiedBlobId); + } + + TBlobRangeLink16::TLinkId GetBlobIdxVerified(const TUnifiedBlobId& blobId) const { + auto result = GetBlobIdxOptional(blobId); + AFL_VERIFY(result); + return *result; + } +}; + +class TPortionMeta: public TPortionMetaBase { private: + using TBase = TPortionMetaBase; NArrow::TFirstLastSpecialKeys ReplaceKeyEdges; // first and last PK rows YDB_READONLY_DEF(TString, TierName); YDB_READONLY(ui32, DeletionsCount, 0); @@ -25,7 +73,6 @@ struct TPortionMeta { YDB_READONLY(ui32, ColumnBlobBytes, 0); YDB_READONLY(ui32, IndexRawBytes, 0); YDB_READONLY(ui32, IndexBlobBytes, 0); - YDB_READONLY_DEF(std::vector, BlobIds); friend class TPortionMetaConstructor; friend class TPortionInfo; @@ -41,10 +88,7 @@ struct TPortionMeta { TSnapshot RecordSnapshotMax; void FullValidation() const { - for (auto&& i : BlobIds) { - AFL_VERIFY(i.BlobSize()); - } - AFL_VERIFY(BlobIds.size()); + TBase::FullValidation(); AFL_VERIFY(RecordsCount); AFL_VERIFY(ColumnRawBytes); AFL_VERIFY(ColumnBlobBytes); @@ -55,37 +99,10 @@ struct TPortionMeta { return ReplaceKeyEdges; } - const TUnifiedBlobId& GetBlobId(const TBlobRangeLink16::TLinkId linkId) const { - AFL_VERIFY(linkId < GetBlobIds().size()); - return BlobIds[linkId]; - } - - ui32 GetBlobIdsCount() const { - return BlobIds.size(); - } - void ResetCompactionLevel(const ui32 level) { CompactionLevel = level; } - std::optional GetBlobIdxOptional(const TUnifiedBlobId& blobId) const { - AFL_VERIFY(blobId.IsValid()); - TBlobRangeLink16::TLinkId idx = 0; - for (auto&& i : BlobIds) { - if (i == blobId) { - return idx; - } - ++idx; - } - return std::nullopt; - } - - TBlobRangeLink16::TLinkId GetBlobIdxVerified(const TUnifiedBlobId& blobId) const { - auto result = GetBlobIdxOptional(blobId); - AFL_VERIFY(result); - return *result; - } - using EProduced = NPortion::EProduced; NArrow::TReplaceKey IndexKeyStart; @@ -96,7 +113,7 @@ struct TPortionMeta { std::optional GetTierNameOptional() const; ui64 GetMetadataMemorySize() const { - return sizeof(TPortionMeta) + ReplaceKeyEdges.GetMemorySize() + BlobIds.size() * sizeof(TUnifiedBlobId); + return sizeof(TPortionMeta) + ReplaceKeyEdges.GetMemorySize() + TBase::GetMetadataMemorySize(); } NKikimrTxColumnShard::TIndexPortionMeta SerializeToProto() const;