From 64df20cb365ca4da03f8ab8dfbc1c62d85fb6896 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sat, 25 Feb 2023 12:39:35 -0500 Subject: [PATCH] refactor: Remove unused config-fallback path This seems to have been here since the dawn of Spark. It is only initialized via the -ConfigFallback option in the sparkd cli, an option that no one ever uses (the cli provides no documentation for it either). --- src/lib/config/ConfigurationState.cpp | 53 ++++++--------------------- src/lib/config/ConfigurationState.h | 2 +- 2 files changed, 12 insertions(+), 43 deletions(-) diff --git a/src/lib/config/ConfigurationState.cpp b/src/lib/config/ConfigurationState.cpp index dc31a484c..179b97923 100644 --- a/src/lib/config/ConfigurationState.cpp +++ b/src/lib/config/ConfigurationState.cpp @@ -50,7 +50,6 @@ namespace internal { const char *MESSAGE_STRING_RULE = "rule"; const char *MESSAGE_STRING_VALUE = "value"; const char *MESSAGE_STRING_INCLUDE = "include"; -const char *MESSAGE_STRING_INCLUDE_BACKUP = "fallback"; const char *MESSAGE_STRING_MACRO_TYPE = "MacroType"; const char *MESSAGE_STRING_MACRO = "macro"; @@ -75,12 +74,10 @@ std::string get_command_argument(const char *key) { for (; begin != end; begin++) { if (boost::iequals(*begin, key)) { begin++; - if (begin == end) { - break; - } else { - os::setenv(CONFIG_SERVER_ENV_VAR, begin->c_str()); + if (begin != end) { return *begin; } + break; } } return ""; @@ -361,12 +358,14 @@ void ConfigurationState::initialize_settings() { initialize_defaults(log); std::string settings = settings_path(); - std::string fallback = get_command_argument("-ConfigFallback"); + bts_assert_msg(!settings.empty(), "Failed to determine config path"); + os::setenv(CONFIG_SERVER_ENV_VAR, settings.c_str()); { DEFER( // Do this even if load() fails - initialize_builtins(); initialize_macros(); _deferred_queue->process();); - load(settings, fallback, log); + initialize_builtins(); initialize_macros(); + _deferred_queue->process();); + load(settings, log); } std::vector descs; @@ -395,29 +394,12 @@ void ConfigurationState::reset() { _port = 80; } -int ConfigurationState::load( - const std::string &url, const std::string &fallback_url, IConfigLog &log) { +int ConfigurationState::load(const std::string &url, IConfigLog &log) { std::shared_ptr new_message(_prototype->New()); bool loaded = false; - try { - loaded = - load_message(url, *new_message.get(), log, *_deferred_queue.get()); - } catch (ServerUnreachableException &) { - if (fallback_url.empty()) { - throw; - } - } + loaded = load_message(url, *new_message.get(), log, *_deferred_queue.get()); - if (!loaded && !fallback_url.empty()) { - std::string message = "Failed to load: " + url + " using fallback."; - log.warning(message); - loaded = load_message( - fallback_url, *new_message.get(), log, *_deferred_queue.get()); - if (_host.empty() || _host == "localhost") { - tie(_host, _port) = hostname(fallback_url); - } - } if (_host.empty() || _host == "localhost") { tie(_host, _port) = hostname(url); } @@ -425,14 +407,13 @@ int ConfigurationState::load( return 0; std::string include = get_include(*new_message.get()); - std::string fallback = get_fallback(*new_message.get()); // insert at front? _config_chain.push_back(new_message); // Recursively load includes if (!include.empty()) { - return 1 + load(include, fallback, log); + return 1 + load(include, log); } return 1; } @@ -452,13 +433,12 @@ int ConfigurationState::load_string( *_deferred_queue.get()); std::string include = get_include(*new_message.get()); - std::string fallback = get_fallback(*new_message.get()); _config_chain.push_back(new_message); int count = 0; if (!include.empty()) { - count += load(include, fallback, log); + count += load(include, log); } if (_host.empty()) { @@ -524,13 +504,6 @@ void ConfigurationState::generate_all_config_proto( include_field->set_type(proto::FieldDescriptorProto_Type_TYPE_STRING); include_field->set_label(proto::FieldDescriptorProto_Label_LABEL_OPTIONAL); - // Add the 'fallback' field - proto::FieldDescriptorProto *backup_field = config_message->add_field(); - backup_field->set_name(MESSAGE_STRING_INCLUDE_BACKUP); - backup_field->set_number(++field_number); - backup_field->set_type(proto::FieldDescriptorProto_Type_TYPE_STRING); - backup_field->set_label(proto::FieldDescriptorProto_Label_LABEL_OPTIONAL); - // Add 'macro' message type proto::DescriptorProto *macro_message = bts_config_dp.add_message_type(); macro_message->set_name(MESSAGE_STRING_MACRO_TYPE); @@ -963,10 +936,6 @@ std::string get_include(const proto::Message &message) { return get_field(message, MESSAGE_STRING_INCLUDE); } -std::string get_fallback(const proto::Message &message) { - return get_field(message, MESSAGE_STRING_INCLUDE_BACKUP); -} - } // namespace internal } // namespace config } // namespace bts diff --git a/src/lib/config/ConfigurationState.h b/src/lib/config/ConfigurationState.h index 29ddd9506..7351a5f0c 100644 --- a/src/lib/config/ConfigurationState.h +++ b/src/lib/config/ConfigurationState.h @@ -54,7 +54,7 @@ class ConfigurationState { void initialize_defaults(IConfigLog &log, const std::vector &proto_dirs); void initialize_settings(); - int load(const std::string &url, const std::string &fallback, IConfigLog &); + int load(const std::string &url, IConfigLog &); int load_string(const std::string &values, bool print_errors = false); void reset();