| 1 |
--source include/have_innodb.inc |
| 2 |
--source include/master-slave.inc |
| 3 |
|
| 4 |
if ($check_mdev_38624) |
| 5 |
{ |
| 6 |
--source include/check_slave_skip_errors.inc |
| 7 |
} |
| 8 |
|
| 9 |
call mtr.add_suppression("Deadlock found when trying to get lock; try restarting transaction"); |
| 10 |
--disable_query_log |
| 11 |
call mtr.add_suppression("InnoDB: Transaction was aborted due to "); |
| 12 |
--enable_query_log |
| 13 |
|
| 14 |
--echo *** Provoke a deadlock on the slave, check that transaction retry succeeds. *** |
| 15 |
--connection master |
| 16 |
CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB; |
| 17 |
CREATE TABLE t2 (a INT) ENGINE=InnoDB; |
| 18 |
INSERT INTO t1(a) VALUES (1), (2), (3), (4), (5); |
| 19 |
|
| 20 |
--sync_slave_with_master |
| 21 |
SELECT * FROM t1 ORDER BY a; |
| 22 |
# Use MyISAM for t2 on the slave, so we have a way to see how far the |
| 23 |
# slave replication thread has proceeded in the transaction. |
| 24 |
SET sql_log_bin=0; |
| 25 |
ALTER TABLE t2 ENGINE=MyISAM; |
| 26 |
SET sql_log_bin=1; |
| 27 |
let $old_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', Value, 1); |
| 28 |
|
| 29 |
# Setup a separate connection that can deadlock with the replication thread. |
| 30 |
# Docs say that InnoDB will try to roll back the smaller transaction. So |
| 31 |
# let us make this transaction a big one, so the one in the replication |
| 32 |
# thread will be selected for rollback and retry. |
| 33 |
--connect (con_temp1,127.0.0.1,root,,test,$SERVER_MYPORT_2,) |
| 34 |
--connection con_temp1 |
| 35 |
BEGIN; |
| 36 |
UPDATE t1 SET b=2 WHERE a=4; |
| 37 |
--disable_query_log |
| 38 |
--let $count=200 |
| 39 |
while ($count) |
| 40 |
{ |
| 41 |
eval INSERT INTO t1(a) VALUES ($count + 10); |
| 42 |
dec $count; |
| 43 |
} |
| 44 |
--enable_query_log |
| 45 |
# Note that InnoDB also (undocumented?) tries to avoid rolling back a |
| 46 |
# "transaction" that modified non-transactional tables. So be sure to also |
| 47 |
# touch the MyISAM table in this transaction. |
| 48 |
INSERT INTO t2 VALUES (2); |
| 49 |
DELETE FROM t2 WHERE a=2; |
| 50 |
|
| 51 |
# Create the transaction that should participate in the deadlock on the slave. |
| 52 |
--connection master |
| 53 |
BEGIN; |
| 54 |
UPDATE t1 SET b=1 WHERE a=2; |
| 55 |
INSERT INTO t2 VALUES (1); |
| 56 |
UPDATE t1 SET b=1 WHERE a=4; |
| 57 |
COMMIT; |
| 58 |
--save_master_pos |
| 59 |
|
| 60 |
--connection slave |
| 61 |
# Wait until replication thread has gone to wait on the a=4 row lock. |
| 62 |
--let $wait_condition= SELECT COUNT(*) = 1 FROM t2 WHERE a=1 |
| 63 |
--source include/wait_condition.inc |
| 64 |
|
| 65 |
# Now provoke the deadlock by waiting on the a=2 row lock while the |
| 66 |
# other thread is waiting for our a=4 row lock. |
| 67 |
--connection con_temp1 |
| 68 |
UPDATE t1 SET b=2 WHERE a=2; |
| 69 |
SELECT * FROM t1 WHERE a<10 ORDER BY a; |
| 70 |
ROLLBACK; |
| 71 |
|
| 72 |
--connection slave |
| 73 |
--sync_with_master |
| 74 |
SELECT * FROM t1 ORDER BY a; |
| 75 |
if (!$ignored_db_deadlock) |
| 76 |
{ |
| 77 |
--echo * There will be two rows in t2 due to the retry. |
| 78 |
} |
| 79 |
if ($ignored_db_deadlock) |
| 80 |
{ |
| 81 |
--echo * There will be one row in t2 because the ignored deadlock does not retry. |
| 82 |
} |
| 83 |
SELECT * FROM t2 ORDER BY a; |
| 84 |
let $new_retry= query_get_value(SHOW STATUS LIKE 'Slave_retried_transactions', Value, 1); |
| 85 |
--disable_query_log |
| 86 |
eval SELECT $new_retry - $old_retry AS retries; |
| 87 |
--enable_query_log |
| 88 |
--let $status_items= Last_SQL_Errno, Last_SQL_Error |
| 89 |
--source include/show_slave_status.inc |
| 90 |
|
| 91 |
--connection master |
| 92 |
DROP TABLE t1; |
| 93 |
DROP TABLE t2; |
| 94 |
--source include/rpl_end.inc |