Skip to content

Commit 8c8b3ab

Browse files
committed
MDEV-34274: Test rpl.rpl_change_master_demote frequently fails on buildbot with "IO thread should not be running..."
The test rpl.rpl_change_master_demote used a `sleep 1` command to give time for a START SLAVE UNTIL to start the slave threads and wait for them to automatically die by UNTIL. On machines with heavy load (especially MSAN bb builders), one second was not enough, and the test would fail due to the IO thread still being up. This patch fixes the test by replacing the sleep with specific conditions to wait for. The test cannot wait for the IO or SQL threads to start, as it would be possible that they would be started and stopped by the time the MTR executor would check the slave status. So instead, we test for proof that they existed via the Connections status variable being incremented by at least 2 (Connections just shows the global thread id). At this point, we still can't use the wait_for_slave_to_stop helper, as the SQL/IO_Running fields of SHOW SLAVE STATUS may not be updated yet. So instead, we use information_schema.processlist, which would show the presence of the Slave_SQL/IO threads. So to "wait for the slave to stop", we wait for the Slave_SQL/IO threads to be gone from the processlist.
1 parent f9e717c commit 8c8b3ab

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

mysql-test/suite/rpl/r/rpl_change_master_demote.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,9 @@ START SLAVE UNTIL master_gtid_pos="ssu_middle_binlog_pos";
500500
Warnings:
501501
Note 1278 It is recommended to use --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you will get problems if you get an unexpected slave's mariadbd restart
502502
# Slave needs time to start and stop automatically
503+
# Waiting for both SQL and IO threads to have started..
504+
# Waiting for SQL thread to be killed..
505+
# Waiting for IO thread to be killed..
503506
# Validating neither SQL nor IO threads are running..
504507
# ..success
505508
# Clean slave state of master

mysql-test/suite/rpl/t/rpl_change_master_demote.test

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,27 @@ SELECT VARIABLE_NAME, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHER
276276
--echo # binlog position and should still succeed despite the SSU stop
277277
--echo # position pointing to a previous event (because
278278
--echo # master_demote_to_slave=1 merges gtid_binlog_pos into gtid_slave_pos).
279+
280+
--let $pre_start_slave_thread_count= query_get_value(SHOW STATUS LIKE 'Connections', Value, 1)
281+
279282
--replace_result $ssu_middle_binlog_pos ssu_middle_binlog_pos
280283
eval START SLAVE UNTIL master_gtid_pos="$ssu_middle_binlog_pos";
281284

282285
--echo # Slave needs time to start and stop automatically
283-
# Note sync_with_master_gtid.inc, wait_for_slave_to_start.inc, and
284-
# wait_for_slave_to_stop.inc won't work due to replication state and race
285-
# conditions
286-
--sleep 1
286+
--echo # Waiting for both SQL and IO threads to have started..
287+
--let $expected_cons_after_start_slave= `SELECT ($pre_start_slave_thread_count + 2)`
288+
--let $status_var= Connections
289+
--let $status_var_value= $expected_cons_after_start_slave
290+
--let $status_var_comparsion= >=
291+
--source include/wait_for_status_var.inc
292+
--let $status_var_comparsion=
293+
294+
--echo # Waiting for SQL thread to be killed..
295+
--let $wait_condition= SELECT count(*)=0 from information_schema.PROCESSLIST where COMMAND="Slave_SQL"
296+
--source include/wait_condition.inc
297+
--echo # Waiting for IO thread to be killed..
298+
--let $wait_condition= SELECT count(*)=0 from information_schema.PROCESSLIST where COMMAND="Slave_IO"
299+
--source include/wait_condition.inc
287300

288301
--echo # Validating neither SQL nor IO threads are running..
289302
--let $io_state= query_get_value("SHOW SLAVE STATUS", Slave_IO_State, 1)

0 commit comments

Comments
 (0)