From 6c32c7421be8e3dacc2c6ffe974b124aba9d9858 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Tue, 27 Mar 2018 16:51:30 +0300 Subject: [PATCH 1/2] MXS-1746 Query global gtid_domain_id instead of session-specific value The monitor queried the session-specific domain id, which does not follow the global value while the session is alive. This caused the monitor to follow the wrong gtid domain if the domain was changed after MaxScale was started. This patch modifies the query to read the global value instead. Even this is not fool-proof, as existing sessions can issue writes with the old domain, confusing the gtid-parsing. --- server/modules/monitor/mariadbmon/mariadbmon.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/modules/monitor/mariadbmon/mariadbmon.cc b/server/modules/monitor/mariadbmon/mariadbmon.cc index 672b09c10..28a560e59 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon.cc +++ b/server/modules/monitor/mariadbmon/mariadbmon.cc @@ -4564,7 +4564,7 @@ static void read_server_variables(MXS_MONITORED_SERVER* database, MySqlServerInf if (serv_info->version == MYSQL_SERVER_VERSION_100) { query.erase(query.end() - 1); - query += ", @@gtid_domain_id;"; + query += ", @@global.gtid_domain_id;"; columns = 3; } From 7209080236a188378ba6e6f1974fab2551de6655 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Tue, 27 Mar 2018 18:21:17 +0300 Subject: [PATCH 2/2] MXS-1747 Improve error messages of rejoin operations Now states which query caused the error. --- .../modules/monitor/mariadbmon/mariadbmon.cc | 71 ++++++++++++++----- 1 file changed, 52 insertions(+), 19 deletions(-) diff --git a/server/modules/monitor/mariadbmon/mariadbmon.cc b/server/modules/monitor/mariadbmon/mariadbmon.cc index 28a560e59..a84529b9e 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon.cc +++ b/server/modules/monitor/mariadbmon/mariadbmon.cc @@ -3774,21 +3774,32 @@ string generate_change_master_cmd(MYSQL_MONITOR* mon, const string& master_host, */ bool redirect_one_slave(MXS_MONITORED_SERVER* slave, const char* change_cmd) { - bool rval = false; - if (mxs_mysql_query(slave->con, "STOP SLAVE;") == 0 && - mxs_mysql_query(slave->con, "RESET SLAVE;") == 0 && // To erase any old I/O or SQL errors - mxs_mysql_query(slave->con, change_cmd) == 0 && - mxs_mysql_query(slave->con, "START SLAVE;") == 0) + bool success = false; + const char* query = "STOP SLAVE;"; + if (mxs_mysql_query(slave->con, query) == 0) { - rval = true; - MXS_NOTICE("Slave '%s' redirected to new master.", slave->server->unique_name); + query = "RESET SLAVE;"; // To erase any old I/O or SQL errors + if (mxs_mysql_query(slave->con, query) == 0) + { + query = "CHANGE MASTER TO ..."; // Don't show the real query as it contains a password. + if (mxs_mysql_query(slave->con, change_cmd) == 0) + { + query = "START SLAVE;"; + if (mxs_mysql_query(slave->con, query) == 0) + { + success = true; + MXS_NOTICE("Slave '%s' redirected to new master.", slave->server->unique_name); + } + } + } } - else + + if (!success) { - MXS_WARNING("Slave '%s' redirection failed: '%s'.", slave->server->unique_name, - mysql_error(slave->con)); + MXS_WARNING("Slave '%s' redirection failed: '%s'. Query: '%s'.", slave->server->unique_name, + mysql_error(slave->con), query); } - return rval; + return success; } /** @@ -4782,18 +4793,40 @@ static bool join_cluster(MXS_MONITORED_SERVER* server, const char* change_cmd) { /* Server does not have slave connections. This operation can fail, or the resulting * replication may end up broken. */ - bool rval = false; - if (mxs_mysql_query(server->con, "SET GLOBAL read_only=1;") == 0 && - mxs_mysql_query(server->con, change_cmd) == 0 && - mxs_mysql_query(server->con, "START SLAVE;") == 0) + bool success = false; + string error_msg; + const char* query = "SET GLOBAL read_only=1;"; + if (mxs_mysql_query(server->con, query) == 0) { - rval = true; + query = "CHANGE MASTER TO ..."; // Don't show the real query as it contains a password. + if (mxs_mysql_query(server->con, change_cmd) == 0) + { + query = "START SLAVE;"; + if (mxs_mysql_query(server->con, query) == 0) + { + success = true; + MXS_NOTICE("Standalone server '%s' starting replication.", server->server->unique_name); + } + } + + if (!success) + { + // A step after "SET GLOBAL read_only=1" failed, try to undo. First, backup error message. + error_msg = mysql_error(server->con); + mxs_mysql_query(server->con, "SET GLOBAL read_only=0;"); + } } - else + + if (!success) { - mxs_mysql_query(server->con, "SET GLOBAL read_only=0;"); + if (error_msg.empty()) + { + error_msg = mysql_error(server->con); + } + MXS_WARNING("Standalone server '%s' failed to start replication: '%s'. Query: '%s'.", + server->server->unique_name, error_msg.c_str(), query); } - return rval; + return success; } /**