Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 4 additions & 188 deletions ydb/core/driver_lib/cli_utils/cli_cmds_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class TClientCommandServerBase : public TClientCommand {
bool NodeBrokerUseTls;
bool FixedNodeID;
bool IgnoreCmsConfigs;
bool HierarchicalCfg;
bool TinyMode;
TString NodeAddress;
TString NodeHost;
Expand Down Expand Up @@ -260,8 +259,6 @@ class TClientCommandServerBase : public TClientCommand {
config.Opts->AddLongOption("body", "body name (used to describe dynamic node location)")
.RequiredArgument("NUM").StoreResult(&Body);
config.Opts->AddLongOption("yaml-config", "Yaml config").OptionalArgument("PATH").AppendTo(&YamlConfigFiles);
config.Opts->AddLongOption("cms-config-cache-file", "Path to CMS cache config file").OptionalArgument("PATH")
.StoreResult(&RunConfig.PathToConfigCacheFile);
config.Opts->AddLongOption("http-proxy-file", "Http proxy config file").OptionalArgument("PATH");
config.Opts->AddLongOption("public-http-file", "Public HTTP config file").OptionalArgument("PATH");

Expand All @@ -278,9 +275,6 @@ class TClientCommandServerBase : public TClientCommand {
ProxyBusSessionConfig.ConfigureLastGetopt(*config.Opts, "mbus-");
ProxyBusQueueConfig.ConfigureLastGetopt(*config.Opts, "mbus-");

config.Opts->AddLongOption("hierarchic-cfg", "Use hierarchical approach for configuration parts overriding")
.NoArgument().SetFlag(&HierarchicalCfg);

config.Opts->AddLongOption("label", "labels for this node")
.Optional().RequiredArgument("KEY=VALUE")
.KVHandler([&](TString key, TString val) {
Expand All @@ -299,7 +293,7 @@ class TClientCommandServerBase : public TClientCommand {
ui32 kind,
TCallContext callCtx) {
TProto *res = nullptr;
if (!HierarchicalCfg && (AppConfig.*hasConfig)()) {
if ((AppConfig.*hasConfig)()) {
return nullptr; // this field is already provided in AppConfig, so we don't overwrite it
}

Expand Down Expand Up @@ -374,7 +368,7 @@ class TClientCommandServerBase : public TClientCommand {
(ui32)NKikimrConsole::TConfigItem:: FIELD ## Item, TCallContext{__FILE__, __LINE__})

OPTION("auth-file", AuthConfig);
LoadBaseConfig(config);
LoadBootstrapConfig(config);
LoadYamlConfig(CALL_CTX());
OPTION_MERGE("auth-token-file", AuthConfig);

Expand Down Expand Up @@ -453,17 +447,15 @@ class TClientCommandServerBase : public TClientCommand {
if (!NodeId) {
ythrow yexception() << "Either --node [NUM|'static'] or --node-broker[-port] should be specified";
}

if (!HierarchicalCfg && RunConfig.PathToConfigCacheFile)
LoadCachedConfigsForStaticNode();
} else {
RegisterDynamicNode();

RunConfig.Labels["node_id"] = ToString(RunConfig.NodeId);
AddLabelToAppConfig("node_id", RunConfig.Labels["node_id"]);

if (!HierarchicalCfg && !IgnoreCmsConfigs)
if (!IgnoreCmsConfigs) {
LoadConfigForDynamicNode();
}
}

LoadYamlConfig(CALL_CTX());
Expand Down Expand Up @@ -830,96 +822,6 @@ class TClientCommandServerBase : public TClientCommand {
RunConfig.ClusterName = AppConfig.GetNameserviceConfig().GetClusterUUID();
}

inline bool LoadConfigFromCMS() {
TVector<TString> addrs;
FillClusterEndpoints(addrs);

SetRandomSeed(TInstant::Now().MicroSeconds());

int minAttempts = 10;
int attempts = 0;

TString error;

while (attempts < minAttempts) {
for (const auto &addr : addrs) {
// Randomized backoff
if (attempts > 0)
Sleep(TDuration::MilliSeconds(500 + RandomNumber<ui64>(1000)));

NClient::TKikimr kikimr(GetKikimr(addr));
auto configurator = kikimr.GetNodeConfigurator();

Cout << "Trying to get configs from " << addr << Endl;

auto result = configurator.SyncGetNodeConfig(RunConfig.NodeId,
FQDNHostName(),
TenantName,
NodeType,
DeduceNodeDomain(),
AppConfig.GetAuthConfig().GetStaffApiUserToken(),
true,
1);

if (result.IsSuccess()) {
auto appConfig = result.GetConfig();

if (RunConfig.PathToConfigCacheFile) {
Cout << "Saving config to cache file " << RunConfig.PathToConfigCacheFile << Endl;
if (!SaveConfigForNodeToCache(appConfig)) {
Cout << "Failed to save config to cache file" << Endl;
}
}

NKikimrConfig::TAppConfig yamlConfig;

if (result.HasYamlConfig() && !result.GetYamlConfig().empty()) {
NYamlConfig::ResolveAndParseYamlConfig(
result.GetYamlConfig(),
result.GetVolatileYamlConfigs(),
RunConfig.Labels,
yamlConfig);
}

RunConfig.InitialCmsConfig.CopyFrom(appConfig);

RunConfig.InitialCmsYamlConfig.CopyFrom(yamlConfig);
NYamlConfig::ReplaceUnmanagedKinds(appConfig, RunConfig.InitialCmsYamlConfig);

if (yamlConfig.HasYamlConfigEnabled() && yamlConfig.GetYamlConfigEnabled()) {
BaseConfig.Swap(&yamlConfig);
NYamlConfig::ReplaceUnmanagedKinds(result.GetConfig(), BaseConfig);
} else {
BaseConfig.Swap(&appConfig);
}

Cout << "Success." << Endl;

return true;
}

error = result.GetErrorMessage();
Cerr << "Configuration error: " << error << Endl;
++attempts;
}
}

return false;
}

inline bool LoadConfigFromCache() {
if (RunConfig.PathToConfigCacheFile) {
NKikimrConfig::TAppConfig config;
if (GetCachedConfig(config)) {
BaseConfig.Swap(&config);

return true;
}
}

return false;
}

inline void LoadYamlConfig(TCallContext callCtx) {
for(const TString& yamlConfigFile: YamlConfigFiles) {
auto yamlConfig = TFileInput(yamlConfigFile);
Expand Down Expand Up @@ -962,21 +864,6 @@ class TClientCommandServerBase : public TClientCommand {
return res;
}

void LoadBaseConfig(TConfig& config) {
if (HierarchicalCfg) {
if (LoadConfigFromCMS())
return;
if (LoadConfigFromCache())
return;
if (LoadBootstrapConfig(config))
return;

ythrow yexception() << "cannot load configuration";
} else {
LoadBootstrapConfig(config);
}
}

TString DeduceNodeDomain() {
if (NodeDomain)
return NodeDomain;
Expand All @@ -993,29 +880,6 @@ class TClientCommandServerBase : public TClientCommand {
return "";
}

bool GetCachedConfig(NKikimrConfig::TAppConfig &appConfig) {
Y_DEBUG_ABORT_UNLESS(RunConfig.PathToConfigCacheFile, "GetCachedConfig called with a cms config cache file set");

try {
auto cacheFile = TFileInput(RunConfig.PathToConfigCacheFile);
if (!google::protobuf::TextFormat::ParseFromString(cacheFile.ReadAll(), &appConfig))
ythrow yexception() << "Failed to parse config protobuf from string";
return true;
} catch (const yexception &ex) {
Cerr << "WARNING: an exception occurred while getting config from cache file: " << ex.what() << Endl;
}
return false;
}

void LoadCachedConfigsForStaticNode() {
NKikimrConfig::TAppConfig appConfig;

// log config
if (GetCachedConfig(appConfig) && appConfig.HasLogConfig()) {
AppConfig.MutableLogConfig()->CopyFrom(appConfig.GetLogConfig());
}
}

TNodeLocation CreateNodeLocation() {
NActorsInterconnect::TNodeLocation location;
location.SetDataCenter(DataCenter);
Expand Down Expand Up @@ -1344,30 +1208,6 @@ class TClientCommandServerBase : public TClientCommand {
}
}

bool SaveConfigForNodeToCache(const NKikimrConfig::TAppConfig &appConfig) {
Y_DEBUG_ABORT_UNLESS(RunConfig.PathToConfigCacheFile, "SaveConfigForNodeToCache called without a cms config cache file set");

// Ensure "atomicity" by writing to temp file and renaming it
const TString pathToTempFile = RunConfig.PathToConfigCacheFile + ".tmp";
TString proto;
bool status;
try {
TFileOutput tempFile(pathToTempFile);
status = google::protobuf::TextFormat::PrintToString(appConfig, &proto);
if (status) {
tempFile << proto;
if (!NFs::Rename(pathToTempFile, RunConfig.PathToConfigCacheFile)) {
ythrow yexception() << "Failed to rename temporary file " << LastSystemError() << " " << LastSystemErrorText();
}
}
} catch (const yexception& ex) {
Cerr << "WARNING: an exception occured while saving config to cache file: " << ex.what() << Endl;
status = false;
}

return status;
}

bool TryToLoadConfigForDynamicNodeFromCMS(const TString &addr, TString &error) {
NClient::TKikimr kikimr(GetKikimr(addr));
auto configurator = kikimr.GetNodeConfigurator();
Expand Down Expand Up @@ -1434,27 +1274,11 @@ class TClientCommandServerBase : public TClientCommand {
}
}

if (RunConfig.PathToConfigCacheFile) {
Cout << "Saving config to cache file " << RunConfig.PathToConfigCacheFile << Endl;
if (!SaveConfigForNodeToCache(appConfig)) {
Cout << "Failed to save config to cache file" << Endl;
}
}

ApplyConfigForNode(appConfig);

return true;
}

bool LoadConfigForDynamicNodeFromCache() {
NKikimrConfig::TAppConfig config;
if (GetCachedConfig(config)) {
ApplyConfigForNode(config);
return true;
}
return false;
}

void LoadConfigForDynamicNode() {
auto res = false;
TString error;
Expand All @@ -1479,14 +1303,6 @@ class TClientCommandServerBase : public TClientCommand {

if (!res) {
Cerr << "WARNING: couldn't load config from CMS: " << error << Endl;
if (RunConfig.PathToConfigCacheFile) {
Cout << "Loading config from cache file " << RunConfig.PathToConfigCacheFile << Endl;
if (!LoadConfigForDynamicNodeFromCache())
Cerr << "WARNING: couldn't load config from cache file" << Endl;
} else {
Cerr << "WARNING: option --cms-config-cache-file was not set, ";
Cerr << "couldn't load config from cache file" << Endl;
}
}
}

Expand Down
93 changes: 0 additions & 93 deletions ydb/tests/functional/cms_config_cache/main.py

This file was deleted.

Loading