diff --git a/server/core/config.cc b/server/core/config.cc index 9216f1340..930166135 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -4666,6 +4666,7 @@ MXS_CONFIG_PARAMETER* ParamList::params() return m_ctx.parameters; } +} void dump_if_changed(const MXS_MODULE_PARAM* params, int file, const std::string& key, const std::string& value) @@ -4694,4 +4695,17 @@ void dump_if_changed(const MXS_MODULE_PARAM* params, int file, } } +void dump_param_list(int file, MXS_CONFIG_PARAMETER* list, + const std::unordered_set& ignored, + const MXS_MODULE_PARAM* common_params, + const MXS_MODULE_PARAM* module_params) +{ + for (auto p = list; p; p = p->next) + { + if (ignored.count(p->name) == 0 && *p->value) + { + dump_if_changed(common_params, file, p->name, p->value); + dump_if_changed(module_params, file, p->name, p->value); + } + } } diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index 4fbee5e33..bcefd6525 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -585,6 +585,7 @@ bool runtime_alter_service(Service *service, const char* zKey, const char* zValu if (service->is_basic_parameter(key)) { + service_replace_parameter(service, zKey, zValue); service->update_basic_parameter(key, value); } else diff --git a/server/core/filter.cc b/server/core/filter.cc index e1142b1f6..a8b903b5c 100644 --- a/server/core/filter.cc +++ b/server/core/filter.cc @@ -534,18 +534,12 @@ static bool create_filter_config(const SFilterDef& filter, const char *filename) dprintf(file, "[%s]\n", filter->name.c_str()); dprintf(file, "%s=%s\n", CN_TYPE, CN_FILTER); - dprintf(file, "%s=%s\n", CN_MODULE, filter->module.c_str()); - std::set param_set{CN_TYPE, CN_MODULE}; - - for (MXS_CONFIG_PARAMETER* p = filter->parameters; p; p = p->next) - { - if (param_set.count(p->name) == 0) - { - dprintf(file, "%s=%s\n", p->name, p->value); - } - } + const MXS_MODULE* mod = get_module(filter->module.c_str(), NULL); + ss_dassert(mod); + MXS_MODULE_PARAM no_common_params = {}; + dump_param_list(file, filter->parameters, {CN_TYPE}, &no_common_params, mod->parameters); close(file); return true; diff --git a/server/core/internal/config.hh b/server/core/internal/config.hh index faa8093d2..4a50638bd 100644 --- a/server/core/internal/config.hh +++ b/server/core/internal/config.hh @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -218,60 +219,8 @@ bool is_normal_server_parameter(const char *param); */ bool get_suffixed_size(const char* value, uint64_t* dest); -namespace maxscale -{ - -// Internal function -void dump_if_changed(const MXS_MODULE_PARAM* params, int file, - const std::string& key, const std::string& value); - - -/** - * Dump a parameter into a file descriptor - * - * The function detects only literal matches to the string format default values. - * If the string conversion results in an empty string, the value will not be - * dumped. This can only happen if an empty string is passed as the value. - * - * The function writes a single key-value pair into the file and terminates - * the line with a newline. This is intended to be used with configuration - * dumping code in the core. - * - * Note: Does not work with enum type parameters, they'll get converted into - * integers. Convert them to string format at the call site. - * - * @param file File descriptor where the line is written - * @param key Name of the parameter - * @param value The parameter value - * @param params List of module parameters to use - */ -template -inline void dump_param(int file, const std::string& key, const T value, std::initializer_list params) -{ - std::stringstream ss; - ss << value; - auto strval = ss.str(); - - if (!strval.empty()) - { - // Don't dump empty values - for (auto a : params) - { - dump_if_changed(a, file, key, strval); - } - } -} - -// Specialization required to dump booleans in the same format as they used in -// the defaults. This requires that all defaults use either "true" or "false" -// for the values. -template <> -inline void dump_param(int file, const std::string& key, bool value, std::initializer_list params) -{ - for (auto a : params) - { - dump_if_changed(a, file, key, value ? "true" : "false"); - } -} - -} +// Dump a parameter list into a file as `key=value` pairs +void dump_param_list(int file, MXS_CONFIG_PARAMETER* list, + const std::unordered_set& ignored, + const MXS_MODULE_PARAM* common_params, + const MXS_MODULE_PARAM* module_params); diff --git a/server/core/monitor.cc b/server/core/monitor.cc index a39bafdf1..b5dff04c6 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -1562,16 +1562,6 @@ static bool create_monitor_config(const MXS_MONITOR *monitor, const char *filena dprintf(file, "[%s]\n", monitor->name); dprintf(file, "%s=monitor\n", CN_TYPE); - dprintf(file, "%s=%s\n", CN_MODULE, monitor->module_name); - dprintf(file, "%s=%s\n", CN_USER, monitor->user); - dprintf(file, "%s=%s\n", CN_PASSWORD, monitor->password); - dprintf(file, "%s=%lu\n", CN_MONITOR_INTERVAL, monitor->interval); - dprintf(file, "%s=%d\n", CN_BACKEND_CONNECT_TIMEOUT, monitor->connect_timeout); - dprintf(file, "%s=%d\n", CN_BACKEND_WRITE_TIMEOUT, monitor->write_timeout); - dprintf(file, "%s=%d\n", CN_BACKEND_READ_TIMEOUT, monitor->read_timeout); - dprintf(file, "%s=%d\n", CN_BACKEND_CONNECT_ATTEMPTS, monitor->connect_attempts); - dprintf(file, "%s=%ld\n", CN_JOURNAL_MAX_AGE, monitor->journal_max_age); - dprintf(file, "%s=%d\n", CN_SCRIPT_TIMEOUT, monitor->script_timeout); if (monitor->monitored_servers) { @@ -1587,35 +1577,12 @@ static bool create_monitor_config(const MXS_MONITOR *monitor, const char *filena dprintf(file, "\n"); } - const char* params[] = - { - CN_TYPE, - CN_MODULE, - CN_USER, - CN_PASSWORD, - "passwd", // TODO: Remove this - CN_MONITOR_INTERVAL, - CN_BACKEND_CONNECT_TIMEOUT, - CN_BACKEND_WRITE_TIMEOUT, - CN_BACKEND_READ_TIMEOUT, - CN_BACKEND_CONNECT_ATTEMPTS, - CN_JOURNAL_MAX_AGE, - CN_SCRIPT_TIMEOUT, - CN_SERVERS - }; - - std::set param_set(params, params + sizeof(params) / sizeof(params[0])); - - for (MXS_CONFIG_PARAMETER* p = monitor->parameters; p; p = p->next) - { - if (param_set.find(p->name) == param_set.end()) - { - dprintf(file, "%s=%s\n", p->name, p->value); - } - } + const MXS_MODULE* mod = get_module(monitor->module_name, NULL); + ss_dassert(mod); + dump_param_list(file, monitor->parameters, {CN_TYPE, CN_SERVERS}, + config_monitor_params, mod->parameters); spinlock_release(&monitor->lock); - close(file); return true; diff --git a/server/core/service.cc b/server/core/service.cc index c53329f77..3ebf1321b 100644 --- a/server/core/service.cc +++ b/server/core/service.cc @@ -1779,23 +1779,6 @@ bool Service::dump_config(const char *filename) const */ dprintf(file, "[%s]\n", m_name.c_str()); dprintf(file, "%s=service\n", CN_TYPE); - dprintf(file, "%s=%s\n", CN_ROUTER, m_router_name.c_str()); - dprintf(file, "%s=%s\n", CN_USER, m_user.c_str()); - dprintf(file, "%s=%s\n", CN_PASSWORD, m_password.c_str()); - - const MXS_MODULE_PARAM* mp = config_service_params; - - dump_param(file, CN_ENABLE_ROOT_USER, enable_root, {mp}); - dump_param(file, CN_MAX_RETRY_INTERVAL, max_retry_interval, {mp}); - dump_param(file, CN_MAX_CONNECTIONS, max_connections, {mp}); - dump_param(file, CN_CONNECTION_TIMEOUT, conn_idle_timeout, {mp}); - dump_param(file, CN_AUTH_ALL_SERVERS, users_from_all, {mp}); - dump_param(file, CN_STRIP_DB_ESC, strip_db_esc, {mp}); - dump_param(file, CN_LOCALHOST_MATCH_WILDCARD_HOST, localhost_match_wildcard_host, {mp}); - dump_param(file, CN_LOG_AUTH_WARNINGS, log_auth_warnings, {mp}); - dump_param(file, CN_RETRY_ON_FAILURE, retry_start, {mp}); - dump_param(file, CN_VERSION_STRING, m_version_string, {mp}); - dump_param(file, CN_WEIGHTBY, m_weightby, {mp}); if (!m_filters.empty()) { @@ -1827,36 +1810,11 @@ bool Service::dump_config(const char *filename) const dprintf(file, "\n"); } - std::unordered_set common_params - { - CN_TYPE, - CN_USER, - CN_PASSWORD, - CN_ENABLE_ROOT_USER, - CN_MAX_RETRY_INTERVAL, - CN_MAX_CONNECTIONS, - CN_CONNECTION_TIMEOUT, - CN_AUTH_ALL_SERVERS, - CN_STRIP_DB_ESC, - CN_LOCALHOST_MATCH_WILDCARD_HOST, - CN_LOG_AUTH_WARNINGS, - CN_RETRY_ON_FAILURE, - CN_VERSION_STRING, - CN_WEIGHTBY, - CN_SERVERS - }; - const MXS_MODULE* mod = get_module(m_router_name.c_str(), NULL); ss_dassert(mod); - // Dump router specific parameters - for (auto p = svc_config_param; p; p = p->next) - { - if (common_params.count(p->name) == 0) - { - dump_param(file, p->name, p->value, {mod->parameters}); - } - } + dump_param_list(file, svc_config_param, {CN_TYPE, CN_FILTERS, CN_SERVERS}, + config_service_params, mod->parameters); close(file);