diff options
author | innokentii <innokentii@yandex-team.com> | 2023-04-04 17:50:07 +0300 |
---|---|---|
committer | innokentii <innokentii@yandex-team.com> | 2023-04-04 17:50:07 +0300 |
commit | eae406170c263f43ee06d8e794ae331db7397a79 (patch) | |
tree | cd302fe1928a68e8e0095880d638ed0be2ae177f | |
parent | 895f6854157845969c838a81e1902976d28f51e9 (diff) | |
download | ydb-eae406170c263f43ee06d8e794ae331db7397a79.tar.gz |
Force first update in console
force first update in console
-rw-r--r-- | ydb/core/cms/console/config_index.h | 2 | ||||
-rw-r--r-- | ydb/core/cms/console/configs_cache.cpp | 4 | ||||
-rw-r--r-- | ydb/core/cms/console/configs_cache_ut.cpp | 2 | ||||
-rw-r--r-- | ydb/core/cms/console/console_configs_provider.cpp | 4 | ||||
-rw-r--r-- | ydb/core/cms/console/console_configs_subscriber.cpp | 21 | ||||
-rw-r--r-- | ydb/core/cms/console/console_ut_configs.cpp | 48 |
6 files changed, 58 insertions, 23 deletions
diff --git a/ydb/core/cms/console/config_index.h b/ydb/core/cms/console/config_index.h index 611339c5c1f..063a3313ec9 100644 --- a/ydb/core/cms/console/config_index.h +++ b/ydb/core/cms/console/config_index.h @@ -666,6 +666,8 @@ struct TInMemorySubscription : public TThrRefBase { ui64 YamlConfigVersion = 0; TMap<ui64, ui64> VolatileYamlConfigHashes; + bool FirstUpdateSent = false; + TActorId Worker; }; diff --git a/ydb/core/cms/console/configs_cache.cpp b/ydb/core/cms/console/configs_cache.cpp index 9f69ceacb1d..49fedcba920 100644 --- a/ydb/core/cms/console/configs_cache.cpp +++ b/ydb/core/cms/console/configs_cache.cpp @@ -105,6 +105,10 @@ void TConfigsCache::Bootstrap(const TActorContext &ctx) { void TConfigsCache::Handle(TEvConsole::TEvConfigSubscriptionNotification::TPtr &ev) { auto &rec = ev->Get()->Record; + if (rec.AffectedKindsSize() == 0) { + return; + } + CurrentConfig.Swap(rec.MutableConfig()); BLOG_DEBUG("Saving configuration: " << CurrentConfig.ShortDebugString()); diff --git a/ydb/core/cms/console/configs_cache_ut.cpp b/ydb/core/cms/console/configs_cache_ut.cpp index 450a95804af..8110ef20f06 100644 --- a/ydb/core/cms/console/configs_cache_ut.cpp +++ b/ydb/core/cms/console/configs_cache_ut.cpp @@ -128,7 +128,7 @@ Y_UNIT_TEST_SUITE(TConfigsCacheTests) { CheckConfigure(runtime, Ydb::StatusIds::SUCCESS, MakeAddAction(ITEM_DOMAIN_LOG_1)); TSaveCallback save = [](auto&) { - Y_ASSERT(false); + UNIT_ASSERT(false); }; TLoadCallback load = [](auto &config) { diff --git a/ydb/core/cms/console/console_configs_provider.cpp b/ydb/core/cms/console/console_configs_provider.cpp index 3d4157ef3b7..3a7415e5feb 100644 --- a/ydb/core/cms/console/console_configs_provider.cpp +++ b/ydb/core/cms/console/console_configs_provider.cpp @@ -660,7 +660,7 @@ void TConfigsProvider::CheckSubscription(TInMemorySubscription::TPtr subscriptio } } - if (affectedKinds.empty() && !yamlChanged) { + if (affectedKinds.empty() && !yamlChanged && subscription->FirstUpdateSent) { LOG_TRACE_S(ctx, NKikimrServices::CMS_CONFIGS, "TConfigsProvider: no changes found for subscription" << " " << subscription->Subscriber.ToString() << ":" << subscription->Generation); @@ -709,6 +709,8 @@ void TConfigsProvider::CheckSubscription(TInMemorySubscription::TPtr subscriptio subscription->VolatileYamlConfigHashes = VolatileYamlConfigHashes; ctx.Send(subscription->Worker, request.Release()); + + subscription->FirstUpdateSent = true; } void TConfigsProvider::DumpStateHTML(IOutputStream &os) const { diff --git a/ydb/core/cms/console/console_configs_subscriber.cpp b/ydb/core/cms/console/console_configs_subscriber.cpp index 7cff1d7ca8a..3928c04cfb8 100644 --- a/ydb/core/cms/console/console_configs_subscriber.cpp +++ b/ydb/core/cms/console/console_configs_subscriber.cpp @@ -177,22 +177,30 @@ public: return; } + bool notChanged = true; + if (ServeYaml) { if (!(rec.HasYamlConfigNotChanged() && rec.GetYamlConfigNotChanged())) { if (rec.HasYamlConfig()) { YamlConfig = rec.GetYamlConfig(); YamlConfigVersion = NYamlConfig::GetVersion(YamlConfig); } + notChanged = false; + } + + if (rec.VolatileConfigsSize() != VolatileYamlConfigs.size()) { + notChanged = false; } TMap<ui64, TString> newVolatileYamlConfigs; TMap<ui64, ui64> newVolatileYamlConfigHashes; - for (auto &volatileConfig : *rec.MutableVolatileConfigs()) { + for (auto &volatileConfig : rec.GetVolatileConfigs()) { if (volatileConfig.HasNotChanged() && volatileConfig.GetNotChanged()) { Y_ASSERT(VolatileYamlConfigs.contains(volatileConfig.GetId())); newVolatileYamlConfigs[volatileConfig.GetId()] = std::move(VolatileYamlConfigs[volatileConfig.GetId()]); newVolatileYamlConfigHashes[volatileConfig.GetId()] = VolatileYamlConfigHashes[volatileConfig.GetId()]; } else { + notChanged = false; newVolatileYamlConfigs[volatileConfig.GetId()] = volatileConfig.GetConfig(); newVolatileYamlConfigHashes[volatileConfig.GetId()] = THash<TString>()(volatileConfig.GetConfig()); } @@ -222,8 +230,14 @@ public: else CurrentConfig.MutableVersion()->Swap(&newVersion); - Send(OwnerId, new TEvConsole::TEvConfigSubscriptionNotification(Generation, CurrentConfig, changes, YamlConfig, VolatileYamlConfigs), - IEventHandle::FlagTrackDelivery, Cookie); + notChanged &= changes.empty(); + + if (!notChanged || !FirstUpdateSent) { + Send(OwnerId, new TEvConsole::TEvConfigSubscriptionNotification(Generation, CurrentConfig, changes, YamlConfig, VolatileYamlConfigs), + IEventHandle::FlagTrackDelivery, Cookie); + + FirstUpdateSent = true; + } LastOrder++; } @@ -335,6 +349,7 @@ private: const TActorId OwnerId; ui64 Cookie; const TVector<ui32> Kinds; + bool FirstUpdateSent = false; ui64 Generation; ui64 NextGeneration; diff --git a/ydb/core/cms/console/console_ut_configs.cpp b/ydb/core/cms/console/console_ut_configs.cpp index e92b92c733b..5b0be54eac9 100644 --- a/ydb/core/cms/console/console_ut_configs.cpp +++ b/ydb/core/cms/console/console_ut_configs.cpp @@ -3584,6 +3584,8 @@ Y_UNIT_TEST_SUITE(TConsoleInMemoryConfigSubscriptionTests) { event->Record.AddConfigItemKinds(NKikimrConsole::TConfigItem::LogConfigItem); runtime.SendToPipe(MakeConsoleID(0), edgeId, event, 0, GetPipeConfigWithRetries()); + runtime.GrabEdgeEventRethrow<TEvConsole::TEvConfigSubscriptionNotification>(edgeId); // initial update + ITEM_DOMAIN_LOG_1.MutableConfig()->MutableLogConfig()->SetClusterName("cluster-1"); CheckConfigure(runtime, Ydb::StatusIds::SUCCESS, @@ -3609,15 +3611,15 @@ Y_UNIT_TEST_SUITE(TConsoleInMemoryConfigSubscriptionTests) { TActorId edgeId = runtime.Sender; - auto subscriber = NConsole::CreateConfigsSubscriber(edgeId, TVector<ui32>({(ui32)NKikimrConsole::TConfigItem::LogConfigItem}), NKikimrConfig::TAppConfig()); - - runtime.Register(subscriber); - ITEM_DOMAIN_LOG_1.MutableConfig()->MutableLogConfig()->SetClusterName("cluster-1"); CheckConfigure(runtime, Ydb::StatusIds::SUCCESS, MakeAddAction(ITEM_DOMAIN_LOG_1)); + auto subscriber = NConsole::CreateConfigsSubscriber(edgeId, TVector<ui32>({(ui32)NKikimrConsole::TConfigItem::LogConfigItem}), NKikimrConfig::TAppConfig()); + + runtime.Register(subscriber); + NKikimrConfig::TAppConfig config; config.MutableLogConfig()->SetClusterName("cluster-1"); @@ -3642,6 +3644,8 @@ Y_UNIT_TEST_SUITE(TConsoleInMemoryConfigSubscriptionTests) { runtime.Register(subscriber); + runtime.GrabEdgeEventRethrow<TEvConsole::TEvConfigSubscriptionNotification>(edgeId); // initial update + for (int i = 0; i < 100; i++) { ITEM_DOMAIN_LOG_1.MutableConfig()->MutableLogConfig()->SetClusterName(TStringBuilder() << "cluster-" << i); @@ -3679,6 +3683,8 @@ Y_UNIT_TEST_SUITE(TConsoleInMemoryConfigSubscriptionTests) { runtime.Register(subscriber); + runtime.GrabEdgeEventRethrow<TEvConsole::TEvConfigSubscriptionNotification>(edgeId); // initial update + ui64 id = 0; for (int i = 0; i < 100; i++) { if (i % 2 == 0) { @@ -3730,6 +3736,8 @@ Y_UNIT_TEST_SUITE(TConsoleInMemoryConfigSubscriptionTests) { options1.FinalEvents.emplace_back(TEvConsole::EvConfigSubscriptionResponse, 1); runtime.DispatchEvents(options1); + runtime.GrabEdgeEventRethrow<TEvConsole::TEvConfigSubscriptionNotification>(edgeId); // initial update + runtime.Send(new IEventHandle(clientId, edgeId, new TEvents::TEvPoisonPill()), 0, true); TDispatchOptions options2; @@ -3743,13 +3751,6 @@ Y_UNIT_TEST_SUITE(TConsoleInMemoryConfigSubscriptionTests) { TActorId edgeId = runtime.AllocateEdgeActor(1); - auto subscriber = NConsole::CreateConfigsSubscriber(edgeId, TVector<ui32>({(ui32)NKikimrConsole::TConfigItem::LogConfigItem}), NKikimrConfig::TAppConfig()); - runtime.Register(subscriber, 1); - - TDispatchOptions options1; - options1.FinalEvents.emplace_back(TEvConsole::EvConfigSubscriptionResponse, 1); - runtime.DispatchEvents(options1); - ITEM_DOMAIN_LOG_1.MutableConfig()->MutableLogConfig()->SetClusterName("cluster-1"); auto ids = CheckConfigure(runtime, Ydb::StatusIds::SUCCESS, @@ -3757,6 +3758,13 @@ Y_UNIT_TEST_SUITE(TConsoleInMemoryConfigSubscriptionTests) { AssignIds(ids, ITEM_DOMAIN_LOG_1); + auto subscriber = NConsole::CreateConfigsSubscriber(edgeId, TVector<ui32>({(ui32)NKikimrConsole::TConfigItem::LogConfigItem}), NKikimrConfig::TAppConfig()); + runtime.Register(subscriber, 1); + + TDispatchOptions options1; + options1.FinalEvents.emplace_back(TEvConsole::EvConfigSubscriptionResponse, 1); + runtime.DispatchEvents(options1); + NKikimrConfig::TAppConfig config1; config1.MutableLogConfig()->SetClusterName("cluster-1"); { @@ -3816,10 +3824,12 @@ Y_UNIT_TEST_SUITE(TConsoleInMemoryConfigSubscriptionTests) { false); runtime.Register(subscriber, 1); - TDispatchOptions options1; + TDispatchOptions options1; options1.FinalEvents.emplace_back(TEvConsole::EvConfigSubscriptionResponse, 1); runtime.DispatchEvents(options1); + runtime.GrabEdgeEventRethrow<TEvConsole::TEvConfigSubscriptionNotification>(edgeId); // initial update + ITEM_DOMAIN_LOG_1.MutableConfig()->MutableLogConfig()->SetClusterName("cluster-1"); CheckConfigure(runtime, Ydb::StatusIds::SUCCESS, @@ -3863,6 +3873,11 @@ Y_UNIT_TEST_SUITE(TConsoleInMemoryConfigSubscriptionTests) { TActorId edgeId = runtime.AllocateEdgeActor(1); + ITEM_DOMAIN_LOG_1.MutableConfig()->MutableLogConfig()->SetClusterName("cluster-1"); + + CheckConfigure(runtime, Ydb::StatusIds::SUCCESS, + MakeAddAction(ITEM_DOMAIN_LOG_1)); + auto subscriber = NConsole::CreateConfigsSubscriber( edgeId, TVector<ui32>({(ui32)NKikimrConsole::TConfigItem::LogConfigItem}), @@ -3875,11 +3890,6 @@ Y_UNIT_TEST_SUITE(TConsoleInMemoryConfigSubscriptionTests) { options1.FinalEvents.emplace_back(TEvConsole::EvConfigSubscriptionResponse, 1); runtime.DispatchEvents(options1); - ITEM_DOMAIN_LOG_1.MutableConfig()->MutableLogConfig()->SetClusterName("cluster-1"); - - CheckConfigure(runtime, Ydb::StatusIds::SUCCESS, - MakeAddAction(ITEM_DOMAIN_LOG_1)); - NKikimrConfig::TAppConfig config; config.MutableLogConfig()->SetClusterName("cluster-1"); @@ -3977,6 +3987,8 @@ Y_UNIT_TEST_SUITE(TConsoleInMemoryConfigSubscriptionTests) { event->Record.AddConfigItemKinds(NKikimrConsole::TConfigItem::LogConfigItem); runtime.SendToPipe(MakeConsoleID(0), edgeId, event, 0, GetPipeConfigWithRetries()); + runtime.GrabEdgeEventRethrow<TEvConsole::TEvConfigSubscriptionNotification>(edgeId); // initial update + CheckApplyConfig(runtime, Ydb::StatusIds::SUCCESS, YAML_CONFIG_1); auto notification = runtime.GrabEdgeEventRethrow<TEvConsole::TEvConfigSubscriptionNotification>(edgeId); @@ -4109,7 +4121,7 @@ Y_UNIT_TEST_SUITE(TConsoleInMemoryConfigSubscriptionTests) { event->Record.AddConfigItemKinds(NKikimrConsole::TConfigItem::LogConfigItem); runtime.SendToPipe(MakeConsoleID(0), edgeId, event, 0, GetPipeConfigWithRetries()); - // Nothing changed so no notification + runtime.GrabEdgeEventRethrow<TEvConsole::TEvConfigSubscriptionNotification>(edgeId); // initial update generation = 2; |