From 3568427d11f7afcd111b4c28c14cc8aba2b10807 Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Thu, 7 Mar 2019 08:12:26 +0400 Subject: MDEV-18450 Slaves wait shutdown The patches features an optional shutdown behavior to hold on until after all connected slaves have been sent the last binlogged event. The connected slave is one whose START SLAVE has been acknowledged and that was not stopped since that though it could be technically reconnecting in background. The solution therefore disallows killing the dump thread until is has found EOF of the latest binlog file. It is up to the shutdown requester (DBA) to set up a sufficiently large shutdown timeout value for shudown to wait patiently until lagging behind slaves have been synchronized. On the other hand if a specific slave needs exclusion from synchronization the DBA would have to stop it manually which would terminate its dump thread. `mysqladmin shutdown' is extended with a `--wait_for_all_slaves' option which translates to `SHUTDOW WAIT FOR ALL SLAVES' sql query to enable the feature on the client side. The patch also performs a small refactoring of the server shutdown around close_connections() to introduce kill thread phases which are two as of current. --- sql/repl_failsafe.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'sql/repl_failsafe.cc') diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc index f13ff6c9163..e7873b185c5 100644 --- a/sql/repl_failsafe.cc +++ b/sql/repl_failsafe.cc @@ -147,11 +147,11 @@ int THD::register_slave(uchar *packet, size_t packet_length) if (!(si->master_id= uint4korr(p))) si->master_id= global_system_variables.server_id; - binlog_dump_thread_count++; unregister_slave(); mysql_mutex_lock(&LOCK_thd_data); slave_info= si; mysql_mutex_unlock(&LOCK_thd_data); + binlog_dump_thread_count++; return 0; err: @@ -161,6 +161,16 @@ err: } +bool THD::is_binlog_dump_thread() +{ + mysql_mutex_lock(&LOCK_thd_data); + bool res= slave_info != NULL; + mysql_mutex_unlock(&LOCK_thd_data); + + return res; +} + + static my_bool show_slave_hosts_callback(THD *thd, Protocol *protocol) { my_bool res= FALSE; -- cgit v1.2.1