From fa7cd9450affa07f0b62de12301f257022e7f3ec Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Mon, 23 Apr 2018 16:05:47 +0300 Subject: [PATCH] MXS-1639 Do not run demote_sql_file if the server already has a slave connection In this case, the server was already a slave and is not being demoted. Also, the file may contain queries which cannot be ran while a slave connection is running. --- Documentation/Monitors/MariaDB-Monitor.md | 3 +- .../modules/monitor/mariadbmon/mariadbmon.cc | 39 ++++++++++--------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Documentation/Monitors/MariaDB-Monitor.md b/Documentation/Monitors/MariaDB-Monitor.md index fb0358b4d..0ceff9a34 100644 --- a/Documentation/Monitors/MariaDB-Monitor.md +++ b/Documentation/Monitors/MariaDB-Monitor.md @@ -459,7 +459,8 @@ from an external master if any. `demotion_sql_file` is ran on an old master during demotion to slave, before the old master starts replicating from the new master. The file is also ran before rejoining a standalone server to the cluster, as the standalone server is -typically a former master server. +typically a former master server. When redirecting a slave replicating from a +wrong master, the sql-file is not executed. Since the queries in the files are ran during operations which modify replication topology, care is required. If `promotion_sql_file` contains data diff --git a/server/modules/monitor/mariadbmon/mariadbmon.cc b/server/modules/monitor/mariadbmon/mariadbmon.cc index 72d59a875..464fd3ef9 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon.cc +++ b/server/modules/monitor/mariadbmon/mariadbmon.cc @@ -4793,30 +4793,30 @@ static uint32_t do_rejoin(MYSQL_MONITOR* mon, const ServerVector& joinable_serve const char* master_name = master->unique_name; MySqlServerInfo* redir_info = get_server_info(mon, joinable); - if (*mon->demote_sql_file && !run_sql_from_file(joinable, mon->demote_sql_file, output)) + bool op_success = false; + if (redir_info->n_slaves_configured == 0) { - PRINT_MXS_JSON_ERROR(output, "%s execution failed when attempting to rejoin server '%s'.", - CN_DEMOTION_SQL_FILE, joinable->server->unique_name); - } - else - { - bool op_success; - if (redir_info->n_slaves_configured == 0) + if (*mon->demote_sql_file && !run_sql_from_file(joinable, mon->demote_sql_file, output)) + { + PRINT_MXS_JSON_ERROR(output, "%s execution failed when attempting to rejoin server '%s'.", + CN_DEMOTION_SQL_FILE, joinable->server->unique_name); + } + else { MXS_NOTICE("Directing standalone server '%s' to replicate from '%s'.", name, master_name); op_success = join_cluster(joinable, change_cmd.c_str()); } - else - { - MXS_NOTICE("Server '%s' is replicating from a server other than '%s', " - "redirecting it to '%s'.", name, master_name, master_name); - op_success = redirect_one_slave(joinable, change_cmd.c_str()); - } + } + else + { + MXS_NOTICE("Server '%s' is replicating from a server other than '%s', " + "redirecting it to '%s'.", name, master_name, master_name); + op_success = redirect_one_slave(joinable, change_cmd.c_str()); + } - if (op_success) - { - servers_joined++; - } + if (op_success) + { + servers_joined++; } } } @@ -4933,7 +4933,8 @@ static bool run_sql_from_file(MXS_MONITORED_SERVER* server, const string& path, std::ifstream sql_file(path); if (sql_file.is_open()) { - MXS_NOTICE("Executing sql queries from file '%s'.", path.c_str()); + MXS_NOTICE("Executing sql queries from file '%s' on server '%s'.", path.c_str(), + server->server->unique_name); int lines_executed = 0; while (!sql_file.eof() && !error)