Debian Codegraph @

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

raw
1 # ==== Purpose ====
2 #
3 # This test will generate two XA transactions on the master in a way that
4 # they will block each other on the slave if the transaction isolation level
5 # used by the slave applier is more restrictive than the READ COMMITTED one.
6 #
7 # Consider:
8 # E=execute, P=prepare, C=commit;
9 # 1=first transaction, 2=second transaction;
10 #
11 # Master does: E1, E2, P2, P1, C1, C2
12 # Slave does: E2, P2, E1, P1, C1, C2
13 #
14 # The transactions are designed so that, if the applier transaction isolation
15 # level is more restrictive than the READ COMMITTED, E1 will be blocked on
16 # the slave waiting for gap locks to be released.
17 #
18 # Step 1
19 #
20 # The test will verify that the transactions don't block each other because
21 # the applier thread automatically changed the isolation level.
22 #
23 # Step 2
24 #
25 # The test will verify that applying master's binary log dump in slave doesn't
26 # block because mysqlbinlog is informing the isolation level to be used.
27 #
28 # ==== Related Bugs and Worklogs ====
29 #
30 # BUG#25040331: INTERLEAVED XA TRANSACTIONS MAY DEADLOCK SLAVE APPLIER WITH
31 # REPEATABLE READ
32 #
33 --source include/have_debug.inc
34 --source include/have_innodb.inc
35 # The test case only make sense for RBR
36 --source include/have_binlog_format_row.inc
37 --source include/master-slave.inc
38
39 --connection slave
40 # To hit the issue, we need to split the data in two pages.
41 # This global variable will help us.
42 SET @saved_innodb_limit_optimistic_insert_debug = @@GLOBAL.innodb_limit_optimistic_insert_debug;
43 SET @@GLOBAL.innodb_limit_optimistic_insert_debug = 2;
44
45 #
46 # Step 1 - Using async replication
47 #
48
49 # Let's generate the workload on the master
50 --connection master
51 CREATE TABLE t1 (
52 c1 INT NOT NULL,
53 KEY(c1)
54 ) ENGINE=InnoDB;
55
56 CREATE TABLE t2 (
57 c1 INT NOT NULL,
58 FOREIGN KEY(c1) REFERENCES t1(c1)
59 ) ENGINE=InnoDB;
60
61 INSERT INTO t1 VALUES (1), (3), (4);
62
63 --connection master1
64 XA START 'XA1';
65 INSERT INTO t1 values(2);
66 XA END 'XA1';
67
68 # This transaction will reference the gap where XA1
69 # was inserted, and will be prepared and committed
70 # before XA1, so the slave will prepare it (but will
71 # not commit it) before preparing XA1.
72 --connection master
73 XA START 'XA2';
74 INSERT INTO t2 values(3);
75 XA END 'XA2';
76
77 # The XA2 prepare should be binary logged first
78 XA PREPARE 'XA2';
79
80 # The XA1 prepare should be binary logged
81 # after XA2 prepare and before XA2 commit.
82 --connection master1
83 XA PREPARE 'XA1';
84
85 # The commit order doesn't matter much for the issue being tested.
86 XA COMMIT 'XA1';
87 --connection master
88 XA COMMIT 'XA2';
89
90 # Everything is fine if the slave can sync with the master.
91 --source include/sync_slave_sql_with_master.inc
92
93 #
94 # Step 2 - Using mysqlbinlog dump to restore the salve
95 #
96 --source include/stop_slave.inc
97 DROP TABLE t2, t1;
98 RESET SLAVE;
99 RESET MASTER;
100
101 --connection master
102 --let $master_data_dir= `SELECT @@datadir`
103 --let $master_log_file= query_get_value(SHOW MASTER STATUS, File, 1)
104 --let $mysql_server= $MYSQL --defaults-group-suffix=.2
105 --echo Restore binary log from the master into the slave
106 --exec $MYSQL_BINLOG --force-if-open $master_data_dir/$master_log_file | $mysql_server
107
108 --let $diff_tables= master:test.t1, slave:test.t1
109 --source include/diff_tables.inc
110 --let $diff_tables= master:test.t2, slave:test.t2
111 --source include/diff_tables.inc
112
113 #
114 # Cleanup
115 #
116 --let $master_file= query_get_value(SHOW MASTER STATUS, File, 1)
117 --let $master_pos= query_get_value(SHOW MASTER STATUS, Position, 1)
118 DROP TABLE t2, t1;
119
120 ## When GTID_MODE=OFF, we need to skip already applied transactions
121 --connection slave
122 #--let $gtid_mode= `SELECT @@GTID_MODE`
123 #if ($gtid_mode == OFF)
124 #{
125 # --disable_query_log
126 # --disable_result_log
127 # --eval CHANGE MASTER TO MASTER_LOG_FILE='$master_file', MASTER_LOG_POS=$master_pos
128 # --enable_result_log
129 # --enable_query_log
130 #}
131 --replace_result $master_file LOG_FILE $master_pos LOG_POS
132 --eval CHANGE MASTER TO MASTER_LOG_FILE='$master_file', MASTER_LOG_POS=$master_pos, MASTER_USE_GTID=NO
133
134 SET @@GLOBAL.innodb_limit_optimistic_insert_debug = @saved_innodb_limit_optimistic_insert_debug;
135 --source include/start_slave.inc
136
137 --source include/rpl_end.inc