diff --git a/include/maxscale/monitor.hh b/include/maxscale/monitor.hh index 902961065..36a734607 100644 --- a/include/maxscale/monitor.hh +++ b/include/maxscale/monitor.hh @@ -210,9 +210,9 @@ public: virtual bool start(const MXS_CONFIG_PARAMETER* params) = 0; /** - * Stops the monitor. If the monitor uses a polling thread, the thread should be stopped. + * Stops the monitor. */ - virtual void stop() = 0; + void stop(); /** * Write diagnostic information to a DCB. @@ -320,6 +320,10 @@ public: std::vector m_servers; /**< Monitored servers */ protected: + /** + * Stop the monitor. If the monitor uses a polling thread, the thread should be stopped. + */ + virtual void do_stop() = 0; /** * Check if the monitor user can execute a query. The query should be such that it only succeeds if @@ -670,14 +674,7 @@ public: * * @return True, if the monitor started, false otherwise. */ - bool start(const MXS_CONFIG_PARAMETER* params); - - /** - * @brief Stops the monitor. - * - * When the function returns, the monitor has stopped. - */ - void stop(); + bool start(const MXS_CONFIG_PARAMETER* params) final; /** * @brief Write diagnostics @@ -711,6 +708,8 @@ public: protected: MonitorWorker(const std::string& name, const std::string& module); + void do_stop() final; + /** * @brief Should the monitor shut down? * diff --git a/server/core/monitor.cc b/server/core/monitor.cc index d65a81831..cf9ec5811 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -186,6 +186,18 @@ Monitor::Monitor(const string& name, const string& module) memset(m_journal_hash, 0, sizeof(m_journal_hash)); } +void Monitor::stop() +{ + do_stop(); + + for (auto db : m_servers) + { + // TODO: Should be db->close(). + mysql_close(db->con); + db->con = NULL; + } +} + bool Monitor::configure_base(const MXS_CONFIG_PARAMETER* params) { m_settings.conn_settings.read_timeout = params->get_integer(CN_BACKEND_READ_TIMEOUT); @@ -311,13 +323,6 @@ void monitor_stop(Monitor* monitor) monitor->m_state = MONITOR_STATE_STOPPING; monitor->stop(); monitor->m_state = MONITOR_STATE_STOPPED; - - for (auto db : monitor->m_servers) - { - // TODO: Create a generic entry point for this or move it inside stopMonitor - mysql_close(db->con); - db->con = NULL; - } } } @@ -2477,7 +2482,7 @@ monitor_state_t MonitorWorker::monitor_state() const return __atomic_load_n(&(Monitor::m_state), __ATOMIC_RELAXED); // TODO: Convert enum to atomic } -void MonitorWorker::stop() +void MonitorWorker::do_stop() { // This should only be called by monitor_stop(). NULL worker is allowed since the main worker may // not exist during program start/stop.