Debian Codegraph @

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

raw
1 --source include/have_innodb.inc
2 --source include/have_log_bin.inc
3 --let $rpl_topology=1->2,1->3
4 --source include/rpl_init.inc
5 --connect (server_2b,127.0.0.1,root,,,$SERVER_MYPORT_2)
6
7 --connection server_2
8 SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
9 SET @old_parallel_mode= @@GLOBAL.slave_parallel_mode;
10 SET @old_timeout= @@GLOBAL.lock_wait_timeout;
11 SET @old_innodb_timeout= @@GLOBAL.innodb_lock_wait_timeout;
12 --source include/stop_slave.inc
13 SET GLOBAL slave_parallel_threads=5;
14 set global slave_parallel_mode= aggressive;
15 # High timeout so we get replication sync error and test failure if the
16 # conflict handling is insufficient and lock wait timeout occurs.
17 SET GLOBAL lock_wait_timeout= 86400;
18 SET GLOBAL innodb_lock_wait_timeout= 86400;
19 SET STATEMENT sql_log_bin=0 FOR ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
20 --source include/start_slave.inc
21
22 --connection server_1
23 CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
24 INSERT INTO t1 VALUES (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (6, 0), (7, 0), (8, 0);
25 --save_master_pos
26
27 --connection server_2
28 --sync_with_master
29 --source include/stop_slave.inc
30
31 # Test the following scenario:
32 #
33 # Transactions T1, T2 in domain 1, U1, U2 in domain 2.
34 # Wait cycle T1->U2->U1->T2->T1 as follows:
35 # T1 row lock wait on U2
36 # U2 wait_for_prior_commit on U1
37 # U1 row lock wait on T2
38 # T2 wait_for_prior_commit on T1
39 #
40 # Test that the wait cycle is broken correctly with deadlock kill.
41
42 --connection server_2b
43 # Temporarily block T1 and U1.
44 BEGIN;
45 SELECT * FROM t1 WHERE a=1 FOR UPDATE;
46 SELECT * FROM t1 WHERE a=5 FOR UPDATE;
47
48 --connection server_1
49
50 SET SESSION gtid_domain_id= 1;
51 # T1 in domain 1
52 BEGIN;
53 UPDATE t1 SET b=1 WHERE a=1;
54 UPDATE t1 SET b=1 WHERE a=7;
55 COMMIT;
56 # T2 in domain 1
57 UPDATE t1 SET b=2 WHERE a=3;
58
59 SET SESSION gtid_domain_id=2;
60 # U1 in domain 2
61 BEGIN;
62 UPDATE t1 SET b=3 WHERE a=5;
63 UPDATE t1 SET b=3 WHERE a=3;
64 COMMIT;
65 # U2 in domain 2
66 UPDATE t1 SET b=4 WHERE a=7;
67 SET SESSION gtid_domain_id= 0;
68 --source include/save_master_gtid.inc
69
70 --connection server_2
71 --source include/start_slave.inc
72 # Wait until T2, U2 are holding the row locks.
73 --let $wait_condition= SELECT COUNT(*)=2 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE state LIKE '%Waiting for prior transaction to commit%'
74 --source include/wait_condition.inc
75
76 # Then let T1, U1 continue to conflict on the row locks, and check that
77 # replication correctly handles the conflict.
78 --connection server_2b
79 ROLLBACK;
80
81 --connection server_2
82 --source include/sync_with_master_gtid.inc
83
84 # Allow either domain to "win" on the conflicting updates.
85 SELECT a, (
86 (a=1 AND b=1) OR
87 (a=3 AND (b=2 OR b=3)) OR
88 (a=5 AND b=3) OR
89 (a=7 AND (b=1 OR b=4)) OR
90 ((a MOD 2)=0 AND b=0)) AS `ok`
91 FROM t1
92 ORDER BY a;
93
94 # Now try the same thing with multi-source replication.
95
96 # Make server_3 a second master
97 --connection server_3
98 --source include/sync_with_master_gtid.inc
99 --source include/stop_slave.inc
100
101 --connection server_2
102 --source include/stop_slave.inc
103 --replace_result $SERVER_MYPORT_3 MYPORT_3
104 eval CHANGE MASTER 'm2' to master_port=$SERVER_MYPORT_3 , master_host='127.0.0.1', master_user='root', master_use_gtid=slave_pos, master_ssl_verify_server_cert=0;
105
106 --connection server_1
107
108 SET SESSION gtid_domain_id= 1;
109 # T1 in domain 1
110 BEGIN;
111 UPDATE t1 SET b=11 WHERE a=1;
112 UPDATE t1 SET b=11 WHERE a=7;
113 COMMIT;
114 # T2 in domain 1
115 UPDATE t1 SET b=12 WHERE a=3;
116 SET SESSION gtid_domain_id= 1;
117
118 --connection server_3
119 SET SESSION gtid_domain_id=3;
120 # U1 in domain 3
121 BEGIN;
122 UPDATE t1 SET b=13 WHERE a=5;
123 UPDATE t1 SET b=13 WHERE a=3;
124 COMMIT;
125 # U2 in domain 3
126 UPDATE t1 SET b=14 WHERE a=7;
127 --source include/save_master_gtid.inc
128
129 --connection server_2b
130 # Temporarily block T1 and U1.
131 BEGIN;
132 SELECT * FROM t1 WHERE a=1 FOR UPDATE;
133 SELECT * FROM t1 WHERE a=5 FOR UPDATE;
134
135 START ALL SLAVES;
136 # Wait until T2, U2 are holding the row locks.
137 --let $wait_condition= SELECT COUNT(*)=2 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE state LIKE '%Waiting for prior transaction to commit%'
138 --source include/wait_condition.inc
139
140 --connection server_2b
141 ROLLBACK;
142
143 --connection server_1
144 --source include/save_master_gtid.inc
145 --connection server_2
146 --source include/sync_with_master_gtid.inc
147 --connection server_3
148 --source include/save_master_gtid.inc
149 --connection server_2
150 --source include/sync_with_master_gtid.inc
151
152 SELECT a, (
153 (a=1 AND b=11) OR
154 (a=3 AND (b=12 OR b=13)) OR
155 (a=5 AND b=13) OR
156 (a=7 AND (b=11 OR b=14)) OR
157 ((a MOD 2)=0 AND b=0)) AS `ok`
158 FROM t1
159 ORDER BY a;
160
161 SET default_master_connection = 'm2';
162 --source include/stop_slave.inc
163 RESET SLAVE 'm2' ALL;
164 SET default_master_connection = '';
165
166 --connection server_3
167 --source include/start_slave.inc
168
169 # Cleanup
170
171 --disconnect server_2b
172 --connection server_1
173 DROP TABLE t1;
174 --connection server_2
175 --source include/stop_slave.inc
176 SET GLOBAL slave_parallel_threads=@old_parallel_threads;
177 set global slave_parallel_mode= @old_parallel_mode;
178 SET GLOBAL lock_wait_timeout= @old_timeout;
179 SET GLOBAL innodb_lock_wait_timeout= @old_innodb_timeout;
180 --source include/start_slave.inc
181
182 --source include/rpl_end.inc