From 555e5dc2e90396d8c3bdab570f7218f9f0132623 Mon Sep 17 00:00:00 2001 From: Semyon Yentsov Date: Fri, 20 Dec 2024 15:21:23 +0300 Subject: [PATCH 1/2] use canonized storage path as tier id --- ydb/core/kqp/ut/olap/tiering_ut.cpp | 2 +- .../abstract/storages_manager.cpp | 2 +- ydb/core/tx/columnshard/columnshard.cpp | 4 +- ydb/core/tx/columnshard/columnshard_impl.cpp | 8 +- ydb/core/tx/columnshard/columnshard_impl.h | 2 +- .../engines/scheme/tiering/tier_info.cpp | 7 +- .../engines/scheme/tiering/tier_info.h | 61 ++++------ .../engines/scheme/tiering/ya.make | 1 + ydb/core/tx/tiering/abstract/manager.cpp | 2 +- ydb/core/tx/tiering/abstract/manager.h | 7 +- ydb/core/tx/tiering/abstract/ya.make | 1 + ydb/core/tx/tiering/manager.cpp | 115 ++++++++---------- ydb/core/tx/tiering/manager.h | 37 +++--- ydb/core/tx/tiering/tier/identifier.cpp | 3 + ydb/core/tx/tiering/tier/identifier.h | 38 ++++++ ydb/core/tx/tiering/tier/ya.make | 2 + ydb/core/tx/tiering/ut/ut_tiers.cpp | 12 +- 17 files changed, 168 insertions(+), 136 deletions(-) create mode 100644 ydb/core/tx/tiering/tier/identifier.cpp create mode 100644 ydb/core/tx/tiering/tier/identifier.h diff --git a/ydb/core/kqp/ut/olap/tiering_ut.cpp b/ydb/core/kqp/ut/olap/tiering_ut.cpp index 847091530c4b..4238d0953c31 100644 --- a/ydb/core/kqp/ut/olap/tiering_ut.cpp +++ b/ydb/core/kqp/ut/olap/tiering_ut.cpp @@ -68,7 +68,7 @@ class TTestEvictionBase { UNIT_ASSERT_GT(columnRawBytes, 0); } - TestHelper->SetTiering("/Root/olapStore/olapTable", "/Root/tier1", "timestamp"); + TestHelper->SetTiering("/Root/olapStore/olapTable", "Root/tier1", "timestamp"); csController->WaitActualization(TDuration::Seconds(5)); { diff --git a/ydb/core/tx/columnshard/blobs_action/abstract/storages_manager.cpp b/ydb/core/tx/columnshard/blobs_action/abstract/storages_manager.cpp index 0902a464871a..2735ca8a0a42 100644 --- a/ydb/core/tx/columnshard/blobs_action/abstract/storages_manager.cpp +++ b/ydb/core/tx/columnshard/blobs_action/abstract/storages_manager.cpp @@ -44,7 +44,7 @@ std::shared_ptr IStoragesManager::GetOper void IStoragesManager::OnTieringModified(const std::shared_ptr& tiers) { AFL_VERIFY(tiers); for (auto&& i : tiers->GetManagers()) { - GetOperatorGuarantee(i.first)->OnTieringModified(tiers); + GetOperatorGuarantee(i.first.GetPath())->OnTieringModified(tiers); } } diff --git a/ydb/core/tx/columnshard/columnshard.cpp b/ydb/core/tx/columnshard/columnshard.cpp index f0782462de4d..b7ef9c210fef 100644 --- a/ydb/core/tx/columnshard/columnshard.cpp +++ b/ydb/core/tx/columnshard/columnshard.cpp @@ -109,7 +109,7 @@ void TColumnShard::OnActivateExecutor(const TActorContext& ctx) { Tiers->Start(Tiers); if (const auto& tiersSnapshot = NYDBTest::TControllers::GetColumnShardController()->GetOverrideTierConfigs(); !tiersSnapshot.empty()) { for (const auto& [id, tier] : tiersSnapshot) { - Tiers->UpdateTierConfig(tier, CanonizePath(id), false); + Tiers->UpdateTierConfig(tier, NTiers::TExternalStorageId(id), false); } } BackgroundSessionsManager = std::make_shared( @@ -131,7 +131,7 @@ void TColumnShard::OnActivateExecutor(const TActorContext& ctx) { void TColumnShard::Handle(TEvPrivate::TEvTieringModified::TPtr& /*ev*/, const TActorContext& /*ctx*/) { if (const auto& tiersSnapshot = NYDBTest::TControllers::GetColumnShardController()->GetOverrideTierConfigs(); !tiersSnapshot.empty()) { for (const auto& [id, tier] : tiersSnapshot) { - Tiers->UpdateTierConfig(tier, CanonizePath(id), false); + Tiers->UpdateTierConfig(tier, NTiers::TExternalStorageId(id), false); } } diff --git a/ydb/core/tx/columnshard/columnshard_impl.cpp b/ydb/core/tx/columnshard/columnshard_impl.cpp index dd74874db49f..101304e0e6ac 100644 --- a/ydb/core/tx/columnshard/columnshard_impl.cpp +++ b/ydb/core/tx/columnshard/columnshard_impl.cpp @@ -405,7 +405,7 @@ void TColumnShard::RunEnsureTable(const NKikimrTxColumnShard::TCreateTable& tabl } { - THashSet usedTiers; + THashSet usedTiers; TTableInfo table(pathId); if (tableProto.HasTtlSettings()) { const auto& ttlSettings = tableProto.GetTtlSettings(); @@ -451,7 +451,7 @@ void TColumnShard::RunAlterTable(const NKikimrTxColumnShard::TAlterTable& alterP schema = alterProto.GetSchema(); } - THashSet usedTiers; + THashSet usedTiers; if (alterProto.HasTtlSettings()) { const auto& ttlSettings = alterProto.GetTtlSettings(); *tableVerProto.MutableTtlSettings() = ttlSettings; @@ -1581,10 +1581,10 @@ void TColumnShard::Handle(NOlap::NBlobOperations::NEvents::TEvDeleteSharedBlobs: Execute(new TTxRemoveSharedBlobs(this, blobs, NActors::ActorIdFromProto(ev->Get()->Record.GetSourceActorId()), ev->Get()->Record.GetStorageId()), ctx); } -void TColumnShard::ActivateTiering(const ui64 pathId, const THashSet& usedTiers) { +void TColumnShard::ActivateTiering(const ui64 pathId, const THashSet& usedTiers) { AFL_VERIFY(Tiers); if (!usedTiers.empty()) { - AFL_INFO(NKikimrServices::TX_COLUMNSHARD)("event", "activate_tiering")("path_id", pathId)("tiers", JoinStrings(usedTiers.begin(), usedTiers.end(), ",")); + AFL_INFO(NKikimrServices::TX_COLUMNSHARD)("event", "activate_tiering")("path_id", pathId)("tier_count", usedTiers.size()); Tiers->EnablePathId(pathId, usedTiers); } else { Tiers->DisablePathId(pathId); diff --git a/ydb/core/tx/columnshard/columnshard_impl.h b/ydb/core/tx/columnshard/columnshard_impl.h index ddbb00c45d8f..f254149a1700 100644 --- a/ydb/core/tx/columnshard/columnshard_impl.h +++ b/ydb/core/tx/columnshard/columnshard_impl.h @@ -323,7 +323,7 @@ class TColumnShard: public TActor, public NTabletFlatExecutor::TTa putStatus.OnYellowChannels(Executor()); } - void ActivateTiering(const ui64 pathId, const THashSet& usedTiers); + void ActivateTiering(const ui64 pathId, const THashSet& usedTiers); void OnTieringModified(const std::optional pathId = {}); public: diff --git a/ydb/core/tx/columnshard/engines/scheme/tiering/tier_info.cpp b/ydb/core/tx/columnshard/engines/scheme/tiering/tier_info.cpp index a36e02595d38..3dd26b69bbbb 100644 --- a/ydb/core/tx/columnshard/engines/scheme/tiering/tier_info.cpp +++ b/ydb/core/tx/columnshard/engines/scheme/tiering/tier_info.cpp @@ -25,17 +25,18 @@ TTiering::TTieringContext TTiering::GetTierToMove(const std::shared_ptr nextTierDuration; for (auto& tierRef : GetOrderedTiers()) { auto& tierInfo = tierRef.Get(); - if (skipEviction && tierInfo.GetName() != NTiering::NCommon::DeleteTierName) { + if (skipEviction && tierInfo.GetStorageId()) { continue; } + TString tierName = tierInfo.GetStorageId() ? tierInfo.GetStorageId()->GetPath() : NTiering::NCommon::DeleteTierName; auto mpiOpt = tierInfo.ScalarToInstant(max); Y_ABORT_UNLESS(mpiOpt); const TInstant maxTieringPortionInstant = *mpiOpt; const TDuration dWaitLocal = maxTieringPortionInstant - tierInfo.GetEvictInstant(now); if (!dWaitLocal) { - return TTieringContext(tierInfo.GetName(), tierInfo.GetEvictInstant(now) - maxTieringPortionInstant, nextTierName, nextTierDuration); + return TTieringContext(tierName, tierInfo.GetEvictInstant(now) - maxTieringPortionInstant, nextTierName, nextTierDuration); } else { - nextTierName = tierInfo.GetName(); + nextTierName = tierName; nextTierDuration = dWaitLocal; } } diff --git a/ydb/core/tx/columnshard/engines/scheme/tiering/tier_info.h b/ydb/core/tx/columnshard/engines/scheme/tiering/tier_info.h index 6097f85ee0c4..7ea4cf6dfd9e 100644 --- a/ydb/core/tx/columnshard/engines/scheme/tiering/tier_info.h +++ b/ydb/core/tx/columnshard/engines/scheme/tiering/tier_info.h @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -16,7 +17,7 @@ namespace NKikimr::NOlap { class TTierInfo { private: - YDB_READONLY_DEF(TString, Name); + YDB_READONLY_DEF(std::optional, StorageId); YDB_READONLY_DEF(TString, EvictColumnName); YDB_READONLY_DEF(TDuration, EvictDuration); @@ -27,12 +28,12 @@ class TTierInfo { return NTiering::NCommon::DeleteTierName; } - TTierInfo(const TString& tierName, TDuration evictDuration, const TString& column, ui32 unitsInSecond = 0) - : Name(tierName) + TTierInfo(const std::optional& storage, TDuration evictDuration, const TString& column, + ui32 unitsInSecond = 0) + : StorageId(storage) , EvictColumnName(column) , EvictDuration(evictDuration) , TtlUnitsInSecond(unitsInSecond) { - Y_ABORT_UNLESS(!!Name); Y_ABORT_UNLESS(!!EvictColumnName); } @@ -72,7 +73,8 @@ class TTierInfo { TString GetDebugString() const { TStringBuilder sb; - sb << "name=" << Name << ";duration=" << EvictDuration << ";column=" << EvictColumnName << ";serializer="; + sb << "storage=" << (StorageId ? StorageId->GetPath() : "") << ";duration=" << EvictDuration << ";column=" << EvictColumnName + << ";serializer="; if (Serializer) { sb << Serializer->DebugString(); } else { @@ -95,19 +97,19 @@ class TTierRef { if (Info->GetEvictDuration() > b.Info->GetEvictDuration()) { return true; } else if (Info->GetEvictDuration() == b.Info->GetEvictDuration()) { - if (Info->GetName() == NTiering::NCommon::DeleteTierName) { + if (!Info->GetStorageId()) { return true; - } else if (b.Info->GetName() == NTiering::NCommon::DeleteTierName) { + } else if (!b.Info->GetStorageId()) { return false; } - return Info->GetName() > b.Info->GetName(); // add stability: smaller name is hotter + return *Info->GetStorageId() > *b.Info->GetStorageId(); // add stability: smaller name is hotter } return false; } bool operator == (const TTierRef& b) const { return Info->GetEvictDuration() == b.Info->GetEvictDuration() - && Info->GetName() == b.Info->GetName(); + && Info->GetStorageId() == b.Info->GetStorageId(); } const TTierInfo& Get() const { @@ -124,8 +126,7 @@ class TTierRef { class TTiering { using TProto = NKikimrSchemeOp::TColumnDataLifeCycle::TTtl; - using TTiersMap = THashMap>; - TTiersMap TierByName; + using TTiersMap = THashMap>; TSet OrderedTiers; std::optional TTLColumnName; public: @@ -169,18 +170,6 @@ class TTiering { TTieringContext GetTierToMove(const std::shared_ptr& max, const TInstant now, const bool skipEviction) const; - const TTiersMap& GetTierByName() const { - return TierByName; - } - - std::shared_ptr GetTierByName(const TString& name) const { - auto it = TierByName.find(name); - if (it == TierByName.end()) { - return nullptr; - } - return it->second; - } - const TSet& GetOrderedTiers() const { return OrderedTiers; } @@ -203,20 +192,10 @@ class TTiering { return false; } - TierByName.emplace(tier->GetName(), tier); OrderedTiers.emplace(tier); return true; } - std::optional GetSerializer(const TString& name) const { - auto it = TierByName.find(name); - if (it != TierByName.end()) { - Y_ABORT_UNLESS(!name.empty()); - return it->second->GetSerializer(); - } - return {}; - } - TConclusionStatus DeserializeFromProto(const TProto& serialized) { if (serialized.HasExpireAfterBytes()) { return TConclusionStatus::Fail("TTL by size is not supported."); @@ -264,24 +243,26 @@ class TTiering { TString GetDebugString() const { TStringBuilder sb; + sb << "["; for (auto&& i : OrderedTiers) { sb << i.Get().GetDebugString() << "; "; } + sb << "]"; return sb; } - THashSet GetUsedTiers() const { - THashSet tiers; - for (const auto& [name, info] : TierByName) { - if (name != NTiering::NCommon::DeleteTierName) { - tiers.emplace(name); + THashSet GetUsedTiers() const { + THashSet tiers; + for (const auto& tier : OrderedTiers) { + if (const auto& storageId = tier.Get().GetStorageId()) { + tiers.emplace(*storageId); } } return tiers; } - static THashSet GetUsedTiers(const TProto& ttlSettings) { - THashSet usedTiers; + static THashSet GetUsedTiers(const TProto& ttlSettings) { + THashSet usedTiers; for (const auto& tier : ttlSettings.GetTiers()) { if (tier.HasEvictToExternalStorage()) { usedTiers.emplace(CanonizePath(tier.GetEvictToExternalStorage().GetStorage())); diff --git a/ydb/core/tx/columnshard/engines/scheme/tiering/ya.make b/ydb/core/tx/columnshard/engines/scheme/tiering/ya.make index 45f21958d0d8..f63e1c562d12 100644 --- a/ydb/core/tx/columnshard/engines/scheme/tiering/ya.make +++ b/ydb/core/tx/columnshard/engines/scheme/tiering/ya.make @@ -7,6 +7,7 @@ SRCS( PEERDIR( ydb/core/formats/arrow/serializer + ydb/core/tx/tiering/tier ) END() diff --git a/ydb/core/tx/tiering/abstract/manager.cpp b/ydb/core/tx/tiering/abstract/manager.cpp index dc6f9c16cd1e..17f82056d420 100644 --- a/ydb/core/tx/tiering/abstract/manager.cpp +++ b/ydb/core/tx/tiering/abstract/manager.cpp @@ -3,7 +3,7 @@ namespace NKikimr::NColumnShard { -const NTiers::TManager& ITiersManager::GetManagerVerified(const TString& tierId) const { +const NTiers::TManager& ITiersManager::GetManagerVerified(const NTiers::TExternalStorageId& tierId) const { auto* result = GetManagerOptional(tierId); AFL_VERIFY(result)("tier_id", tierId); return *result; diff --git a/ydb/core/tx/tiering/abstract/manager.h b/ydb/core/tx/tiering/abstract/manager.h index 994ecbfa6b4e..63d440dcc1ed 100644 --- a/ydb/core/tx/tiering/abstract/manager.h +++ b/ydb/core/tx/tiering/abstract/manager.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include namespace NKikimr::NColumnShard { namespace NTiers { @@ -9,9 +10,9 @@ class TManager; class ITiersManager { public: - const NTiers::TManager& GetManagerVerified(const TString& tierId) const; - virtual const NTiers::TManager* GetManagerOptional(const TString& tierId) const = 0; - virtual const std::map& GetManagers() const = 0; + const NTiers::TManager& GetManagerVerified(const NTiers::TExternalStorageId& tierId) const; + virtual const NTiers::TManager* GetManagerOptional(const NTiers::TExternalStorageId& tierId) const = 0; + virtual const std::map& GetManagers() const = 0; virtual ~ITiersManager() = default; }; diff --git a/ydb/core/tx/tiering/abstract/ya.make b/ydb/core/tx/tiering/abstract/ya.make index cd240f0f8cd6..53111aa636f0 100644 --- a/ydb/core/tx/tiering/abstract/ya.make +++ b/ydb/core/tx/tiering/abstract/ya.make @@ -6,6 +6,7 @@ SRCS( PEERDIR( ydb/library/actors/core + ydb/core/tx/tiering/tier ) END() diff --git a/ydb/core/tx/tiering/manager.cpp b/ydb/core/tx/tiering/manager.cpp index d937aaa95420..a9f1a1b37c66 100644 --- a/ydb/core/tx/tiering/manager.cpp +++ b/ydb/core/tx/tiering/manager.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -18,7 +19,7 @@ class TTiersManager::TActor: public TActorBootstrapped { std::shared_ptr Owner; IRetryPolicy::TPtr RetryPolicy; - THashMap RetryStateByObject; + THashMap RetryStateByObject; NMetadata::NFetcher::ISnapshotsFetcher::TPtr SecretsFetcher; TActorId TiersFetcher; @@ -27,29 +28,23 @@ class TTiersManager::TActor: public TActorBootstrapped { return NMetadata::NProvider::MakeServiceId(SelfId().NodeId()); } - void OnInvalidTierConfig(const TString& path) { - if (!Owner->TierRefCount.contains(path)) { - ResetRetryState(path); + void OnTierFetchingError(const NTiers::TExternalStorageId& tier) { + if (!Owner->TierRefCount.contains(tier)) { + ResetRetryState(tier); return; } AFL_DEBUG(NKikimrServices::TX_TIERING)("component", "tiers_manager")("event", "retry_watch_objects"); - auto findRetryState = RetryStateByObject.find(path); + auto findRetryState = RetryStateByObject.find(tier); if (!findRetryState) { - findRetryState = RetryStateByObject.emplace(path, RetryPolicy->CreateRetryState()).first; + findRetryState = RetryStateByObject.emplace(tier, RetryPolicy->CreateRetryState()).first; } auto retryDelay = findRetryState->second->GetNextRetryDelay(); - AFL_VERIFY(retryDelay)("object", path); - ActorContext().Schedule(*retryDelay, std::make_unique(SelfId(), TiersFetcher, new NTiers::TEvWatchSchemeObject(std::vector({ path })))); + AFL_VERIFY(retryDelay)("object", tier.GetPath()); + ActorContext().Schedule(*retryDelay, std::make_unique(SelfId(), TiersFetcher, new NTiers::TEvWatchSchemeObject(std::vector({ tier.GetPath() })))); } - void ResetRetryState(const TString& path) { - RetryStateByObject.erase(path); - } - - void OnFetchingFailure(const TString& path) { - if (Owner->TierRefCount.contains(path)) { - OnInvalidTierConfig(path); - } + void ResetRetryState(const NTiers::TExternalStorageId& tier) { + RetryStateByObject.erase(tier); } STATEFN(StateMain) { @@ -82,33 +77,33 @@ class TTiersManager::TActor: public TActorBootstrapped { void Handle(NTiers::TEvNotifySchemeObjectUpdated::TPtr& ev) { AFL_DEBUG(NKikimrServices::TX_TIERING)("component", "tiering_manager")("event", "object_updated")("path", ev->Get()->GetObjectPath()); - const TString& objectPath = ev->Get()->GetObjectPath(); + const NTiers::TExternalStorageId tierId(ev->Get()->GetObjectPath()); const auto& description = ev->Get()->GetDescription(); - ResetRetryState(objectPath); + ResetRetryState(tierId); if (description.GetSelf().GetPathType() == NKikimrSchemeOp::EPathTypeExternalDataSource) { NTiers::TTierConfig tier; if (const auto status = tier.DeserializeFromProto(description.GetExternalDataSourceDescription()); status.IsFail()) { AFL_WARN(NKikimrServices::TX_TIERING)("event", "fetched_invalid_tier_settings")("error", status.GetErrorMessage()); - OnInvalidTierConfig(objectPath); + OnTierFetchingError(tierId); return; } - Owner->UpdateTierConfig(tier, objectPath); + Owner->UpdateTierConfig(tier, tierId); } else { - AFL_WARN(false)("error", "invalid_object_type")("type", static_cast(description.GetSelf().GetPathType()))("path", objectPath); - OnInvalidTierConfig(objectPath); + AFL_WARN(false)("error", "invalid_object_type")("type", static_cast(description.GetSelf().GetPathType()))("path", tierId.GetPath()); + OnTierFetchingError(tierId); } } void Handle(NTiers::TEvNotifySchemeObjectDeleted::TPtr& ev) { AFL_DEBUG(NKikimrServices::TX_TIERING)("component", "tiering_manager")("event", "object_deleted")("name", ev->Get()->GetObjectPath()); - OnInvalidTierConfig(ev->Get()->GetObjectPath()); + OnTierFetchingError(ev->Get()->GetObjectPath()); } void Handle(NTiers::TEvSchemeObjectResolutionFailed::TPtr& ev) { const TString objectPath = ev->Get()->GetObjectPath(); AFL_WARN(NKikimrServices::TX_TIERING)("event", "object_resolution_failed")("path", objectPath)( "reason", static_cast(ev->Get()->GetReason())); - OnInvalidTierConfig(objectPath); + OnTierFetchingError(objectPath); } void Handle(NTiers::TEvWatchSchemeObject::TPtr& ev) { @@ -141,7 +136,7 @@ class TTiersManager::TActor: public TActorBootstrapped { namespace NTiers { TManager& TManager::Restart(const TTierConfig& config, std::shared_ptr secrets) { - ALS_DEBUG(NKikimrServices::TX_TIERING) << "Restarting tier '" << TierName << "' at tablet " << TabletId; + ALS_DEBUG(NKikimrServices::TX_TIERING) << "Restarting tier '" << TierId.GetPath() << "' at tablet " << TabletId; Stop(); Start(config, secrets); return *this; @@ -149,26 +144,26 @@ TManager& TManager::Restart(const TTierConfig& config, std::shared_ptr secrets) { - AFL_VERIFY(!S3Settings)("tier", TierName)("event", "already started"); + AFL_VERIFY(!S3Settings)("tier", TierId.GetPath())("event", "already started"); auto patchedConfig = config.GetPatchedConfig(secrets); if (patchedConfig.IsFail()) { AFL_ERROR(NKikimrServices::TX_TIERING)("error", "cannot_read_secrets")("reason", patchedConfig.GetErrorMessage()); return false; } S3Settings = patchedConfig.DetachResult(); - ALS_DEBUG(NKikimrServices::TX_TIERING) << "Tier '" << TierName << "' started at tablet " << TabletId; + ALS_DEBUG(NKikimrServices::TX_TIERING) << "Tier '" << TierId.GetPath() << "' started at tablet " << TabletId; return true; } -TManager::TManager(const ui64 tabletId, const NActors::TActorId& tabletActorId, const TString& tierName) +TManager::TManager(const ui64 tabletId, const NActors::TActorId& tabletActorId, const TExternalStorageId& tierName) : TabletId(tabletId) , TabletActorId(tabletActorId) - , TierName(tierName) { + , TierId(tierName) { } NArrow::NSerialization::TSerializerContainer ConvertCompression(const NKikimrSchemeOp::TCompressionOptions& compressionProto) { @@ -184,31 +179,31 @@ NArrow::NSerialization::TSerializerContainer ConvertCompression(const NKikimrSch } } -TTiersManager::TTierRefGuard::TTierRefGuard(const TString& tierName, TTiersManager& owner) - : TierName(tierName) +TTiersManager::TTierRefGuard::TTierRefGuard(const NTiers::TExternalStorageId& tierId, TTiersManager& owner) + : TierId(tierId) , Owner(&owner) { - if (!Owner->TierRefCount.contains(TierName)) { - Owner->RegisterTier(tierName); + if (!Owner->TierRefCount.contains(TierId)) { + Owner->RegisterTier(tierId); } - ++Owner->TierRefCount[TierName]; + ++Owner->TierRefCount[TierId]; } TTiersManager::TTierRefGuard::~TTierRefGuard() { if (Owner) { - auto findTier = Owner->TierRefCount.FindPtr(TierName); + auto findTier = Owner->TierRefCount.FindPtr(TierId); AFL_VERIFY(findTier); AFL_VERIFY(*findTier); --*findTier; if (!*findTier) { - AFL_VERIFY(Owner->TierRefCount.erase(TierName)); - Owner->UnregisterTier(TierName); + AFL_VERIFY(Owner->TierRefCount.erase(TierId)); + Owner->UnregisterTier(TierId); } } } void TTiersManager::OnConfigsUpdated(bool notifyShard) { - for (auto& [tierName, manager] : Managers) { - auto* findTierConfig = TierConfigs.FindPtr(tierName); + for (auto& [tierId, manager] : Managers) { + auto* findTierConfig = TierConfigs.FindPtr(tierId); if (Secrets && findTierConfig) { if (manager.IsReady()) { manager.Restart(*findTierConfig, Secrets); @@ -216,7 +211,7 @@ void TTiersManager::OnConfigsUpdated(bool notifyShard) { manager.Start(*findTierConfig, Secrets); } } else { - AFL_DEBUG(NKikimrServices::TX_TIERING)("event", "skip_tier_manager_reloading")("tier", tierName)("has_secrets", !!Secrets)( + AFL_DEBUG(NKikimrServices::TX_TIERING)("event", "skip_tier_manager_reloading")("tier", tierId.GetPath())("has_secrets", !!Secrets)( "found_tier_config", !!findTierConfig); } } @@ -228,21 +223,21 @@ void TTiersManager::OnConfigsUpdated(bool notifyShard) { AFL_DEBUG(NKikimrServices::TX_TIERING)("event", "configs_updated")("configs", DebugString()); } -void TTiersManager::RegisterTier(const TString& name) { - auto emplaced = Managers.emplace(name, NTiers::TManager(TabletId, TabletActorId, name)); +void TTiersManager::RegisterTier(const NTiers::TExternalStorageId& tierId) { + auto emplaced = Managers.emplace(tierId, NTiers::TManager(TabletId, TabletActorId, tierId)); AFL_VERIFY(emplaced.second); - auto* findConfig = TierConfigs.FindPtr(name); + auto* findConfig = TierConfigs.FindPtr(tierId); if (Secrets && findConfig) { emplaced.first->second.Start(*findConfig, Secrets); } else { - AFL_DEBUG(NKikimrServices::TX_TIERING)("event", "skip_tier_manager_start")("tier", name)("has_secrets", !!Secrets)( + AFL_DEBUG(NKikimrServices::TX_TIERING)("event", "skip_tier_manager_start")("tier", tierId.GetPath())("has_secrets", !!Secrets)( "found_tier_config", !!findConfig); } } -void TTiersManager::UnregisterTier(const TString& name) { - auto findManager = Managers.find(name); +void TTiersManager::UnregisterTier(const NTiers::TExternalStorageId& tierId) { + auto findManager = Managers.find(tierId); AFL_VERIFY(findManager != Managers.end()); findManager->second.Stop(); Managers.erase(findManager); @@ -269,7 +264,7 @@ TTiersManager& TTiersManager::Stop(const bool needStopActor) { return *this; } -const NTiers::TManager* TTiersManager::GetManagerOptional(const TString& tierId) const { +const NTiers::TManager* TTiersManager::GetManagerOptional(const NTiers::TExternalStorageId& tierId) const { auto it = Managers.find(tierId); if (it != Managers.end()) { return &it->second; @@ -278,17 +273,16 @@ const NTiers::TManager* TTiersManager::GetManagerOptional(const TString& tierId) } } -void TTiersManager::EnablePathId(const ui64 pathId, const THashSet& usedTiers) { +void TTiersManager::EnablePathId(const ui64 pathId, const THashSet& usedTiers) { AFL_VERIFY(Actor)("error", "tiers_manager_is_not_started"); auto& tierRefs = UsedTiers[pathId]; tierRefs.clear(); - for (const TString& tierName : usedTiers) { - AFL_VERIFY(tierName == CanonizePath(tierName))("current", tierName)("canonized", CanonizePath(tierName)); - tierRefs.emplace_back(tierName, *this); - if (!TierConfigs.contains(tierName)) { + for (const NTiers::TExternalStorageId& tierId : usedTiers) { + tierRefs.emplace_back(tierId, *this); + if (!TierConfigs.contains(tierId)) { const auto& actorContext = NActors::TActivationContext::AsActorContext(); AFL_VERIFY(&actorContext)("error", "no_actor_context"); - actorContext.Send(Actor->SelfId(), new NTiers::TEvWatchSchemeObject({ tierName })); + actorContext.Send(Actor->SelfId(), new NTiers::TEvWatchSchemeObject({ tierId.GetPath() })); } } OnConfigsUpdated(false); @@ -306,10 +300,9 @@ void TTiersManager::UpdateSecretsSnapshot(std::shared_ptr +#include #include #include @@ -22,7 +23,7 @@ class TManager { private: ui64 TabletId = 0; NActors::TActorId TabletActorId; - TString TierName; + TExternalStorageId TierId; NActors::TActorId StorageActorId; std::optional S3Settings; public: @@ -31,7 +32,7 @@ class TManager { return *S3Settings; } - TManager(const ui64 tabletId, const NActors::TActorId& tabletActorId, const TString& tierName); + TManager(const ui64 tabletId, const NActors::TActorId& tabletActorId, const TExternalStorageId& tierId); bool IsReady() const { return !!S3Settings; @@ -47,21 +48,25 @@ class TTiersManager: public ITiersManager { friend class TTierRef; class TTierRefGuard: public TMoveOnly { private: - YDB_READONLY_DEF(TString, TierName); + NTiers::TExternalStorageId TierId; TTiersManager* Owner; public: - TTierRefGuard(const TString& tierName, TTiersManager& owner); + const NTiers::TExternalStorageId& GetTier() const { + return TierId; + } + + TTierRefGuard(const NTiers::TExternalStorageId& tierId, TTiersManager& owner); ~TTierRefGuard(); TTierRefGuard(TTierRefGuard&& other) - : TierName(other.TierName) + : TierId(other.TierId) , Owner(other.Owner) { other.Owner = nullptr; } TTierRefGuard& operator=(TTierRefGuard&& other) { std::swap(Owner, other.Owner); - std::swap(TierName, other.TierName); + std::swap(TierId, other.TierId); return *this; } }; @@ -69,7 +74,7 @@ class TTiersManager: public ITiersManager { private: class TActor; friend class TActor; - using TManagers = std::map; + using TManagers = std::map; ui64 TabletId = 0; const TActorId TabletActorId; @@ -77,19 +82,19 @@ class TTiersManager: public ITiersManager { IActor* Actor = nullptr; TManagers Managers; - using TTierRefCount = THashMap; + using TTierRefCount = THashMap; using TTierRefsByPathId = THashMap>; YDB_READONLY_DEF(TTierRefCount, TierRefCount); YDB_READONLY_DEF(TTierRefsByPathId, UsedTiers); - using TTierByName = THashMap; - YDB_READONLY_DEF(TTierByName, TierConfigs); + using TTierById = THashMap; + YDB_READONLY_DEF(TTierById, TierConfigs); YDB_READONLY_DEF(std::shared_ptr, Secrets); private: void OnConfigsUpdated(bool notifyShard = true); - void RegisterTier(const TString& name); - void UnregisterTier(const TString& name); + void RegisterTier(const NTiers::TExternalStorageId& name); + void UnregisterTier(const NTiers::TExternalStorageId& name); public: TTiersManager(const ui64 tabletId, const TActorId& tabletActorId, std::function shardCallback = {}) @@ -99,21 +104,21 @@ class TTiersManager: public ITiersManager { , Secrets(std::make_shared(TInstant::Zero())) { } TActorId GetActorId() const; - void EnablePathId(const ui64 pathId, const THashSet& usedTiers); + void EnablePathId(const ui64 pathId, const THashSet& usedTiers); void DisablePathId(const ui64 pathId); void UpdateSecretsSnapshot(std::shared_ptr secrets); - void UpdateTierConfig(const NTiers::TTierConfig& config, const TString& tierName, const bool notifyShard = true); + void UpdateTierConfig(const NTiers::TTierConfig& config, const NTiers::TExternalStorageId& tierId, const bool notifyShard = true); bool AreConfigsComplete() const; TString DebugString(); TTiersManager& Start(std::shared_ptr ownerPtr); TTiersManager& Stop(const bool needStopActor); - virtual const std::map& GetManagers() const override { + virtual const std::map& GetManagers() const override { return Managers; } - virtual const NTiers::TManager* GetManagerOptional(const TString& tierId) const override; + virtual const NTiers::TManager* GetManagerOptional(const NTiers::TExternalStorageId& tierId) const override; }; } diff --git a/ydb/core/tx/tiering/tier/identifier.cpp b/ydb/core/tx/tiering/tier/identifier.cpp new file mode 100644 index 000000000000..9bb067a1eed7 --- /dev/null +++ b/ydb/core/tx/tiering/tier/identifier.cpp @@ -0,0 +1,3 @@ +#include "identifier.h" + +namespace NKikimr::NColumnShard::NTiers {} diff --git a/ydb/core/tx/tiering/tier/identifier.h b/ydb/core/tx/tiering/tier/identifier.h new file mode 100644 index 000000000000..9dc59b563136 --- /dev/null +++ b/ydb/core/tx/tiering/tier/identifier.h @@ -0,0 +1,38 @@ +#pragma once + +#include + +#include + +#include + +namespace NKikimr::NColumnShard::NTiers { + +class TExternalStorageId { +private: + YDB_READONLY_DEF(TString, Path); + +public: + TExternalStorageId(const TString& path) + : Path(CanonizePath(path)) { + } + + bool operator<(const TExternalStorageId& other) const { + return Path < other.Path; + } + bool operator>(const TExternalStorageId& other) const { + return Path > other.Path; + } + bool operator==(const TExternalStorageId& other) const { + return Path == other.Path; + } +}; + +} // namespace NKikimr::NColumnShard::NTiers + +template <> +struct THash { + inline ui64 operator()(const NKikimr::NColumnShard::NTiers::TExternalStorageId& x) const noexcept { + return THash()(x.GetPath()); + } +}; diff --git a/ydb/core/tx/tiering/tier/ya.make b/ydb/core/tx/tiering/tier/ya.make index 32f06144cbd8..297e1d674abe 100644 --- a/ydb/core/tx/tiering/tier/ya.make +++ b/ydb/core/tx/tiering/tier/ya.make @@ -2,9 +2,11 @@ LIBRARY() SRCS( object.cpp + identifier.cpp ) PEERDIR( + ydb/core/base ydb/library/conclusion ydb/services/metadata/secret/accessor ) diff --git a/ydb/core/tx/tiering/ut/ut_tiers.cpp b/ydb/core/tx/tiering/ut/ut_tiers.cpp index 59f3ddf8a177..916c0cb3a708 100644 --- a/ydb/core/tx/tiering/ut/ut_tiers.cpp +++ b/ydb/core/tx/tiering/ut/ut_tiers.cpp @@ -150,7 +150,7 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { class TTestCSEmulator: public NActors::TActorBootstrapped { private: using TBase = NActors::TActorBootstrapped; - THashSet ExpectedTiers; + THashSet ExpectedTiers; TInstant Start; std::shared_ptr Manager; @@ -180,7 +180,7 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { return notFoundTiers.empty(); } - const THashMap& GetTierConfigs() { + const THashMap& GetTierConfigs() { return Manager->GetTierConfigs(); } @@ -193,9 +193,15 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { Manager->EnablePathId(0, ExpectedTiers); } - TTestCSEmulator(THashSet expectedTiers) + TTestCSEmulator(THashSet expectedTiers) : ExpectedTiers(std::move(expectedTiers)) { } + + TTestCSEmulator(const std::initializer_list& expectedTiers) { + for (const auto& tier : expectedTiers) { + ExpectedTiers.emplace(tier); + } + } }; class TEmulatorAlterController: public NMetadata::NModifications::IAlterController { From 2c497ceec1181b1588a1695757b99707de84c008 Mon Sep 17 00:00:00 2001 From: Semyon Yentsov Date: Fri, 20 Dec 2024 21:29:50 +0300 Subject: [PATCH 2/2] fix build --- ydb/core/tx/tiering/ut/ut_tiers.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ydb/core/tx/tiering/ut/ut_tiers.cpp b/ydb/core/tx/tiering/ut/ut_tiers.cpp index 916c0cb3a708..e451f7150f73 100644 --- a/ydb/core/tx/tiering/ut/ut_tiers.cpp +++ b/ydb/core/tx/tiering/ut/ut_tiers.cpp @@ -257,7 +257,7 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { TTestCSEmulator* emulator = new TTestCSEmulator({ "/Root/tier1", "/Root/tier2" }); runtime.Register(emulator); emulator->CheckRuntime(runtime); - UNIT_ASSERT_EQUAL(emulator->GetTierConfigs().at("/Root/tier1").GetProtoConfig().GetBucket(), "abc"); + UNIT_ASSERT_EQUAL(emulator->GetTierConfigs().at(NTiers::TExternalStorageId("/Root/tier1")).GetProtoConfig().GetBucket(), "abc"); } Cerr << "Initialization finished" << Endl; { @@ -313,7 +313,7 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { TTestCSEmulator* emulator = new TTestCSEmulator({ "/Root/tier1" }); runtime.Register(emulator); emulator->CheckRuntime(runtime); - UNIT_ASSERT_EQUAL(emulator->GetTierConfigs().at("/Root/tier1").GetProtoConfig().GetBucket(), "abc1"); + UNIT_ASSERT_EQUAL(emulator->GetTierConfigs().at(NTiers::TExternalStorageId("/Root/tier1")).GetProtoConfig().GetBucket(), "abc1"); } lHelper.CreateExternalDataSource("/Root/tier2", "http://fake.fake/abc2"); @@ -321,8 +321,8 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { TTestCSEmulator* emulator = new TTestCSEmulator({ "/Root/tier1", "/Root/tier2" }); runtime.Register(emulator); emulator->CheckRuntime(runtime); - UNIT_ASSERT_EQUAL(emulator->GetTierConfigs().at("/Root/tier1").GetProtoConfig().GetBucket(), "abc1"); - UNIT_ASSERT_EQUAL(emulator->GetTierConfigs().at("/Root/tier2").GetProtoConfig().GetBucket(), "abc2"); + UNIT_ASSERT_EQUAL(emulator->GetTierConfigs().at(NTiers::TExternalStorageId("/Root/tier1")).GetProtoConfig().GetBucket(), "abc1"); + UNIT_ASSERT_EQUAL(emulator->GetTierConfigs().at(NTiers::TExternalStorageId("/Root/tier2")).GetProtoConfig().GetBucket(), "abc2"); } lHelper.CreateTestOlapTable("olapTable"); @@ -438,7 +438,7 @@ Y_UNIT_TEST_SUITE(ColumnShardTiers) { TTestCSEmulator* emulator = new TTestCSEmulator({ "/Root/tier1", "/Root/tier2" }); runtime.Register(emulator); emulator->CheckRuntime(runtime); - UNIT_ASSERT_VALUES_EQUAL(emulator->GetTierConfigs().at("/Root/tier1").GetProtoConfig().GetEndpoint(), TierEndpoint); + UNIT_ASSERT_VALUES_EQUAL(emulator->GetTierConfigs().at(NTiers::TExternalStorageId("/Root/tier1")).GetProtoConfig().GetEndpoint(), TierEndpoint); } lHelper.CreateTestOlapTable("olapTable", 2);