From 9f6efef67a6b68875241dea08f491311bf31f1dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 5 Aug 2019 13:09:09 +0300 Subject: [PATCH] MXS-2576: Update states atomically in csmon This prevents false transient states from occurring. --- server/modules/monitor/csmon/csmon.cc | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/server/modules/monitor/csmon/csmon.cc b/server/modules/monitor/csmon/csmon.cc index d57896644..a13e390e7 100644 --- a/server/modules/monitor/csmon/csmon.cc +++ b/server/modules/monitor/csmon/csmon.cc @@ -56,7 +56,7 @@ static std::string do_query(MXS_MONITORED_SERVER* srv, const char* query) // Returns a numeric version similar to mysql_get_server_version int get_cs_version(MXS_MONITORED_SERVER* srv) { - int rval = 0; + int rval = -1; std::string prefix = "Columnstore "; std::string result = do_query(srv, "SELECT @@version_comment"); auto pos = result.find(prefix); @@ -106,16 +106,21 @@ void CsMonitor::update_server_status(MXS_MONITORED_SERVER* srv) if (do_query(srv, alive_query) == "1") { - status |= SERVER_RUNNING; + auto version = get_cs_version(srv); - if (get_cs_version(srv) >= 10200) + if (version >= 0) { - // 1.2 supports the mcsSystemPrimary function - status |= do_query(srv, role_query) == "1" ? SERVER_MASTER : SERVER_SLAVE; - } - else - { - status |= srv->server == m_primary ? SERVER_MASTER : SERVER_SLAVE; + status |= SERVER_RUNNING; + + if (version >= 10200) + { + // 1.2 supports the mcsSystemPrimary function + status |= do_query(srv, role_query) == "1" ? SERVER_MASTER : SERVER_SLAVE; + } + else + { + status |= srv->server == m_primary ? SERVER_MASTER : SERVER_SLAVE; + } } }