From b9d76e78d9e490bfc2937efed5026b9697fd0355 Mon Sep 17 00:00:00 2001 From: yegorskii Date: Mon, 16 Sep 2024 23:50:55 +0200 Subject: [PATCH] issue-1946: remove duplicated code (#2040) * issue-1946: remove duplicated code * fix build * update * update --- .../libs/daemon/ydb/config_initializer.cpp | 48 +++++------------ .../libs/daemon/ydb/config_initializer.h | 1 - .../libs/disk_agent/config_initializer.cpp | 52 +++++-------------- .../libs/disk_agent/config_initializer.h | 1 - cloud/blockstore/libs/storage/core/config.cpp | 34 ++++++++++++ cloud/blockstore/libs/storage/core/config.h | 7 ++- 6 files changed, 64 insertions(+), 79 deletions(-) diff --git a/cloud/blockstore/libs/daemon/ydb/config_initializer.cpp b/cloud/blockstore/libs/daemon/ydb/config_initializer.cpp index 4fed426538c..6aa114dc7ce 100644 --- a/cloud/blockstore/libs/daemon/ydb/config_initializer.cpp +++ b/cloud/blockstore/libs/daemon/ydb/config_initializer.cpp @@ -59,7 +59,12 @@ void TConfigInitializerYdb::InitStorageConfig() ParseProtoTextFromFileRobust(Options->StorageConfig, storageConfig); } - AdaptNodeRegistrationParams(storageConfig); + if (ServerConfig && ServerConfig->GetServerConfig()) { + NStorage::AdaptNodeRegistrationParams( + {}, // overriddenNodeType, node type is not passed in cmd line + *ServerConfig->GetServerConfig(), + storageConfig); + } SetupStorageConfig(storageConfig); @@ -264,7 +269,12 @@ void TConfigInitializerYdb::ApplyStorageServiceConfig(const TString& text) NProto::TStorageServiceConfig storageConfig; ParseProtoTextFromStringRobust(text, storageConfig); - AdaptNodeRegistrationParams(storageConfig); + if (ServerConfig && ServerConfig->GetServerConfig()) { + NStorage::AdaptNodeRegistrationParams( + {}, // overriddenNodeType, node type is not passed in cmd line + *ServerConfig->GetServerConfig(), + storageConfig); + } SetupStorageConfig(storageConfig); @@ -390,38 +400,4 @@ void TConfigInitializerYdb::ApplyCustomCMSConfigs(const NKikimrConfig::TAppConfi } } -void TConfigInitializerYdb::AdaptNodeRegistrationParams( - NProto::TStorageServiceConfig& config) -{ - if (!ServerConfig || !ServerConfig->GetServerConfig()) { - return; - } - - const auto* serverConfig = ServerConfig->GetServerConfig(); - - if (!config.GetNodeRegistrationMaxAttempts()) { - config.SetNodeRegistrationMaxAttempts( - serverConfig->GetNodeRegistrationMaxAttempts()); - } - - if (!config.GetNodeRegistrationTimeout()) { - config.SetNodeRegistrationTimeout( - serverConfig->GetNodeRegistrationTimeout()); - } - - if (!config.GetNodeRegistrationErrorTimeout()) { - config.SetNodeRegistrationErrorTimeout( - serverConfig->GetNodeRegistrationErrorTimeout()); - } - - if (!config.GetNodeRegistrationToken()) { - config.SetNodeRegistrationToken( - serverConfig->GetNodeRegistrationToken()); - } - - if (!config.GetNodeType()) { - config.SetNodeType(serverConfig->GetNodeType()); - } -} - } // namespace NCloud::NBlockStore::NServer diff --git a/cloud/blockstore/libs/daemon/ydb/config_initializer.h b/cloud/blockstore/libs/daemon/ydb/config_initializer.h index aa0e3bc8357..3edee9612b8 100644 --- a/cloud/blockstore/libs/daemon/ydb/config_initializer.h +++ b/cloud/blockstore/libs/daemon/ydb/config_initializer.h @@ -78,7 +78,6 @@ struct TConfigInitializerYdb final private: void SetupStorageConfig(NProto::TStorageServiceConfig& config) const; - void AdaptNodeRegistrationParams(NProto::TStorageServiceConfig& config); void ApplyDiagnosticsConfig(const TString& text); void ApplyDiscoveryServiceConfig(const TString& text); diff --git a/cloud/blockstore/libs/disk_agent/config_initializer.cpp b/cloud/blockstore/libs/disk_agent/config_initializer.cpp index 79f4e030615..be4ebb03afb 100644 --- a/cloud/blockstore/libs/disk_agent/config_initializer.cpp +++ b/cloud/blockstore/libs/disk_agent/config_initializer.cpp @@ -139,7 +139,12 @@ void TConfigInitializer::InitStorageConfig() ParseProtoTextFromFileRobust(Options->StorageConfig, storageConfig); } - AdaptNodeRegistrationParams(storageConfig); + if (ServerConfig && ServerConfig->GetServerConfig()) { + NStorage::AdaptNodeRegistrationParams( + Options->NodeType, + *ServerConfig->GetServerConfig(), + storageConfig); + } if (Options->SchemeShardDir) { storageConfig.SetSchemeShardDir(GetFullSchemeShardDir()); @@ -383,7 +388,12 @@ void TConfigInitializer::ApplyStorageServiceConfig(const TString& text) NProto::TStorageServiceConfig storageConfig; ParseProtoTextFromStringRobust(text, storageConfig); - AdaptNodeRegistrationParams(storageConfig); + if (ServerConfig && ServerConfig->GetServerConfig()) { + NStorage::AdaptNodeRegistrationParams( + Options->NodeType, + *ServerConfig->GetServerConfig(), + storageConfig); + } storageConfig.SetServiceVersionInfo(GetFullVersionString()); StorageConfig = std::make_shared( @@ -465,42 +475,4 @@ void TConfigInitializer::ApplyCustomCMSConfigs(const NKikimrConfig::TAppConfig& } } -void TConfigInitializer::AdaptNodeRegistrationParams( - NProto::TStorageServiceConfig& config) -{ - if (!ServerConfig || !ServerConfig->GetServerConfig()) { - return; - } - - const auto* serverConfig = ServerConfig->GetServerConfig(); - - if (!config.GetNodeRegistrationMaxAttempts()) { - config.SetNodeRegistrationMaxAttempts( - serverConfig->GetNodeRegistrationMaxAttempts()); - } - - if (!config.GetNodeRegistrationTimeout()) { - config.SetNodeRegistrationTimeout( - serverConfig->GetNodeRegistrationTimeout()); - } - - if (!config.GetNodeRegistrationErrorTimeout()) { - config.SetNodeRegistrationErrorTimeout( - serverConfig->GetNodeRegistrationErrorTimeout()); - } - - if (!config.GetNodeRegistrationToken()) { - config.SetNodeRegistrationToken( - serverConfig->GetNodeRegistrationToken()); - } - - if (Options->NodeType) { - config.SetNodeType(Options->NodeType); - } - - if (!config.GetNodeType()) { - config.SetNodeType(serverConfig->GetNodeType()); - } -} - } // namespace NCloud::NBlockStore::NServer diff --git a/cloud/blockstore/libs/disk_agent/config_initializer.h b/cloud/blockstore/libs/disk_agent/config_initializer.h index d6f7e12cda5..e5dba610314 100644 --- a/cloud/blockstore/libs/disk_agent/config_initializer.h +++ b/cloud/blockstore/libs/disk_agent/config_initializer.h @@ -61,7 +61,6 @@ struct TConfigInitializer private: TString GetFullSchemeShardDir() const; - void AdaptNodeRegistrationParams(NProto::TStorageServiceConfig& config); void SetupMonitoringConfig(NKikimrConfig::TMonitoringConfig& monConfig) const; void SetupLogConfig(NKikimrConfig::TLogConfig& logConfig) const; diff --git a/cloud/blockstore/libs/storage/core/config.cpp b/cloud/blockstore/libs/storage/core/config.cpp index 626f7208e11..619d81f0879 100644 --- a/cloud/blockstore/libs/storage/core/config.cpp +++ b/cloud/blockstore/libs/storage/core/config.cpp @@ -958,4 +958,38 @@ const NProto::TStorageServiceConfig& TStorageConfig::GetStorageConfigProto() con return Impl->StorageServiceConfig; } +void AdaptNodeRegistrationParams( + const TString& overriddenNodeType, + const NProto::TServerConfig& serverConfig, + NProto::TStorageServiceConfig& storageConfig) +{ + if (!storageConfig.GetNodeRegistrationMaxAttempts()) { + storageConfig.SetNodeRegistrationMaxAttempts( + serverConfig.GetNodeRegistrationMaxAttempts()); + } + + if (!storageConfig.GetNodeRegistrationTimeout()) { + storageConfig.SetNodeRegistrationTimeout( + serverConfig.GetNodeRegistrationTimeout()); + } + + if (!storageConfig.GetNodeRegistrationErrorTimeout()) { + storageConfig.SetNodeRegistrationErrorTimeout( + serverConfig.GetNodeRegistrationErrorTimeout()); + } + + if (!storageConfig.GetNodeRegistrationToken()) { + storageConfig.SetNodeRegistrationToken( + serverConfig.GetNodeRegistrationToken()); + } + + if (overriddenNodeType) { + storageConfig.SetNodeType(overriddenNodeType); + } + + if (!storageConfig.GetNodeType()) { + storageConfig.SetNodeType(serverConfig.GetNodeType()); + } +} + } // namespace NCloud::NBlockStore::NStorage diff --git a/cloud/blockstore/libs/storage/core/config.h b/cloud/blockstore/libs/storage/core/config.h index f220c280bc9..bb6ca3f35e9 100644 --- a/cloud/blockstore/libs/storage/core/config.h +++ b/cloud/blockstore/libs/storage/core/config.h @@ -2,7 +2,7 @@ #include "public.h" - +#include #include #include #include @@ -610,4 +610,9 @@ ui64 GetAllocationUnit( const TStorageConfig& config, NCloud::NProto::EStorageMediaKind mediaKind); +void AdaptNodeRegistrationParams( + const TString& overriddenNodeType, + const NProto::TServerConfig& serverConfig, + NProto::TStorageServiceConfig& storageConfig); + } // namespace NCloud::NBlockStore::NStorage