Skip to content

Commit

Permalink
Refactor config handlers in filestore (#1758)
Browse files Browse the repository at this point in the history
  • Loading branch information
drbasic authored Aug 9, 2024
1 parent 8bc347a commit 81834c5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 75 deletions.
51 changes: 24 additions & 27 deletions cloud/filestore/libs/daemon/common/config_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,23 @@ using namespace NCloud::NStorage;

////////////////////////////////////////////////////////////////////////////////

TConfigInitializerCommon::TConfigInitializerCommon(TOptionsCommonPtr options)
TConfigInitializerCommon::TConfigInitializerCommon(
TConfigHandlers configHandlers,
TOptionsCommonPtr options)
: TConfigInitializerYdbBase(options)
, ConfigHandlers(std::move(configHandlers))
, Options(std::move(options))
{}
{
ConfigHandlers.insert(
{"DiagnosticsConfig",
bind_front(&TConfigInitializerCommon::ApplyDiagnosticsConfig, this)});
ConfigHandlers.insert(
{"FeaturesConfig",
bind_front(&TConfigInitializerCommon::ApplyFeaturesConfig, this)});
ConfigHandlers.insert(
{"StorageConfig",
bind_front(&TConfigInitializerCommon::ApplyStorageConfig, this)});
}

void TConfigInitializerCommon::InitDiagnosticsConfig()
{
Expand Down Expand Up @@ -79,15 +92,16 @@ TNodeRegistrationSettings
void TConfigInitializerCommon::ApplyCustomCMSConfigs(
const NKikimrConfig::TAppConfig& config)
{
using TSelf = TConfigInitializerCommon;

const THashMap<TString, TApplyConfigFn> map {
{ "DiagnosticsConfig", bind_front(&TSelf::ApplyDiagnosticsConfig, this)},
{ "FeaturesConfig", bind_front(&TSelf::ApplyFeaturesConfig, this) },
{ "StorageConfig", bind_front(&TSelf::ApplyStorageConfig, this) },
};
for (const auto& item: config.GetNamedConfigs()) {
TStringBuf name = item.GetName();
if (!name.SkipPrefix("Cloud.Filestore.")) {
continue;
}

ApplyConfigs(config, map);
if (auto* handler = ConfigHandlers.FindPtr(name)) {
std::invoke(*handler, item.GetConfig());
}
}
}

void TConfigInitializerCommon::ApplyDiagnosticsConfig(const TString& text)
Expand Down Expand Up @@ -117,21 +131,4 @@ void TConfigInitializerCommon::ApplyFeaturesConfig(const TString& text)
std::move(config));
}

void TConfigInitializerCommon::ApplyConfigs(
const NKikimrConfig::TAppConfig& config,
const THashMap<TString, TApplyConfigFn>& handlers)
{
for (const auto& item: config.GetNamedConfigs()) {
TStringBuf name = item.GetName();
if (!name.SkipPrefix("Cloud.Filestore.")) {
continue;
}

auto it = handlers.find(name);
if (it != handlers.end()) {
std::invoke(it->second, item.GetConfig());
}
}
}

} // namespace NCloud::NFileStore::NDaemon
21 changes: 11 additions & 10 deletions cloud/filestore/libs/daemon/common/config_initializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,35 @@ class TConfigInitializerCommon
: public NCloud::NStorage::TConfigInitializerYdbBase
{
protected:
using TApplyConfigFn = std::function<void(const TString&)>;
using TConfigHandlerFn = std::function<void(const TString&)>;
using TConfigHandlers = THashMap<TString, TConfigHandlerFn>;

TConfigInitializerCommon(
TConfigHandlers configHandlers,
TOptionsCommonPtr options);

private:
TConfigHandlers ConfigHandlers;

public:
TOptionsCommonPtr Options;
const TOptionsCommonPtr Options;

TDiagnosticsConfigPtr DiagnosticsConfig;
NStorage::TStorageConfigPtr StorageConfig;
NFeatures::TFeaturesConfigPtr FeaturesConfig;

TConfigInitializerCommon(TOptionsCommonPtr options);

void InitDiagnosticsConfig();
void InitStorageConfig();
void InitFeaturesConfig();

void ApplyCustomCMSConfigs(const NKikimrConfig::TAppConfig& config) override;
void ApplyCustomCMSConfigs(const NKikimrConfig::TAppConfig& config) final;

NCloud::NStorage::TNodeRegistrationSettings GetNodeRegistrationSettings();

private:
void ApplyDiagnosticsConfig(const TString& text);
void ApplyStorageConfig(const TString& text);
void ApplyFeaturesConfig(const TString& text);

protected:
static void ApplyConfigs(
const NKikimrConfig::TAppConfig& config,
const THashMap<TString, TApplyConfigFn>& handlers);
};

} // namespace NCloud::NFileStore::NDaemon
19 changes: 4 additions & 15 deletions cloud/filestore/libs/daemon/server/config_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ namespace NCloud::NFileStore::NDaemon {
////////////////////////////////////////////////////////////////////////////////

TConfigInitializerServer::TConfigInitializerServer(TOptionsServerPtr options)
: TConfigInitializerCommon(options)
: TConfigInitializerCommon(
{{"ServerAppConfig",
bind_front(&TConfigInitializerServer::ApplyServerAppConfig, this)}},
options)
, Options(std::move(options))
{}

Expand All @@ -32,20 +35,6 @@ void TConfigInitializerServer::InitAppConfig()
ServerConfig = std::make_shared<NServer::TServerConfig>(serverConfig);
}

void TConfigInitializerServer::ApplyCustomCMSConfigs(
const NKikimrConfig::TAppConfig& config)
{
TConfigInitializerCommon::ApplyCustomCMSConfigs(config);

using TSelf = TConfigInitializerServer;

const THashMap<TString, TApplyConfigFn> map {
{ "ServerAppConfig", bind_front(&TSelf::ApplyServerAppConfig, this) },
};

ApplyConfigs(config, map);
}

void TConfigInitializerServer::ApplyServerAppConfig(const TString& text)
{
AppConfig.Clear();
Expand Down
6 changes: 2 additions & 4 deletions cloud/filestore/libs/daemon/server/config_initializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ class TConfigInitializerServer
: public TConfigInitializerCommon
{
public:
TOptionsServerPtr Options;
const TOptionsServerPtr Options;

NProto::TServerAppConfig AppConfig;
NServer::TServerConfigPtr ServerConfig;

TConfigInitializerServer(TOptionsServerPtr options);
explicit TConfigInitializerServer(TOptionsServerPtr options);

void InitAppConfig();

void ApplyCustomCMSConfigs(const NKikimrConfig::TAppConfig& config) override;

private:
void ApplyServerAppConfig(const TString& text);
};
Expand Down
19 changes: 4 additions & 15 deletions cloud/filestore/libs/daemon/vhost/config_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ using namespace NCloud::NFileStore::NVhost;
////////////////////////////////////////////////////////////////////////////////

TConfigInitializerVhost::TConfigInitializerVhost(TOptionsVhostPtr options)
: TConfigInitializerCommon(options)
: TConfigInitializerCommon(
{{"VHostAppConfig",
bind_front(&TConfigInitializerVhost::ApplyVHostAppConfig, this)}},
options)
, Options(std::move(options))
{}

Expand All @@ -37,20 +40,6 @@ void TConfigInitializerVhost::InitAppConfig()
AppConfig.GetVhostServiceConfig());
}

void TConfigInitializerVhost::ApplyCustomCMSConfigs(
const NKikimrConfig::TAppConfig& config)
{
TConfigInitializerCommon::ApplyCustomCMSConfigs(config);

using TSelf = TConfigInitializerVhost;

const THashMap<TString, TApplyConfigFn> map {
{ "VHostAppConfig", bind_front(&TSelf::ApplyVHostAppConfig, this) },
};

ApplyConfigs(config, map);
}

void TConfigInitializerVhost::ApplyVHostAppConfig(const TString& text)
{
AppConfig.Clear();
Expand Down
6 changes: 2 additions & 4 deletions cloud/filestore/libs/daemon/vhost/config_initializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ class TConfigInitializerVhost final
: public TConfigInitializerCommon
{
public:
TOptionsVhostPtr Options;
const TOptionsVhostPtr Options;

NProto::TVhostAppConfig AppConfig;
NVhost::TVhostServiceConfigPtr VhostServiceConfig;
NServer::TServerConfigPtr ServerConfig;

TConfigInitializerVhost(TOptionsVhostPtr options);
explicit TConfigInitializerVhost(TOptionsVhostPtr options);

void InitAppConfig();

void ApplyCustomCMSConfigs(const NKikimrConfig::TAppConfig& config) override;

private:
void ApplyVHostAppConfig(const TString& text);
};
Expand Down

0 comments on commit 81834c5

Please sign in to comment.