diff options
| author | vporyadke <[email protected]> | 2024-06-11 10:01:25 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-06-11 10:01:25 +0200 |
| commit | 2dbb024ac08e9629dc89169c673ee44abf2d2dac (patch) | |
| tree | 0f7e7b2300a495736c7d64a5bb287939a11380ff | |
| parent | c72cf7b6b4ec715df13a91ffe03e28044f5f5fe4 (diff) | |
db metadata cache: feature flag + config (#5214)
| -rw-r--r-- | ydb/core/base/appdata.cpp | 2 | ||||
| -rw-r--r-- | ydb/core/base/appdata_fwd.h | 2 | ||||
| -rw-r--r-- | ydb/core/cms/console/configs_dispatcher.cpp | 1 | ||||
| -rw-r--r-- | ydb/core/driver_lib/run/run.cpp | 4 | ||||
| -rw-r--r-- | ydb/core/grpc_services/db_metadata_cache.h | 71 | ||||
| -rw-r--r-- | ydb/core/protos/config.proto | 5 | ||||
| -rw-r--r-- | ydb/core/protos/console_config.proto | 1 | ||||
| -rw-r--r-- | ydb/core/protos/feature_flags.proto | 1 |
8 files changed, 73 insertions, 14 deletions
diff --git a/ydb/core/base/appdata.cpp b/ydb/core/base/appdata.cpp index 385acfe8dd1..ca40e853715 100644 --- a/ydb/core/base/appdata.cpp +++ b/ydb/core/base/appdata.cpp @@ -60,6 +60,7 @@ struct TAppData::TImpl { NKikimrConfig::TBackgroundCleaningConfig BackgroundCleaningConfig; NKikimrConfig::TGraphConfig GraphConfig; NKikimrSharedCache::TSharedCacheConfig SharedCacheConfig; + NKikimrConfig::TMetadataCacheConfig MetadataCacheConfig; }; TAppData::TAppData( @@ -111,6 +112,7 @@ TAppData::TAppData( , BackgroundCleaningConfig(Impl->BackgroundCleaningConfig) , GraphConfig(Impl->GraphConfig) , SharedCacheConfig(Impl->SharedCacheConfig) + , MetadataCacheConfig(Impl->MetadataCacheConfig) , KikimrShouldContinue(kikimrShouldContinue) {} diff --git a/ydb/core/base/appdata_fwd.h b/ydb/core/base/appdata_fwd.h index 74153ec598d..4fb175b725d 100644 --- a/ydb/core/base/appdata_fwd.h +++ b/ydb/core/base/appdata_fwd.h @@ -62,6 +62,7 @@ namespace NKikimrConfig { class TS3ProxyResolverConfig; class TBackgroundCleaningConfig; class TGraphConfig; + class TMetadataCacheConfig; } namespace NKikimrNetClassifier { @@ -211,6 +212,7 @@ struct TAppData { NKikimrConfig::TBackgroundCleaningConfig& BackgroundCleaningConfig; NKikimrConfig::TGraphConfig& GraphConfig; NKikimrSharedCache::TSharedCacheConfig& SharedCacheConfig; + NKikimrConfig::TMetadataCacheConfig& MetadataCacheConfig; bool EnforceUserTokenRequirement = false; bool EnforceUserTokenCheckRequirement = false; // check token if it was specified bool AllowHugeKeyValueDeletes = true; // delete when all clients limit deletes per request diff --git a/ydb/core/cms/console/configs_dispatcher.cpp b/ydb/core/cms/console/configs_dispatcher.cpp index 7a9d9429a15..9688829f0f9 100644 --- a/ydb/core/cms/console/configs_dispatcher.cpp +++ b/ydb/core/cms/console/configs_dispatcher.cpp @@ -65,6 +65,7 @@ const THashSet<ui32> DYNAMIC_KINDS({ (ui32)NKikimrConsole::TConfigItem::BackgroundCleaningConfigItem, (ui32)NKikimrConsole::TConfigItem::TracingConfigItem, (ui32)NKikimrConsole::TConfigItem::BlobStorageConfigItem, + (ui32)NKikimrConsole::TConfigItem::MetadataCacheConfigItem, }); const THashSet<ui32> NON_YAML_KINDS({ diff --git a/ydb/core/driver_lib/run/run.cpp b/ydb/core/driver_lib/run/run.cpp index 0bcb2e51f1c..bc4066057d2 100644 --- a/ydb/core/driver_lib/run/run.cpp +++ b/ydb/core/driver_lib/run/run.cpp @@ -1129,6 +1129,10 @@ void TKikimrRunner::InitializeAppData(const TKikimrRunConfig& runConfig) AppData->GraphConfig.CopyFrom(runConfig.AppConfig.GetGraphConfig()); } + if (runConfig.AppConfig.HasMetadataCacheConfig()) { + AppData->MetadataCacheConfig.CopyFrom(runConfig.AppConfig.GetMetadataCacheConfig()); + } + // setup resource profiles AppData->ResourceProfiles = new TResourceProfiles; if (runConfig.AppConfig.GetBootstrapConfig().ResourceProfilesSize()) diff --git a/ydb/core/grpc_services/db_metadata_cache.h b/ydb/core/grpc_services/db_metadata_cache.h index 70ddd0393ae..531ec7fbe9a 100644 --- a/ydb/core/grpc_services/db_metadata_cache.h +++ b/ydb/core/grpc_services/db_metadata_cache.h @@ -8,6 +8,8 @@ #include <ydb/core/base/feature_flags.h> #include <ydb/core/base/domain.h> #include <ydb/core/base/statestorage.h> +#include <ydb/core/cms/console/console.h> +#include <ydb/core/cms/console/configs_dispatcher.h> #include <ydb/core/health_check/health_check.h> #include <ydb/core/protos/db_metadata_cache.pb.h> @@ -34,7 +36,8 @@ public: using TBoardInfoEntries = TMap<TActorId, TEvStateStorage::TBoardInfoEntry>; private: - static constexpr TDuration TIMEOUT = TDuration::Seconds(15); + TDuration RefreshPeriod; + bool Enabled = false; const TString Path; const TString BoardPath; ui32 ActiveNode; @@ -70,7 +73,7 @@ private: void RefreshCache() { SendRequest(); - Schedule(TIMEOUT, new TEvRefreshCache()); + Schedule(RefreshPeriod, new TEvRefreshCache()); } void UpdateActiveNode() { @@ -129,7 +132,7 @@ private: void Handle(NHealthCheck::TEvSelfCheckRequestProto::TPtr& ev) { LOG_DEBUG_S(TActivationContext::AsActorContext(), NKikimrServices::DB_METADATA_CACHE, "Got request"); TInstant now = TActivationContext::Now(); - if (Result && now - LastResultUpdate <= 2 * TIMEOUT) { + if (Result && now - LastResultUpdate <= 2 * RefreshPeriod) { LOG_DEBUG_S(TActivationContext::AsActorContext(), NKikimrServices::DB_METADATA_CACHE, "Replying now"); Reply(ev->Sender); } else { @@ -139,6 +142,12 @@ private: } } + void Handle(NConsole::TEvConsole::TEvConfigNotificationRequest::TPtr& ev) { + const auto& record = ev->Get()->Record; + ApplyConfig(record.GetConfig().GetMetadataCacheConfig(), record.GetConfig().GetFeatureFlags()); + Send(ev->Sender, new NConsole::TEvConsole::TEvConfigNotificationResponse(record), 0, ev->Cookie); + } + public: TDatabaseMetadataCache(const TString& path, const ::NMonitoring::TDynamicCounterPtr& counters) : Path(path) @@ -167,23 +176,43 @@ public: return result; } + void ApplyConfig(const NKikimrConfig::TMetadataCacheConfig& config, const NKikimrConfig::TFeatureFlags& flags) { + RefreshPeriod = TDuration::MilliSeconds(config.GetRefreshPeriodMs()); + bool enabled = flags.GetEnableDbMetadataCache(); + if (!Enabled && enabled) { + TInstant now = TActivationContext::Now(); + NKikimrMetadataCache::TDatabaseMetadataCacheInfo info; + info.SetStartTimestamp(now.MicroSeconds()); + PublishActor = RegisterWithSameMailbox(CreateBoardPublishActor(BoardPath, + info.SerializeAsString(), + SelfId(), + 0, + true)); + SubscribeToBoard(); + Become(&TThis::StateWait); + } else if (Enabled && !enabled) { + CleanUp(); + Become(&TThis::StateDisabled); + } + Enabled = enabled; + } + void Bootstrap() { LOG_DEBUG_S(TActivationContext::AsActorContext(), NKikimrServices::DB_METADATA_CACHE, "Starting db metadata cache actor"); - TInstant now = TActivationContext::Now(); - NKikimrMetadataCache::TDatabaseMetadataCacheInfo info; - info.SetStartTimestamp(now.MicroSeconds()); - PublishActor = RegisterWithSameMailbox(CreateBoardPublishActor(BoardPath, - info.SerializeAsString(), - SelfId(), - 0, - true)); - SubscribeToBoard(); - Become(&TThis::StateWait); + Become(&TThis::StateInactive); + ApplyConfig(AppData()->MetadataCacheConfig, AppData()->FeatureFlags); + Send(NConsole::MakeConfigsDispatcherID(SelfId().NodeId()), + new NConsole::TEvConfigsDispatcher::TEvSetConfigSubscriptionRequest({NKikimrConsole::TConfigItem::FeatureFlagsItem, + NKikimrConsole::TConfigItem::MetadataCacheConfigItem})); } - void PassAway() override { + void CleanUp() { Send(PublishActor, new TEvents::TEvPoison); Send(SubscribeActor, new TEvents::TEvPoison); + } + + void PassAway() override { + CleanUp(); return TActor::PassAway(); } @@ -194,6 +223,8 @@ public: cFunc(TEvents::TEvPoison::EventType, PassAway); hFunc(NHealthCheck::TEvSelfCheckResult, Handle); hFunc(NHealthCheck::TEvSelfCheckRequestProto, Handle); + IgnoreFunc(NConsole::TEvConfigsDispatcher::TEvSetConfigSubscriptionResponse); + hFunc(NConsole::TEvConsole::TEvConfigNotificationRequest, Handle); default: Y_ABORT("Unexpected event: %s", ev->ToString().c_str()); } } @@ -206,6 +237,8 @@ public: hFunc(TEvStateStorage::TEvBoardInfo, Handle); hFunc(TEvStateStorage::TEvBoardInfoUpdate, Handle); cFunc(TEvents::TEvPoison::EventType, PassAway); + IgnoreFunc(NConsole::TEvConfigsDispatcher::TEvSetConfigSubscriptionResponse); + hFunc(NConsole::TEvConsole::TEvConfigNotificationRequest, Handle); default: Y_ABORT("Unexpected event: %s", ev->ToString().c_str()); } } @@ -218,9 +251,19 @@ public: hFunc(TEvStateStorage::TEvBoardInfo, Handle); hFunc(TEvStateStorage::TEvBoardInfoUpdate, Handle); cFunc(TEvents::TEvPoison::EventType, PassAway); + IgnoreFunc(NConsole::TEvConfigsDispatcher::TEvSetConfigSubscriptionResponse); + hFunc(NConsole::TEvConsole::TEvConfigNotificationRequest, Handle); default: Y_ABORT("Unexpected event: %s", ev->ToString().c_str()); } } + + STATEFN(StateDisabled) { + switch (ev->GetTypeRewrite()) { + cFunc(TEvents::TEvPoison::EventType, PassAway); + hFunc(NConsole::TEvConsole::TEvConfigNotificationRequest, Handle); + // Ignore everything else + } + } }; inline TActorId MakeDatabaseMetadataCacheId(ui32 nodeId) { diff --git a/ydb/core/protos/config.proto b/ydb/core/protos/config.proto index 3e27da29986..aae19c1d9ca 100644 --- a/ydb/core/protos/config.proto +++ b/ydb/core/protos/config.proto @@ -1795,6 +1795,10 @@ message TAwsCompatibilityConfig { optional string AwsRegion = 1; } +message TMetadataCacheConfig { + optional uint64 RefreshPeriodMs = 1 [default = 15000]; +} + message TLabel { optional string Name = 1; optional string Value = 2; @@ -1875,6 +1879,7 @@ message TAppConfig { optional TBackgroundCleaningConfig BackgroundCleaningConfig = 77; optional TBlobCacheConfig BlobCacheConfig = 78; optional TLimiterConfig CompDiskLimiterConfig = 79; + optional TMetadataCacheConfig MetadataCacheConfig = 80; repeated TNamedConfig NamedConfigs = 100; optional string ClusterYamlConfig = 101; diff --git a/ydb/core/protos/console_config.proto b/ydb/core/protos/console_config.proto index fefc4b14d52..c90ff05bed1 100644 --- a/ydb/core/protos/console_config.proto +++ b/ydb/core/protos/console_config.proto @@ -138,6 +138,7 @@ message TConfigItem { AllowEditYamlInUiItem = 75; S3ProxyResolverConfigItem = 76; BackgroundCleaningConfigItem = 77; + MetadataCacheConfigItem = 80; NamedConfigsItem = 100; ClusterYamlConfigItem = 101; diff --git a/ydb/core/protos/feature_flags.proto b/ydb/core/protos/feature_flags.proto index 57c3a022c3d..7d31f6702e1 100644 --- a/ydb/core/protos/feature_flags.proto +++ b/ydb/core/protos/feature_flags.proto @@ -139,4 +139,5 @@ message TFeatureFlags { optional bool EnableVolatileTransactionArbiters = 124 [default = false]; optional bool EnableGraphShard = 125 [default = false]; optional bool EnableExternalSourceSchemaInference = 126 [default = false]; + optional bool EnableDbMetadataCache = 127 [default = false]; } |
