| 1 |
# MDEV-6549, failing to update gtid_slave_pos for a transaction that was retried. |
| 2 |
|
| 3 |
# The problem was that when a transaction updates the mysql.gtid_slave_pos |
| 4 |
# table, it clears the flag that marks that there is a GTID position that |
| 5 |
# needs to be updated. Then, if the transaction got killed after that due |
| 6 |
# to a deadlock, the subsequent retry would fail to notice that the GTID needs |
| 7 |
# to be recorded in gtid_slave_pos. |
| 8 |
# |
| 9 |
# (In the original bug report, the symptom was an assertion; this was however |
| 10 |
# just a side effect of the missing update of gtid_slave_pos, which also |
| 11 |
# happened to cause a missing clear of OPTION_GTID_BEGIN). |
| 12 |
--source include/have_innodb.inc |
| 13 |
--source include/have_debug.inc |
| 14 |
--source include/have_debug_sync.inc |
| 15 |
# Must use statement-based binlogging. Otherwise the transaction will not be |
| 16 |
# binlogged at all, as it modifies no rows. |
| 17 |
--source include/have_binlog_format_statement.inc |
| 18 |
--source include/master-slave.inc |
| 19 |
|
| 20 |
--connection server_2 |
| 21 |
SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads; |
| 22 |
--source include/stop_slave.inc |
| 23 |
SET GLOBAL slave_parallel_threads=10; |
| 24 |
CHANGE MASTER TO master_use_gtid=slave_pos; |
| 25 |
--source include/start_slave.inc |
| 26 |
|
| 27 |
--connection server_1 |
| 28 |
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; |
| 29 |
CREATE TABLE t4 (a INT PRIMARY KEY, b INT, KEY b_idx(b)) ENGINE=InnoDB; |
| 30 |
INSERT INTO t4 VALUES (1,NULL), (2,2), (3,NULL), (4,4), (5, NULL), (6, 6); |
| 31 |
--connect (con1,127.0.0.1,root,,test,$SERVER_MYPORT_1,) |
| 32 |
--connect (con2,127.0.0.1,root,,test,$SERVER_MYPORT_1,) |
| 33 |
--save_master_pos |
| 34 |
|
| 35 |
--connection server_2 |
| 36 |
--sync_with_master |
| 37 |
--source include/stop_slave.inc |
| 38 |
|
| 39 |
# Create two transactions that can run in parallel on the slave but cause |
| 40 |
# a deadlock if the second runs before the first. |
| 41 |
--connection con1 |
| 42 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued1 WAIT_FOR master_cont1'; |
| 43 |
send UPDATE t4 SET b=NULL WHERE a=6; |
| 44 |
--connection server_1 |
| 45 |
SET debug_sync='now WAIT_FOR master_queued1'; |
| 46 |
|
| 47 |
--connection con2 |
| 48 |
SET debug_sync='commit_after_release_LOCK_prepare_ordered SIGNAL master_queued2'; |
| 49 |
send DELETE FROM t4 WHERE b <= 1; |
| 50 |
|
| 51 |
--connection server_1 |
| 52 |
SET debug_sync='now WAIT_FOR master_queued2'; |
| 53 |
SET debug_sync='now SIGNAL master_cont1'; |
| 54 |
|
| 55 |
--connection con1 |
| 56 |
REAP; |
| 57 |
--connection con2 |
| 58 |
REAP; |
| 59 |
SET debug_sync='RESET'; |
| 60 |
--save_master_pos |
| 61 |
--let $last_gtid= `SELECT @@last_gtid` |
| 62 |
|
| 63 |
--connection server_2 |
| 64 |
# Disable the usual skip of gap locks for transactions that are run in |
| 65 |
# parallel, using DBUG. This allows the deadlock to occur, and this in turn |
| 66 |
# triggers a retry of the second transaction, and the code that was buggy and |
| 67 |
# caused the gtid_slave_pos update to be skipped in the retry. |
| 68 |
SET @old_dbug= @@GLOBAL.debug_dbug; |
| 69 |
SET GLOBAL debug_dbug="+d,disable_thd_need_ordering_with"; |
| 70 |
--source include/start_slave.inc |
| 71 |
--sync_with_master |
| 72 |
SET GLOBAL debug_dbug=@old_dbug; |
| 73 |
|
| 74 |
SELECT * FROM t4 ORDER BY a; |
| 75 |
# Check that the GTID of the second transaction was correctly recorded in |
| 76 |
# gtid_slave_pos, in the variable as well as in the table. |
| 77 |
--replace_result $last_gtid GTID |
| 78 |
eval SET @last_gtid= '$last_gtid'; |
| 79 |
SELECT IF(@@gtid_slave_pos LIKE CONCAT('%',@last_gtid,'%'), "GTID found ok", |
| 80 |
CONCAT("GTID ", @last_gtid, " not found in gtid_slave_pos=", @@gtid_slave_pos)) |
| 81 |
AS result; |
| 82 |
SELECT "ROW FOUND" AS `Is the row found?` |
| 83 |
FROM mysql.gtid_slave_pos |
| 84 |
WHERE CONCAT(domain_id, "-", server_id, "-", seq_no) = @last_gtid; |
| 85 |
|
| 86 |
# Clean up. |
| 87 |
--connection server_2 |
| 88 |
--source include/stop_slave.inc |
| 89 |
SET GLOBAL slave_parallel_threads=@old_parallel_threads; |
| 90 |
--source include/start_slave.inc |
| 91 |
SET DEBUG_SYNC= 'RESET'; |
| 92 |
|
| 93 |
--connection server_1 |
| 94 |
DROP TABLE t4; |
| 95 |
SET DEBUG_SYNC= 'RESET'; |
| 96 |
--disconnect con1 |
| 97 |
--disconnect con2 |
| 98 |
--source include/rpl_end.inc |