| 1 |
# |
| 2 |
# Verify that SHOW SLAVE STATUS will not cause deadlocks on the replica. |
| 3 |
# A deadlock has been seen in do_gco_wait if the thread is killed, as it will |
| 4 |
# hold the LOCK_parallel_entry, and during error reporting, try to grab the |
| 5 |
# err_lock. Prior to MDEV-10653, SHOW SLAVE STATUS would grab these locks in |
| 6 |
# the reverse order, as calling workers_idle() used to grab LOCK_parallel_entry |
| 7 |
# with the err_lock already grabbed (though the MDEV-10653 patch changed the |
| 8 |
# workles_idle() implementation to remove the need for locking the |
| 9 |
# parallel_entry). |
| 10 |
# |
| 11 |
# References: |
| 12 |
# MDEV-10653: SHOW SLAVE STATUS Can Deadlock an Errored Slave |
| 13 |
# |
| 14 |
|
| 15 |
--source include/master-slave.inc |
| 16 |
--source include/have_innodb.inc |
| 17 |
--source include/have_debug.inc |
| 18 |
--source include/have_binlog_format_row.inc |
| 19 |
|
| 20 |
--echo # |
| 21 |
--echo # Initialize test data |
| 22 |
--connection master |
| 23 |
create table t1 (a int) engine=innodb; |
| 24 |
insert into t1 values (1); |
| 25 |
--source include/save_master_gtid.inc |
| 26 |
|
| 27 |
--connection slave |
| 28 |
--source include/sync_with_master_gtid.inc |
| 29 |
--source include/stop_slave.inc |
| 30 |
|
| 31 |
call mtr.add_suppression("Connection was killed"); |
| 32 |
call mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends"); |
| 33 |
|
| 34 |
set @save_parallel_threads= @@global.slave_parallel_threads; |
| 35 |
set @save_parallel_mode= @@global.slave_parallel_mode; |
| 36 |
set @save_transaction_retries= @@global.slave_transaction_retries; |
| 37 |
set @save_innodb_lock_wait_timeout= @@global.innodb_lock_wait_timeout; |
| 38 |
|
| 39 |
set @@global.slave_parallel_threads= 2; |
| 40 |
set @@global.slave_parallel_mode= CONSERVATIVE; |
| 41 |
set @@global.slave_transaction_retries= 0; |
| 42 |
set @@global.innodb_lock_wait_timeout= 10; |
| 43 |
|
| 44 |
--echo # Grabbing lock on innodb row to force future replication transaction to wait (and eventually timeout) |
| 45 |
BEGIN; |
| 46 |
select * from t1 where a=1 for update; |
| 47 |
|
| 48 |
--connection master |
| 49 |
|
| 50 |
set @old_dbug= @@session.debug_dbug; |
| 51 |
set @@session.debug_dbug="+d,binlog_force_commit_id"; |
| 52 |
|
| 53 |
|
| 54 |
# GCO 1 |
| 55 |
SET @commit_id= 10000; |
| 56 |
# T1 |
| 57 |
update t1 set a=2 where a=1; |
| 58 |
|
| 59 |
# GCO 2 |
| 60 |
SET @commit_id= 10001; |
| 61 |
# T2 |
| 62 |
insert into t1 values (3); |
| 63 |
|
| 64 |
set @@session.debug_dbug= @old_dbug; |
| 65 |
|
| 66 |
--connection slave |
| 67 |
start slave; |
| 68 |
|
| 69 |
--echo # Waiting for first transaction to start (and be held at innodb row lock).. |
| 70 |
--let $wait_condition= SELECT count(*)=1 FROM information_schema.processlist WHERE state LIKE 'Update_rows_log_event::find_row(%)%' and command LIKE 'Slave_worker'; |
| 71 |
--source include/wait_condition.inc |
| 72 |
|
| 73 |
--echo # Waiting for next transaction to start and hold at do_gco_wait().. |
| 74 |
--let $wait_condition= SELECT count(*)=1 FROM information_schema.processlist WHERE state LIKE 'Waiting for prior transaction to start commit%' and command LIKE 'Slave_worker'; |
| 75 |
--source include/wait_condition.inc |
| 76 |
|
| 77 |
--connection slave1 |
| 78 |
set @@session.debug_dbug="+d,hold_sss_with_err_lock"; |
| 79 |
--send show slave status |
| 80 |
|
| 81 |
--connection slave |
| 82 |
set debug_sync="now wait_for sss_got_err_lock"; |
| 83 |
|
| 84 |
--let $t2_tid= `SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE LIKE 'Waiting for prior transaction to start commit%'` |
| 85 |
--replace_result $t2_tid "<TID of worker in do_gco_wait>" |
| 86 |
--eval kill $t2_tid |
| 87 |
--let $wait_condition= SELECT count(*)=1 FROM information_schema.processlist WHERE command LIKE 'Killed'; |
| 88 |
--source include/wait_condition.inc |
| 89 |
|
| 90 |
set debug_sync="now signal sss_continue"; |
| 91 |
|
| 92 |
--connection slave1 |
| 93 |
--echo # Waiting for SHOW SLAVE STATUS to complete.. |
| 94 |
--disable_result_log |
| 95 |
--reap |
| 96 |
--enable_result_log |
| 97 |
--echo # ..done |
| 98 |
|
| 99 |
--connection slave |
| 100 |
ROLLBACK; |
| 101 |
--let $slave_sql_errno= 1927 |
| 102 |
--source include/wait_for_slave_sql_error.inc |
| 103 |
|
| 104 |
|
| 105 |
--echo # |
| 106 |
--echo # Cleanup |
| 107 |
--connection master |
| 108 |
drop table t1; |
| 109 |
--source include/save_master_gtid.inc |
| 110 |
|
| 111 |
--connection slave |
| 112 |
set debug_sync= "RESET"; |
| 113 |
set @@global.slave_parallel_threads= @save_parallel_threads; |
| 114 |
set @@global.slave_parallel_mode= @save_parallel_mode; |
| 115 |
set @@global.slave_transaction_retries= @save_transaction_retries; |
| 116 |
set @@global.innodb_lock_wait_timeout= @save_innodb_lock_wait_timeout; |
| 117 |
start slave sql_thread; |
| 118 |
--source include/sync_with_master_gtid.inc |
| 119 |
|
| 120 |
--source include/rpl_end.inc |
| 121 |
--echo # End of rpl_deadlock_show_slave_status.test |