From 0833db8a480d5a4b1c836a505ab560b37044e80f Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Fri, 25 May 2018 09:09:21 +0300 Subject: [PATCH] MXS-1775 Flush pending status to servers using common code --- include/maxscale/monitor.hh | 30 +++++++++++++------ server/core/monitor.cc | 20 ++++++++++++- server/modules/monitor/auroramon/auroramon.cc | 2 -- server/modules/monitor/galeramon/galeramon.cc | 8 ----- server/modules/monitor/grmon/grmon.cc | 2 -- server/modules/monitor/mmmon/mmmon.cc | 3 -- .../monitor/ndbclustermon/ndbclustermon.cc | 2 -- 7 files changed, 40 insertions(+), 27 deletions(-) diff --git a/include/maxscale/monitor.hh b/include/maxscale/monitor.hh index f7fba458a..a98ef0826 100644 --- a/include/maxscale/monitor.hh +++ b/include/maxscale/monitor.hh @@ -64,6 +64,15 @@ protected: */ virtual void configure(const MXS_CONFIG_PARAMETER* pParams); + /** + * @brief Flush pending server status to each server. + * + * This function is expected to flush the pending status to each server. + * The default implementation simply copies monitored_server->pending_status + * to server->status. + */ + virtual void flush_server_status(); + /** * @brief Monitor the servers * @@ -71,15 +80,18 @@ protected: * implementation should probe all servers, i.e. call @c update_server_status * on each server. * - * The default implementation will: - * - Not call @c update_server_status for a server that is in maintenance. - * - Before calling, update the previous status of the server. - * - Before calling, update the pending status of the monitored server object - * to the status of the corresponing server object. - * - Ensure that there is a connection to the server. If that fails, then - * the pending status will be updated accordingly and @c update_server_status - * will *not* be called. - * - After the call, update the error count of the server. + * The default implementation will for each server: + * - Do nothing, if the server is in maintenance. + * - Before calling, store the previous status of the server. + * - Before calling, set the pending status of the monitored server object + * to the status of the corresponding server object. + * - Ensure that there is a connection to the server. + * If there is, @c update_server_status is called. + * If there is not, the pending status will be updated accordingly and + * @c update_server_status will *not* be called. + * - After the call, update the error count of the server if it is down. + * + * Finally, it will call @c flush_server_status. */ virtual void tick(); diff --git a/server/core/monitor.cc b/server/core/monitor.cc index 5cbd6ce2a..25b4e0792 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -2635,6 +2635,17 @@ void MonitorInstance::configure(const MXS_CONFIG_PARAMETER* pParams) { } +void MonitorInstance::flush_server_status() +{ + for (MXS_MONITORED_SERVER *pMs = m_monitor->monitored_servers; pMs; pMs = pMs->next) + { + if (!SERVER_IN_MAINT(pMs->server)) + { + pMs->server->status = pMs->pending_status; + } + } +} + void MonitorInstance::tick() { for (MXS_MONITORED_SERVER *pMs = m_monitor->monitored_servers; pMs; pMs = pMs->next) @@ -2672,13 +2683,18 @@ void MonitorInstance::tick() } } +#if defined(SS_DEBUG) if (mon_status_changed(pMs) || mon_print_fail_status(pMs)) { + // The current status is still in pMs->pending_status. + SERVER server = {}; + server.status = pMs->pending_status; MXS_DEBUG("Backend server [%s]:%d state : %s", pMs->server->address, pMs->server->port, - STRSRVSTATUS(pMs->server)); + STRSRVSTATUS(&server)); } +#endif if (SERVER_IS_DOWN(pMs->server)) { @@ -2690,6 +2706,8 @@ void MonitorInstance::tick() } } } + + flush_server_status(); } void MonitorInstance::main() diff --git a/server/modules/monitor/auroramon/auroramon.cc b/server/modules/monitor/auroramon/auroramon.cc index bc8b10ba1..8392b1c74 100644 --- a/server/modules/monitor/auroramon/auroramon.cc +++ b/server/modules/monitor/auroramon/auroramon.cc @@ -83,8 +83,6 @@ void AuroraMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server) { mon_report_query_error(monitored_server); } - - monitored_server->server->status = monitored_server->pending_status; } bool AuroraMonitor::has_sufficient_permissions() const diff --git a/server/modules/monitor/galeramon/galeramon.cc b/server/modules/monitor/galeramon/galeramon.cc index e8635908a..8bd3efa6a 100644 --- a/server/modules/monitor/galeramon/galeramon.cc +++ b/server/modules/monitor/galeramon/galeramon.cc @@ -492,14 +492,6 @@ void GaleraMonitor::tick() { update_sst_donor_nodes(is_cluster); } - - ptr = m_monitor->monitored_servers; - - while (ptr) - { - ptr->server->status = ptr->pending_status; - ptr = ptr->next; - } } /** diff --git a/server/modules/monitor/grmon/grmon.cc b/server/modules/monitor/grmon/grmon.cc index 32321730d..f2b8b3773 100644 --- a/server/modules/monitor/grmon/grmon.cc +++ b/server/modules/monitor/grmon/grmon.cc @@ -142,8 +142,6 @@ void GRMon::update_server_status(MXS_MONITORED_SERVER* monitored_server) monitor_clear_pending_status(monitored_server, SERVER_SLAVE); monitor_clear_pending_status(monitored_server, SERVER_MASTER); } - - monitored_server->server->status = monitored_server->pending_status; } /** diff --git a/server/modules/monitor/mmmon/mmmon.cc b/server/modules/monitor/mmmon/mmmon.cc index 04b202c5f..4a08c1e5d 100644 --- a/server/modules/monitor/mmmon/mmmon.cc +++ b/server/modules/monitor/mmmon/mmmon.cc @@ -419,10 +419,7 @@ void MMMonitor::tick() /* Set the STALE bit for this server in server struct */ monitor_set_pending_status(ptr, SERVER_STALE_STATUS); } - - ptr->server->status = ptr->pending_status; } - ptr = ptr->next; } } diff --git a/server/modules/monitor/ndbclustermon/ndbclustermon.cc b/server/modules/monitor/ndbclustermon/ndbclustermon.cc index 98b4aa1e0..5f87da3c6 100644 --- a/server/modules/monitor/ndbclustermon/ndbclustermon.cc +++ b/server/modules/monitor/ndbclustermon/ndbclustermon.cc @@ -206,6 +206,4 @@ void NDBCMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server) monitor_clear_pending_status(monitored_server, SERVER_NDB); monitored_server->server->depth = -1; } - - monitored_server->server->status = monitored_server->pending_status; }