From 40df519be47f50069e50052e68d5e580f4c0436b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 21 Mar 2019 14:20:37 +0200 Subject: [PATCH] Never reactivate monitors Reactivating monitors shouldn't be done as it's simpler to actually destroy and create a new one. The performance of reactivation is insignificant compared to the possible inconsistency problems it allows. --- server/core/config_runtime.cc | 33 +++++++++++++-------------------- server/core/internal/monitor.hh | 2 -- server/core/monitor.cc | 21 --------------------- 3 files changed, 13 insertions(+), 43 deletions(-) diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index 9d5df5af9..ff34db31b 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -1234,14 +1234,9 @@ bool runtime_create_monitor(const char* name, const char* module, MXS_CONFIG_PAR if (MonitorManager::find_monitor(name) == NULL) { - Monitor* monitor = MonitorManager::reactivate_monitor(name, module); std::string reason; - if (monitor) - { - MXS_DEBUG("Repurposed monitor '%s'", name); - } - else if (config_is_valid_name(name, &reason)) + if (config_is_valid_name(name, &reason)) { MXS_CONFIG_PARAMETER final_params; bool ok; @@ -1254,29 +1249,27 @@ bool runtime_create_monitor(const char* name, const char* module, MXS_CONFIG_PAR final_params.set_multiple(*params); } - if ((monitor = MonitorManager::create_monitor(name, module, &final_params)) == NULL) + Monitor* monitor = MonitorManager::create_monitor(name, module, &final_params); + + if (!monitor) { config_runtime_error("Could not create monitor '%s' with module '%s'", name, module); } + else if (!MonitorManager::monitor_serialize(monitor)) + { + config_runtime_error("Failed to serialize monitor '%s'", name); + } + else + { + MXS_NOTICE("Created monitor '%s'", name); + rval = true; + } } } else { config_runtime_error("%s", reason.c_str()); } - - if (monitor) - { - if (MonitorManager::monitor_serialize(monitor)) - { - MXS_NOTICE("Created monitor '%s'", name); - rval = true; - } - else - { - config_runtime_error("Failed to serialize monitor '%s'", name); - } - } } else { diff --git a/server/core/internal/monitor.hh b/server/core/internal/monitor.hh index e6617c59a..d3783b4bc 100644 --- a/server/core/internal/monitor.hh +++ b/server/core/internal/monitor.hh @@ -132,8 +132,6 @@ public: */ static mxs::Monitor* server_is_monitored(const SERVER* server); - static mxs::Monitor* reactivate_monitor(const char* name, const char* module); - static void show_all_monitors(DCB* dcb); static void monitor_show(DCB* dcb, mxs::Monitor* monitor); diff --git a/server/core/monitor.cc b/server/core/monitor.cc index b9cbab8cf..ca4dac34e 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -680,27 +680,6 @@ Monitor* MonitorManager::find_monitor(const char* name) return rval; } -/** - * Find a destroyed monitor by name - * - * @param name The name of the monitor - * @return Pointer to the destroyed monitor or NULL if monitor is not found - */ -Monitor* MonitorManager::reactivate_monitor(const char* name, const char* module) -{ - Monitor* rval = NULL; - this_unit.foreach_monitor([&rval, name, module](Monitor* monitor) { - if (strcmp(monitor->m_name, name) == 0 && (monitor->m_module == module)) - { - mxb_assert(!monitor->m_active); - monitor->m_active = true; - rval = monitor; - } - return (rval == nullptr); - }); - return rval; -} - /** * Return a resultset that has the current set of monitors in it *