From 92f18bdedeec3a3e8ea6f675d4e284fcb46af205 Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Wed, 22 Mar 2017 01:48:22 +0400 Subject: [PATCH] MDEV-11177 mysqlbinlog exits silently without error when another instance connects to server. New thread kill status added KILL_SLAVE_SAME_ID, and the related error message. --- sql/share/errmsg-utf8.txt | 2 ++ sql/signal_handler.cc | 3 +++ sql/sql_class.cc | 2 ++ sql/sql_class.h | 18 ++++++++++++------ sql/sql_repl.cc | 12 ++++++++++-- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 8939910fc29a5..ae4dc5984bb13 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -7448,3 +7448,5 @@ ER_GEOJSON_NOT_CLOSED eng "Incorrect GeoJSON format - polygon not closed." ER_JSON_PATH_EMPTY eng "Path expression '$' is not allowed in argument %d to function '%s'." +ER_SLAVE_SAME_ID + eng "A slave with the same server_uuid/server_id as this slave has connected to the master" diff --git a/sql/signal_handler.cc b/sql/signal_handler.cc index dc90fcae57656..efcc9a3f0b252 100644 --- a/sql/signal_handler.cc +++ b/sql/signal_handler.cc @@ -201,6 +201,9 @@ extern "C" sig_handler handle_fatal_signal(int sig) case ABORT_QUERY_HARD: kreason= "ABORT_QUERY"; break; + case KILL_SLAVE_SAME_ID: + kreason= "KILL_SLAVE_SAME_ID"; + break; } my_safe_printf_stderr("%s", "\n" "Trying to get some variables.\n" diff --git a/sql/sql_class.cc b/sql/sql_class.cc index f042e6600e062..c3bd40cf23071 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1987,6 +1987,8 @@ int killed_errno(killed_state killed) case KILL_SERVER: case KILL_SERVER_HARD: DBUG_RETURN(ER_SERVER_SHUTDOWN); + case KILL_SLAVE_SAME_ID: + DBUG_RETURN(ER_SLAVE_SAME_ID); } DBUG_RETURN(0); // Keep compiler happy } diff --git a/sql/sql_class.h b/sql/sql_class.h index 22895d7a2d8b0..986cb1c479327 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -477,17 +477,23 @@ enum killed_state ABORT_QUERY_HARD= 7, KILL_TIMEOUT= 8, KILL_TIMEOUT_HARD= 9, + /* + When binlog reading thread connects to the server it kills + all the binlog threads with the same ID. + */ + KILL_SLAVE_SAME_ID= 10, /* All of the following killed states will kill the connection KILL_CONNECTION must be the first of these and it must start with an even number (becasue of HARD bit)! */ - KILL_CONNECTION= 10, - KILL_CONNECTION_HARD= 11, - KILL_SYSTEM_THREAD= 12, - KILL_SYSTEM_THREAD_HARD= 13, - KILL_SERVER= 14, - KILL_SERVER_HARD= 15 + KILL_CONNECTION= 12, + KILL_CONNECTION_HARD= 13, + KILL_SYSTEM_THREAD= 14, + KILL_SYSTEM_THREAD_HARD= 15, + KILL_SERVER= 16, + KILL_SERVER_HARD= 17, + }; extern int killed_errno(killed_state killed); diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 2a22810b8c2f8..0180671977c27 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -2910,6 +2910,13 @@ void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, THD_STAGE_INFO(thd, stage_waiting_to_finalize_termination); RUN_HOOK(binlog_transmit, transmit_stop, (thd, flags)); + if (info->thd->killed == KILL_SLAVE_SAME_ID) + { + info->errmsg= "A slave with the same server_uuid/server_id as this slave " + "has connected to the master"; + info->error= ER_SLAVE_SAME_ID; + } + const bool binlog_open = my_b_inited(&log); if (file >= 0) { @@ -2921,7 +2928,8 @@ void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, thd->variables.max_allowed_packet= old_max_allowed_packet; delete info->fdev; - if (info->error == ER_MASTER_FATAL_ERROR_READING_BINLOG && binlog_open) + if ((info->error == ER_MASTER_FATAL_ERROR_READING_BINLOG || + info->error == ER_SLAVE_SAME_ID) && binlog_open) { /* detailing the fatal error message with coordinates @@ -3392,7 +3400,7 @@ void kill_zombie_dump_threads(uint32 slave_server_id) it will be slow because it will iterate through the list again. We just to do kill the thread ourselves. */ - tmp->awake(KILL_QUERY); + tmp->awake(KILL_SLAVE_SAME_ID); mysql_mutex_unlock(&tmp->LOCK_thd_data); } }