From 3e9b9a08323d4a91ae27639e3841666c9749060e Mon Sep 17 00:00:00 2001 From: ivanmorozov333 Date: Tue, 24 Dec 2024 22:00:07 +0300 Subject: [PATCH] fix schema construction with cached objects (#12935) --- .../tx/columnshard/engines/scheme/index_info.h | 8 +------- .../columnshard/engines/scheme/objects_cache.h | 16 ++++------------ 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/ydb/core/tx/columnshard/engines/scheme/index_info.h b/ydb/core/tx/columnshard/engines/scheme/index_info.h index 420347ae7803..e4b3534cfd14 100644 --- a/ydb/core/tx/columnshard/engines/scheme/index_info.h +++ b/ydb/core/tx/columnshard/engines/scheme/index_info.h @@ -80,13 +80,7 @@ struct TIndexInfo: public IIndexInfo { AFL_VERIFY(arrowType.ok()); auto f = std::make_shared(column.Name, arrowType.ValueUnsafe(), !column.NotNull); if (cache) { - auto fFound = cache->GetField(f->ToString(true)); - if (!fFound) { - cache->RegisterField(f->ToString(true), f); - return f; - } else { - return fFound; - } + return cache->GetOrInsertField(f); } else { return f; } diff --git a/ydb/core/tx/columnshard/engines/scheme/objects_cache.h b/ydb/core/tx/columnshard/engines/scheme/objects_cache.h index fabd90894383..cf7dd7793eb6 100644 --- a/ydb/core/tx/columnshard/engines/scheme/objects_cache.h +++ b/ydb/core/tx/columnshard/engines/scheme/objects_cache.h @@ -36,23 +36,14 @@ class TSchemaObjectsCache { return *it; } - void RegisterField(const TString& fingerprint, const std::shared_ptr& f) { - AFL_TRACE(NKikimrServices::TX_COLUMNSHARD)("event", "register_field")("fp", fingerprint)("f", f->ToString()); - TGuard lock(FieldsMutex); - AFL_VERIFY(Fields.emplace(fingerprint, f).second); - } - void RegisterColumnFeatures(const TString& fingerprint, const std::shared_ptr& f) { - AFL_TRACE(NKikimrServices::TX_COLUMNSHARD)("event", "register_column_features")("fp", fingerprint)("info", f->DebugString()); - TGuard lock(FeaturesMutex); - AFL_VERIFY(ColumnFeatures.emplace(fingerprint, f).second); - } - std::shared_ptr GetField(const TString& fingerprint) const { + std::shared_ptr GetOrInsertField(const std::shared_ptr& f) { TGuard lock(FieldsMutex); + const TString fingerprint = f->ToString(true); auto it = Fields.find(fingerprint); if (it == Fields.end()) { AFL_TRACE(NKikimrServices::TX_COLUMNSHARD)("event", "get_field_miss")("fp", fingerprint)("count", Fields.size())( "acc", AcceptionFieldsCount); - return nullptr; + it = Fields.emplace(fingerprint, f).first; } if (++AcceptionFieldsCount % 1000 == 0) { AFL_TRACE(NKikimrServices::TX_COLUMNSHARD)("event", "get_field_accept")("fp", fingerprint)("count", Fields.size())( @@ -60,6 +51,7 @@ class TSchemaObjectsCache { } return it->second; } + template TConclusion> GetOrCreateColumnFeatures(const TString& fingerprint, const TConstructor& constructor) { TGuard lock(FeaturesMutex);