From 14e38e4e087efc5488e9319e5bae2d25e6192fd2 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Mon, 12 Nov 2018 12:36:30 +0200 Subject: [PATCH] MXS-2158 Return true if update_gtids() succeeds, even if no data is returned Previously, if the server had no gtid:s, the method would fail leading to a confusing error message. This could even totally stop the monitor from working if a recent server version (10.X) did not have any gtid events. --- .../monitor/mariadbmon/mariadbserver.cc | 45 +++++++++++-------- .../monitor/mariadbmon/mariadbserver.hh | 2 +- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/server/modules/monitor/mariadbmon/mariadbserver.cc b/server/modules/monitor/mariadbmon/mariadbserver.cc index 3c0329c95..0ef954c2b 100644 --- a/server/modules/monitor/mariadbmon/mariadbserver.cc +++ b/server/modules/monitor/mariadbmon/mariadbserver.cc @@ -376,32 +376,39 @@ bool MariaDBServer::update_gtids(string* errmsg_out) bool rval = false; auto result = execute_query(query, errmsg_out); - if (result.get() != NULL && result->next_row()) + if (result.get() != NULL) { - auto current_str = result->get_string(i_current_pos); - auto binlog_str = result->get_string(i_binlog_pos); - bool current_ok = false; - if (current_str.empty()) + rval = true; + if (result->next_row()) { - m_gtid_current_pos = GtidList(); + // Query returned at least some data. + auto current_str = result->get_string(i_current_pos); + auto binlog_str = result->get_string(i_binlog_pos); + if (current_str.empty()) + { + m_gtid_current_pos = GtidList(); + } + else + { + m_gtid_current_pos = GtidList::from_string(current_str); + } + + if (binlog_str.empty()) + { + m_gtid_binlog_pos = GtidList(); + } + else + { + m_gtid_binlog_pos = GtidList::from_string(binlog_str); + } } else { - m_gtid_current_pos = GtidList::from_string(current_str); - current_ok = !m_gtid_current_pos.empty(); - } - - if (binlog_str.empty()) - { + // Query succeeded but returned 0 rows. This means that the server has no gtid:s. + m_gtid_current_pos = GtidList(); m_gtid_binlog_pos = GtidList(); } - else - { - m_gtid_binlog_pos = GtidList::from_string(binlog_str); - } - - rval = current_ok; - } + } // If query failed, do not update gtid:s. return rval; } diff --git a/server/modules/monitor/mariadbmon/mariadbserver.hh b/server/modules/monitor/mariadbmon/mariadbserver.hh index 94bf233aa..c35d4b016 100644 --- a/server/modules/monitor/mariadbmon/mariadbserver.hh +++ b/server/modules/monitor/mariadbmon/mariadbserver.hh @@ -202,7 +202,7 @@ public: * Query gtid_current_pos and gtid_binlog_pos and save the values to the server. * * @param errmsg_out Where to store an error message if query fails. Can be null. - * @return True if successful + * @return True if query succeeded */ bool update_gtids(std::string* errmsg_out = NULL);