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.
This commit is contained in:
Esa Korhonen
2018-04-23 16:05:47 +03:00
parent 2aeed3ffab
commit fa7cd9450a
2 changed files with 22 additions and 20 deletions

View File

@ -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 `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 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 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 Since the queries in the files are ran during operations which modify
replication topology, care is required. If `promotion_sql_file` contains data replication topology, care is required. If `promotion_sql_file` contains data

View File

@ -4793,19 +4793,20 @@ static uint32_t do_rejoin(MYSQL_MONITOR* mon, const ServerVector& joinable_serve
const char* master_name = master->unique_name; const char* master_name = master->unique_name;
MySqlServerInfo* redir_info = get_server_info(mon, joinable); MySqlServerInfo* redir_info = get_server_info(mon, joinable);
bool op_success = false;
if (redir_info->n_slaves_configured == 0)
{
if (*mon->demote_sql_file && !run_sql_from_file(joinable, mon->demote_sql_file, output)) 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'.", PRINT_MXS_JSON_ERROR(output, "%s execution failed when attempting to rejoin server '%s'.",
CN_DEMOTION_SQL_FILE, joinable->server->unique_name); CN_DEMOTION_SQL_FILE, joinable->server->unique_name);
} }
else else
{
bool op_success;
if (redir_info->n_slaves_configured == 0)
{ {
MXS_NOTICE("Directing standalone server '%s' to replicate from '%s'.", name, master_name); MXS_NOTICE("Directing standalone server '%s' to replicate from '%s'.", name, master_name);
op_success = join_cluster(joinable, change_cmd.c_str()); op_success = join_cluster(joinable, change_cmd.c_str());
} }
}
else else
{ {
MXS_NOTICE("Server '%s' is replicating from a server other than '%s', " MXS_NOTICE("Server '%s' is replicating from a server other than '%s', "
@ -4819,7 +4820,6 @@ static uint32_t do_rejoin(MYSQL_MONITOR* mon, const ServerVector& joinable_serve
} }
} }
} }
}
return servers_joined; return servers_joined;
} }
@ -4933,7 +4933,8 @@ static bool run_sql_from_file(MXS_MONITORED_SERVER* server, const string& path,
std::ifstream sql_file(path); std::ifstream sql_file(path);
if (sql_file.is_open()) 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; int lines_executed = 0;
while (!sql_file.eof() && !error) while (!sql_file.eof() && !error)