Debian Codegraph @

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

raw
1 --source include/have_debug.inc
2 --source include/have_innodb.inc
3 --source include/have_binlog_format_statement.inc
4 --let $rpl_topology=1->2
5 --source include/rpl_init.inc
6
7 --echo *** MDEV-5509: Incorrect value for Seconds_Behind_Master if parallel replication ***
8
9 --connection server_2
10 SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
11 set @old_parallel_mode= @@GLOBAL.slave_parallel_mode;
12 --source include/stop_slave.inc
13 SET GLOBAL slave_parallel_threads=5;
14 set global slave_parallel_mode= optimistic;
15 --source include/start_slave.inc
16
17 --connection server_1
18 CREATE TABLE t1 (a INT PRIMARY KEY, b INT);
19 CALL mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave");
20 --save_master_pos
21
22 --connection server_2
23 --sync_with_master
24
25 --connection server_1
26 INSERT INTO t1 VALUES (1,sleep(2));
27 --save_master_pos
28
29 --connection server_2
30 --sync_with_master
31
32 # The slave position (which --sync_with_master waits for) is updated just
33 # before the Seconds_Behind_Master. So we have to wait for the zero status
34 # to appear, otherwise there is a small window between --sync_with_master
35 # and SHOW SLAVE STATUS where we can see a non-zero value.
36 --let $slave_param= Seconds_Behind_Master
37 --let $slave_param_value= 0
38 --source include/wait_for_slave_param.inc
39 --echo Seconds_Behind_Master should be zero here because the slave is fully caught up and idle.
40 --let $status_items= Seconds_Behind_Master
41 --source include/show_slave_status.inc
42
43
44 --echo *** MDEV-8294: Inconsistent behavior of slave parallel threads at runtime ***
45
46 --connection server_1
47 INSERT INTO t1 VALUES (10,0);
48 # Force a duplicate key error on the slave.
49 SET sql_log_bin= 0;
50 DELETE FROM t1 WHERE a=10;
51 SET sql_log_bin= 1;
52 INSERT INTO t1 VALUES (10,0);
53 --save_master_pos
54 SELECT * FROM t1 WHERE a >= 10 ORDER BY a;
55
56 --connection server_2
57 --let $slave_sql_errno= 1062
58 --source include/wait_for_slave_sql_error.inc
59
60 # At this point, the worker threads should have stopped also.
61 --let $wait_condition= SELECT COUNT(*)=0 FROM information_schema.processlist WHERE User = "system user" AND State = "Waiting for work from SQL thread";
62 --source include/wait_condition.inc
63
64 # Check that the pool can still be resized, but remains inactive as no slave
65 # SQL thread is running.
66 SET GLOBAL slave_parallel_threads=8;
67 --let $wait_condition= SELECT COUNT(*)=0 FROM information_schema.processlist WHERE User = "system user" AND State = "Waiting for work from SQL thread";
68 --source include/wait_condition.inc
69
70 STOP SLAVE;
71 # At this point, the worker threads should have stopped.
72 --let $wait_condition= SELECT COUNT(*)=0 FROM information_schema.processlist WHERE User = "system user" AND State = "Waiting for work from SQL thread";
73 --source include/wait_condition.inc
74
75
76 SET GLOBAL sql_slave_skip_counter= 1;
77 --source include/start_slave.inc
78 # At this point, the worker threads should have been spawned.
79 --let $wait_condition= SELECT COUNT(*)=8 FROM information_schema.processlist WHERE User = "system user" AND State = "Waiting for work from SQL thread";
80 --source include/wait_condition.inc
81 --sync_with_master
82 SELECT * FROM t1 WHERE a >= 10 ORDER BY a;
83
84
85 --echo *** MDEV-7818: Deadlock occurring with parallel replication and FTWRL ***
86
87 --connection server_1
88 CREATE TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
89 INSERT INTO t2 VALUES (1,0), (2,0), (3,0);
90 --save_master_pos
91
92 --connection server_2
93 --sync_with_master
94 --source include/stop_slave.inc
95
96 --connection server_1
97 # Create a group commit with two transactions, will be used to provoke the
98 # problematic thread interaction with FTWRL on the slave.
99 SET @old_dbug= @@SESSION.debug_dbug;
100 SET @commit_id= 4242;
101 SET SESSION debug_dbug="+d,binlog_force_commit_id";
102
103 BEGIN;
104 UPDATE t2 SET b=b+1 WHERE a=2;
105 COMMIT;
106
107 BEGIN;
108 INSERT INTO t2 VALUES (4,10);
109 COMMIT;
110
111 SET SESSION debug_dbug= @old_dbug;
112
113 INSERT INTO t2 VALUES (5,0);
114 INSERT INTO t2 VALUES (6,0);
115 INSERT INTO t2 VALUES (7,0);
116 INSERT INTO t2 VALUES (8,0);
117 INSERT INTO t2 VALUES (9,0);
118 INSERT INTO t2 VALUES (10,0);
119 INSERT INTO t2 VALUES (11,0);
120 INSERT INTO t2 VALUES (12,0);
121 INSERT INTO t2 VALUES (13,0);
122 INSERT INTO t2 VALUES (14,0);
123 INSERT INTO t2 VALUES (15,0);
124 INSERT INTO t2 VALUES (16,0);
125 INSERT INTO t2 VALUES (17,0);
126 INSERT INTO t2 VALUES (18,0);
127 INSERT INTO t2 VALUES (19,0);
128 --save_master_pos
129
130 --connection server_2
131
132 --connect (s1, 127.0.0.1, root,, test, $SLAVE_MYPORT,)
133 # Block one transaction on a row lock.
134 BEGIN;
135 SELECT * FROM t2 WHERE a=2 FOR UPDATE;
136
137 --connection server_2
138
139 # Wait for slave thread of the other transaction to have the commit lock.
140 --source include/start_slave.inc
141 --let $wait_condition= SELECT COUNT(*) > 0 FROM information_schema.processlist WHERE state = "Waiting for prior transaction to commit"
142 --source include/wait_condition.inc
143
144 --connect (s2, 127.0.0.1, root,, test, $SLAVE_MYPORT,)
145 send FLUSH TABLES WITH READ LOCK;
146 # The bug was that at this point we were deadlocked.
147 # The FTWRL command would wait forever for T2 to commit.
148 # T2 would wait for T1 to commit first, but T1 is waiting for
149 # the global read lock to be released.
150
151 --connection s1
152 # Release the lock that blocs T1 from replicating.
153 COMMIT;
154
155 --connection s1
156 send STOP SLAVE;
157
158 --connection s2
159 reap;
160
161 --connection server_1
162 SELECT * FROM t2 ORDER BY a;
163
164 --connection s2
165 UNLOCK TABLES;
166
167 SELECT "after UNLOCK TABLES" as state;
168
169 --connection s1
170 reap;
171
172 SELECT "after reap of STOP SLAVE" as state;
173
174 --connection server_2
175 --source include/wait_for_slave_to_stop.inc
176 --source include/start_slave.inc
177 --sync_with_master
178
179 SELECT * FROM t2 ORDER BY a;
180
181
182
183 --echo *** MDEV-8318: Assertion `!pool->busy' failed in pool_mark_busy(rpl_parallel_thread_pool*) on concurrent FTWRL ***
184
185 --connection server_1
186 LOCK TABLE t2 WRITE;
187
188
189 --connect (m1,localhost,root,,test)
190 --connection m1
191 --let $cid=`SELECT CONNECTION_ID()`
192 send FLUSH TABLES WITH READ LOCK;
193
194 --connect (m2,localhost,root,,test)
195 # We cannot force the race with DEBUG_SYNC, because the race does not
196 # exist after fixing the bug. At best we could force a debug sync to
197 # time out, which is effectively just a sleep.
198 # So just put a small sleep here; it is enough to trigger the bug in
199 # most run before the bug fix, and the code should work correctly
200 # however the thread scheduling happens.
201 --sleep 0.1
202 send FLUSH TABLES WITH READ LOCK;
203
204 --connection server_1
205 --replace_result $cid CID
206 eval KILL QUERY $cid;
207
208 --connection m1
209 --error ER_QUERY_INTERRUPTED
210 reap;
211
212 --connection server_1
213 UNLOCK TABLES;
214
215 --connection m2
216 reap;
217 UNLOCK TABLES;
218
219
220 # Clean up.
221 --connection server_2
222 --source include/stop_slave.inc
223 SET GLOBAL slave_parallel_threads=@old_parallel_threads;
224 set global slave_parallel_mode= @old_parallel_mode;
225 --source include/start_slave.inc
226
227 --connection server_1
228 DROP TABLE t1, t2;
229
230 --source include/rpl_end.inc