summaryrefslogtreecommitdiff
path: root/sql/sql_repl.cc
diff options
context:
space:
mode:
authorSergey Vojtovich <svoj@mariadb.org>2019-03-07 08:12:26 +0400
committerAndrei Elkin <andrei.elkin@mariadb.com>2019-03-12 17:34:48 +0200
commit3568427d11f7afcd111b4c28c14cc8aba2b10807 (patch)
tree91102931e6813ca183d1f669b7e6da5725a3dce9 /sql/sql_repl.cc
parente4505279388e3c1e84937b6737bf5619a15a7d4c (diff)
downloadmariadb-git-3568427d11f7afcd111b4c28c14cc8aba2b10807.tar.gz
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.
Diffstat (limited to 'sql/sql_repl.cc')
-rw-r--r--sql/sql_repl.cc44
1 files changed, 34 insertions, 10 deletions
diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc
index 7fc3bb5926d..4c7a768b9ce 100644
--- a/sql/sql_repl.cc
+++ b/sql/sql_repl.cc
@@ -506,6 +506,22 @@ static enum enum_binlog_checksum_alg get_binlog_checksum_value_at_connect(THD *
DBUG_RETURN(ret);
}
+
+/**
+ Set current_linfo
+
+ Setting current_linfo needs to be done with LOCK_thd_data to ensure that
+ adjust_linfo_offsets doesn't use a structure that may be deleted.
+*/
+
+void THD::set_current_linfo(LOG_INFO *linfo)
+{
+ mysql_mutex_lock(&LOCK_thd_data);
+ current_linfo= linfo;
+ mysql_mutex_unlock(&LOCK_thd_data);
+}
+
+
/*
Adjust the position pointer in the binary log file for all running slaves
@@ -2125,9 +2141,8 @@ static int init_binlog_sender(binlog_send_info *info,
// set current pos too
linfo->pos= *pos;
-
// note: publish that we use file, before we open it
- thd->current_linfo= linfo;
+ thd->set_current_linfo(linfo);
if (check_start_offset(info, linfo->log_file_name, *pos))
return 1;
@@ -2365,14 +2380,15 @@ static int send_format_descriptor_event(binlog_send_info *info, IO_CACHE *log,
DBUG_RETURN(0);
}
-static bool should_stop(binlog_send_info *info)
+static bool should_stop(binlog_send_info *info, bool kill_server_check= false)
{
return
- info->net->error ||
- info->net->vio == NULL ||
- info->thd->killed ||
- info->error != 0 ||
- info->should_stop;
+ info->net->error ||
+ info->net->vio == NULL ||
+ (info->thd->killed &&
+ (info->thd->killed != KILL_SERVER || kill_server_check)) ||
+ info->error != 0 ||
+ info->should_stop;
}
/**
@@ -2393,7 +2409,7 @@ static int wait_new_events(binlog_send_info *info, /* in */
&stage_master_has_sent_all_binlog_to_slave,
&old_stage);
- while (!should_stop(info))
+ while (!should_stop(info, true))
{
*end_pos_ptr= mysql_bin_log.get_binlog_end_pos(binlog_end_pos_filename);
if (strcmp(linfo->log_file_name, binlog_end_pos_filename) != 0)
@@ -2745,6 +2761,14 @@ void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos,
info->error= ER_UNKNOWN_ERROR;
goto err;
}
+ DBUG_EXECUTE_IF("simulate_delay_at_shutdown",
+ {
+ const char act[]=
+ "now "
+ "WAIT_FOR greetings_from_kill_mysql";
+ DBUG_ASSERT(!debug_sync_set_action(thd,
+ STRING_WITH_LEN(act)));
+ };);
/*
heartbeat_period from @master_heartbeat_period user variable
@@ -3952,7 +3976,7 @@ bool mysql_show_binlog_events(THD* thd)
goto err;
}
- thd->current_linfo= &linfo;
+ thd->set_current_linfo(&linfo);
if ((file=open_binlog(&log, linfo.log_file_name, &errmsg)) < 0)
goto err;