| 1 |
--source include/master-slave.inc |
| 2 |
--source include/have_innodb.inc |
| 3 |
--source include/have_debug.inc |
| 4 |
--source include/have_binlog_format_statement.inc |
| 5 |
|
| 6 |
--disable_query_log |
| 7 |
call mtr.add_suppression("InnoDB: Transaction was aborted due to "); |
| 8 |
--enable_query_log |
| 9 |
|
| 10 |
--connection master |
| 11 |
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; |
| 12 |
CREATE TABLE t1(a INT) ENGINE=INNODB; |
| 13 |
INSERT INTO t1 VALUES(1); |
| 14 |
--source include/save_master_gtid.inc |
| 15 |
|
| 16 |
--connection slave |
| 17 |
--source include/sync_with_master_gtid.inc |
| 18 |
--source include/stop_slave.inc |
| 19 |
--let $save_transaction_retries= `SELECT @@global.slave_transaction_retries` |
| 20 |
--let $save_slave_parallel_threads= `SELECT @@global.slave_parallel_threads` |
| 21 |
--let $save_slave_parallel_mode= `SELECT @@global.slave_parallel_mode` |
| 22 |
set @@global.slave_parallel_threads= 2; |
| 23 |
set @@global.slave_parallel_mode= OPTIMISTIC; |
| 24 |
set @@global.slave_transaction_retries= 2; |
| 25 |
|
| 26 |
--echo *** MDEV-28776: rpl.rpl_mark_optimize_tbl_ddl fails with timeout on sync_with_master |
| 27 |
# This was a failure where a transaction T1 could deadlock multiple times |
| 28 |
# with T2, eventually exceeding the default --slave-transaction-retries=10. |
| 29 |
# Root cause was MDEV-31655, causing InnoDB to wrongly choose T1 as deadlock |
| 30 |
# victim over T2. If thread scheduling is right, it was possible for T1 to |
| 31 |
# repeatedly deadlock, roll back, and have time to grab an S lock again before |
| 32 |
# T2 woke up and got its waiting X lock, thus repeating the same deadlock over |
| 33 |
# and over. |
| 34 |
# Once the bug is fixed, it is not possible to re-create the same execution |
| 35 |
# and thread scheduling. Instead we inject small sleeps in a way that |
| 36 |
# triggered the problem when the bug was there, to demonstrate that the |
| 37 |
# problem no longer occurs. |
| 38 |
|
| 39 |
--connection master |
| 40 |
# T1 |
| 41 |
SET @@gtid_seq_no= 100; |
| 42 |
INSERT INTO t1 SELECT 1+a FROM t1; |
| 43 |
# T2 |
| 44 |
SET @@gtid_seq_no= 200; |
| 45 |
INSERT INTO t1 SELECT 2+a FROM t1; |
| 46 |
|
| 47 |
SELECT * FROM t1 ORDER BY a; |
| 48 |
--source include/save_master_gtid.inc |
| 49 |
|
| 50 |
--connection slave |
| 51 |
SET @save_dbug= @@GLOBAL.debug_dbug; |
| 52 |
|
| 53 |
# Inject various delays to hint thread scheduling to happen in the way that |
| 54 |
# triggered MDEV-28776. |
| 55 |
|
| 56 |
# Small delay starting T1 so it will be the youngest trx and be chosen over |
| 57 |
# T2 as the deadlock victim by default in InnoDB. |
| 58 |
SET GLOBAL debug_dbug="+d,rpl_parallel_delay_gtid_0_x_100_start"; |
| 59 |
|
| 60 |
# Small delay before taking insert X lock to give time for both T1 and T2 to |
| 61 |
# get the S lock first and cause a deadlock. |
| 62 |
SET GLOBAL debug_dbug="+d,rpl_write_record_small_sleep_gtid_100_200"; |
| 63 |
|
| 64 |
# Small delay after T2's wait on the X lock, to give time for T1 retry to |
| 65 |
# re-aquire the T1 S lock first. |
| 66 |
SET GLOBAL debug_dbug="+d,small_sleep_after_lock_wait"; |
| 67 |
|
| 68 |
# Delay deadlock kill of T2. |
| 69 |
SET GLOBAL debug_dbug="+d,rpl_delay_deadlock_kill"; |
| 70 |
|
| 71 |
--source include/start_slave.inc |
| 72 |
--source include/sync_with_master_gtid.inc |
| 73 |
SET GLOBAL debug_dbug= @save_dbug; |
| 74 |
SELECT * FROM t1 ORDER BY a; |
| 75 |
|
| 76 |
# Cleanup. |
| 77 |
--connection slave |
| 78 |
--source include/stop_slave.inc |
| 79 |
eval SET @@global.slave_parallel_threads= $save_slave_parallel_threads; |
| 80 |
eval SET @@global.slave_parallel_mode= $save_slave_parallel_mode; |
| 81 |
eval SET @@global.slave_transaction_retries= $save_transaction_retries; |
| 82 |
--source include/start_slave.inc |
| 83 |
|
| 84 |
--connection master |
| 85 |
DROP TABLE t1; |
| 86 |
|
| 87 |
--source include/rpl_end.inc |