summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorKristian Nielsen <knielsen@knielsen-hq.org>2016-10-14 11:18:33 +0200
committerKristian Nielsen <knielsen@knielsen-hq.org>2016-10-14 23:15:59 +0200
commit814880711f0084f5cb1d8b1342b15ac819935742 (patch)
treecd2a4ca0f321c84efa28195d7ec8f6b7204d3795 /sql
parent851c401c0d2db3d02f5312989da8034e647fecb8 (diff)
downloadmariadb-git-814880711f0084f5cb1d8b1342b15ac819935742.tar.gz
BUG#56442: Slave executes delayed statements when STOP SLAVE is issued
Problem: When using the delayed slave feature, and the SQL thread is delaying, and the user issues STOP SLAVE, the event we wait for was executed. It should not be executed. Fix: Check the return value from the delay function, slave.cc:slave_sleep(). If the return value is 1, it means the thread has been stopped, in this case we don't execute the statement. Also, refactored the test case for delayed slave a little: added the test script include/rpl_assert.inc, which asserts that a condition holds and prints a message if not. Made rpl_delayed_slave.test use this. The advantage is that the test file is much easier to read and maintain, because it is clear what is an assertion and what is not, and also the expected result can be found in the test file, you don't have to compare it to the result file. Manually merged into MariaDB from MySQL commit fd2b210383358fe7697f201e19ac9779879ba72a Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
Diffstat (limited to 'sql')
-rw-r--r--sql/slave.cc20
1 files changed, 12 insertions, 8 deletions
diff --git a/sql/slave.cc b/sql/slave.cc
index 813827e883f..a927b7598c6 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -3410,17 +3410,21 @@ has_temporary_error(THD *thd)
/**
If this is a lagging slave (specified with CHANGE MASTER TO MASTER_DELAY = X), delays accordingly. Also unlocks rli->data_lock.
- Design note: this is the place to unlock rli->data_lock here since
- it should be held when reading delay info from rli, but it should
- not be held while sleeping.
+ Design note: this is the place to unlock rli->data_lock. The lock
+ must be held when reading delay info from rli, but it should not be
+ held while sleeping.
@param ev Event that is about to be executed.
@param thd The sql thread's THD object.
@param rli The sql thread's Relay_log_info structure.
+
+ @retval 0 If the delay timed out and the event shall be executed.
+
+ @retval nonzero If the delay was interrupted and the event shall be skipped.
*/
-static void sql_delay_event(Log_event *ev, THD *thd, rpl_group_info *rgi)
+static int sql_delay_event(Log_event *ev, THD *thd, rpl_group_info *rgi)
{
Relay_log_info* rli= rgi->rli;
long sql_delay= rli->get_sql_delay();
@@ -3459,14 +3463,13 @@ static void sql_delay_event(Log_event *ev, THD *thd, rpl_group_info *rgi)
nap_time));
rli->start_sql_delay(sql_delay_end);
mysql_mutex_unlock(&rli->data_lock);
- slave_sleep(thd, nap_time, sql_slave_killed, rgi);
- DBUG_VOID_RETURN;
+ DBUG_RETURN(slave_sleep(thd, nap_time, sql_slave_killed, rgi));
}
}
mysql_mutex_unlock(&rli->data_lock);
- DBUG_VOID_RETURN;
+ DBUG_RETURN(0);
}
@@ -3696,7 +3699,8 @@ apply_event_and_update_pos(Log_event* ev, THD* thd, rpl_group_info *rgi)
if (reason == Log_event::EVENT_SKIP_NOT)
{
// Sleeps if needed, and unlocks rli->data_lock.
- sql_delay_event(ev, thd, rgi);
+ if (sql_delay_event(ev, thd, rgi))
+ return 0;
}
else
mysql_mutex_unlock(&rli->data_lock);