aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.com>2024-12-24 22:42:08 +0300
committerbabenko <babenko@yandex-team.com>2024-12-24 23:24:59 +0300
commitf5146f15b473fbf5a19b782af7fde119ace0024b (patch)
tree3f0bfbb3e2fcf5246ec1039f46d8503f7473131c
parent8fa83915202633143936bfce16cf1c06653e2dce (diff)
downloadydb-f5146f15b473fbf5a19b782af7fde119ace0024b.tar.gz
Add TSingletonManager::Get[Dynamic]Config
commit_hash:21f11d9692efc088ad5412b498c01c1c7243aa8f
-rw-r--r--yt/yt/core/misc/configurable_singleton_def.cpp31
-rw-r--r--yt/yt/core/misc/configurable_singleton_def.h3
2 files changed, 31 insertions, 3 deletions
diff --git a/yt/yt/core/misc/configurable_singleton_def.cpp b/yt/yt/core/misc/configurable_singleton_def.cpp
index acad95481d..515a107d14 100644
--- a/yt/yt/core/misc/configurable_singleton_def.cpp
+++ b/yt/yt/core/misc/configurable_singleton_def.cpp
@@ -37,10 +37,10 @@ public:
THROW_ERROR_EXCEPTION("Singletons have already been configured");
}
- Config_ = config;
+ Config_ = CloneYsonStruct(config);
for (const auto& [name, traits] : Singletons()) {
- const auto& field = GetOrCrash(config->NameToConfig_, name);
+ const auto& field = GetOrCrash(Config_->NameToConfig_, name);
traits.Configure(field);
}
}
@@ -53,15 +53,29 @@ public:
THROW_ERROR_EXCEPTION("Singletons are not configured yet");
}
+ DynamicConfig_ = CloneYsonStruct(dynamicConfig);
+
for (const auto& [name, traits] : Singletons()) {
if (const auto& reconfigure = traits.Reconfigure) {
const auto& singletonConfig = GetOrCrash(Config_->NameToConfig_, name);
- const auto& singletonDynamicConfig = GetOrCrash(dynamicConfig->NameToConfig_, name);
+ const auto& singletonDynamicConfig = GetOrCrash(DynamicConfig_->NameToConfig_, name);
reconfigure(singletonConfig, singletonDynamicConfig);
}
}
}
+ TSingletonsConfigPtr GetConfig()
+ {
+ auto guard = Guard(ConfigureLock_);
+ return Config_;
+ }
+
+ TSingletonsDynamicConfigPtr GetDynamicConfig()
+ {
+ auto guard = Guard(ConfigureLock_);
+ return DynamicConfig_;
+ }
+
using TSingletonMap = THashMap<std::string, TSingletonTraits>;
const TSingletonMap& Singletons() const
@@ -79,6 +93,7 @@ private:
NThreading::TSpinLock ConfigureLock_;
TSingletonsConfigPtr Config_;
+ TSingletonsDynamicConfigPtr DynamicConfig_;
bool Configured_ = false;
};
@@ -128,6 +143,16 @@ void TSingletonManager::Reconfigure(const TSingletonsDynamicConfigPtr& dynamicCo
NDetail::TSingletonManagerImpl::Get()->Reconfigure(dynamicConfig);
}
+TSingletonsConfigPtr TSingletonManager::GetConfig()
+{
+ return NDetail::TSingletonManagerImpl::Get()->GetConfig();
+}
+
+TSingletonsDynamicConfigPtr TSingletonManager::GetDynamicConfig()
+{
+ return NDetail::TSingletonManagerImpl::Get()->GetDynamicConfig();
+}
+
////////////////////////////////////////////////////////////////////////////////
void TSingletonsConfig::Register(TRegistrar registrar)
diff --git a/yt/yt/core/misc/configurable_singleton_def.h b/yt/yt/core/misc/configurable_singleton_def.h
index 684d50e314..89ed29fcd8 100644
--- a/yt/yt/core/misc/configurable_singleton_def.h
+++ b/yt/yt/core/misc/configurable_singleton_def.h
@@ -82,6 +82,9 @@ class TSingletonManager
public:
static void Configure(const TSingletonsConfigPtr& config);
static void Reconfigure(const TSingletonsDynamicConfigPtr& dynamicConfig);
+
+ static TSingletonsConfigPtr GetConfig();
+ static TSingletonsDynamicConfigPtr GetDynamicConfig();
};
////////////////////////////////////////////////////////////////////////////////