Skip to content

Commit

Permalink
MDEV-10149: sys_vars.rpl_init_slave_func fails sporadically in buildbot
Browse files Browse the repository at this point in the history
problem:
========
mysqltest: In included file "./include/assert.inc":
included from mysql-test/suite/sys_vars/t/rpl_init_slave_func.test at line 69:
Assertion text: '@@global.max_connections = @start_max_connections'
Assertion result: '0'


mysqltest: In included file "./include/assert.inc":
included from mysql-test/suite/sys_vars/t/rpl_init_slave_func.test at line 86:
Assertion text: '@@global.max_connections = @start_max_connections + 1'
Assertion result: '0'

Analysis:
=========
A slave SQL thread sets its Running state to Yes very early in its
initialisation, before the majority of initialisation actions, including
executing the init_slave command, are done. Thus the testcase has a race
condition where the initial replication setup might finish executing later
than the testcase SET GLOBAL init_slave, making the testcase see its effect
where it checks for its absence.

Fix:
===
Include 'sync_slave_sql_with_master.inc' at the beginning of the test to
ensure that slave applier has completed the execution of 'init_slave' command
and proceeded to event application. Replace the apparently needless RESET
MASTER / RESET SLAVE etc.

Patch is based on:
percona/percona-server@b91e2e6
Author: laurynas-biveinis
  • Loading branch information
sujatha-s committed Oct 22, 2020
1 parent b4c225a commit 43ec937
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
15 changes: 4 additions & 11 deletions mysql-test/suite/sys_vars/r/rpl_init_slave_func.result
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include/master-slave.inc
[connection master]
connection slave
include/sync_slave_sql_with_master.inc
SET @start_max_connections= @@global.max_connections;
SET @start_init_slave= @@global.init_slave;
SET NAMES utf8;
Expand All @@ -19,18 +19,11 @@ SELECT @@global.init_slave = 'SET @@global.max_connections = @@global.max_connec
1
Expect 1
include/assert.inc [@@global.max_connections = @start_max_connections]
STOP SLAVE;
RESET MASTER;
RESET SLAVE;
START SLAVE;
include/wait_for_slave_to_start.inc
include/restart_slave.inc
include/sync_slave_sql_with_master.inc
include/assert.inc [@@global.max_connections = @start_max_connections + 1]
SET @@global.init_slave = "SET @a=5";
STOP SLAVE;
RESET MASTER;
RESET SLAVE;
START SLAVE;
include/wait_for_slave_to_start.inc
include/restart_slave.inc
SHOW VARIABLES LIKE 'init_slave';
Variable_name Value
init_slave SET @a=5
Expand Down
33 changes: 17 additions & 16 deletions mysql-test/suite/sys_vars/t/rpl_init_slave_func.test
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@
###############################################################################

source include/master-slave.inc;
--echo connection slave
connection slave;

# Since a part of slave SQL thread initialisation happens after Slave_SQL_Running
# has been set to Yes, there is a race condition between initialisation above and
# init_slave setting given below. Synchronise slave applier with master to ensure
# init_slave is complete and applier had processed few events like FD.
--source include/sync_slave_sql_with_master.inc

--disable_query_log
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
--enable_query_log
Expand Down Expand Up @@ -67,14 +72,15 @@ let $wait_condition= SELECT @@global.max_connections = @start_max_connections;
--let $assert_text= @@global.max_connections = @start_max_connections
--let $assert_cond= @@global.max_connections = @start_max_connections
--source include/assert.inc
#
# reset of the server
STOP SLAVE;
--wait_for_slave_to_stop
RESET MASTER;
RESET SLAVE;
START SLAVE;
source include/wait_for_slave_to_start.inc;

--source include/restart_slave_sql.inc

# Upon slave start, sync the applier with master, to ensure slave has
# completed init_slave command execution and processed FD event from the
# master.
--connection master
--source include/sync_slave_sql_with_master.inc

#
# wait for the slave threads have set the global variable.
let $wait_timeout= 90;
Expand All @@ -88,12 +94,7 @@ let $wait_condition= SELECT @@global.max_connections = @start_max_connections +
# Setting a variable(which is local to a session) and must not be visible
SET @@global.init_slave = "SET @a=5";
#
STOP SLAVE;
--wait_for_slave_to_stop
RESET MASTER;
RESET SLAVE;
START SLAVE;
source include/wait_for_slave_to_start.inc;
--source include/restart_slave_sql.inc
#
SHOW VARIABLES LIKE 'init_slave';
# expect NULL
Expand Down

0 comments on commit 43ec937

Please sign in to comment.