Debian Codegraph @

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

raw
1 #
2 # This include file is used by more than one test suite
3 # (currently rpl and binlog_encryption).
4 # Please check all dependent tests after modifying it
5 #
6
7 source include/long_test.inc;
8 source include/not_embedded.inc;
9 source include/have_innodb.inc;
10 source include/master-slave.inc;
11
12 let $engine_type= InnoDB;
13
14 # Suppress warnings that might be generated during the test
15 connection master;
16 call mtr.add_suppression("Timeout waiting for reply of binlog");
17 call mtr.add_suppression("Read semi-sync reply");
18 call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.");
19 call mtr.add_suppression("mysqld: Got an error reading communication packets");
20 connection slave;
21 # While 'Current_Pos' exists as an option for Using_Gtd, keeping these
22 # events in the binlog will update gtid_binlog_pos, and the later calls to
23 # set `@@global.gtid_slave_pos= ""` will provide warning messages with
24 # inconsistent GTID values because the seq_nos are non-deterministic with
25 # the masters events coming in concurrently
26 set sql_log_bin=0;
27 call mtr.add_suppression("Semi-sync slave .* reply");
28 call mtr.add_suppression("Slave SQL.*Request to stop slave SQL Thread received while applying a group that has non-transactional changes; waiting for completion of the group");
29 set sql_log_bin=1;
30 connection master;
31
32 # wait for dying connections (if any) to disappear
33 let $wait_condition= select count(*) = 0 from information_schema.processlist where command='killed';
34 --source include/wait_condition.inc
35
36 # After fix of BUG#45848, semi-sync slave should not create any extra
37 # connections on master, save the count of connections before start
38 # semi-sync slave for comparison below.
39 let $_connections_normal_slave= query_get_value(SHOW STATUS LIKE 'Threads_connected', Value, 1);
40
41 --echo #
42 --echo # Uninstall semi-sync plugins on master and slave
43 --echo #
44 connection slave;
45 source include/stop_slave.inc;
46 --source include/reset_slave.inc
47 set global rpl_semi_sync_master_enabled= 0;
48 set global rpl_semi_sync_slave_enabled= 0;
49
50 connection master;
51 reset master;
52 set global rpl_semi_sync_master_enabled= 0;
53 set global rpl_semi_sync_slave_enabled= 0;
54
55 --echo #
56 --echo # Main test of semi-sync replication start here
57 --echo #
58
59 connection master;
60
61 set global rpl_semi_sync_master_timeout= 2000; # 2s
62
63 echo [ default state of semi-sync on master should be OFF ];
64 show variables like 'rpl_semi_sync_master_enabled';
65
66 echo [ enable semi-sync on master ];
67 set global rpl_semi_sync_master_enabled = 1;
68 show variables like 'rpl_semi_sync_master_enabled';
69
70 echo [ status of semi-sync on master should be ON even without any semi-sync slaves ];
71 show status like 'Rpl_semi_sync_master_clients';
72 show status like 'Rpl_semi_sync_master_status';
73 show status like 'Rpl_semi_sync_master_yes_tx';
74
75 --echo #
76 --echo # BUG#45672 Semisync repl: ActiveTranx:insert_tranx_node: transaction node allocation failed
77 --echo # BUG#45673 Semisynch reports correct operation even if no slave is connected
78 --echo #
79
80 # BUG#45672 When semi-sync is enabled on master, it would allocate
81 # transaction node even without semi-sync slave connected, and would
82 # finally result in transaction node allocation error.
83 #
84 # Semi-sync master will pre-allocate 'max_connections' transaction
85 # nodes, so here we do more than that much transactions to check if it
86 # will fail or not.
87 # select @@global.max_connections + 1;
88 let $i= `select @@global.max_connections + 1`;
89 disable_query_log;
90 eval create table t1 (a int) engine=$engine_type;
91 while ($i)
92 {
93 eval insert into t1 values ($i);
94 dec $i;
95 }
96 drop table t1;
97 enable_query_log;
98
99 # BUG#45673
100 echo [ status of semi-sync on master should be OFF ];
101 show status like 'Rpl_semi_sync_master_clients';
102 show status like 'Rpl_semi_sync_master_status';
103 show status like 'Rpl_semi_sync_master_yes_tx';
104
105 # reset master to make sure the following test will start with a clean environment
106 reset master;
107
108 connection slave;
109
110 echo [ default state of semi-sync on slave should be OFF ];
111 show variables like 'rpl_semi_sync_slave_enabled';
112
113 echo [ enable semi-sync on slave ];
114 set global rpl_semi_sync_slave_enabled = 1;
115 show variables like 'rpl_semi_sync_slave_enabled';
116 source include/start_slave.inc;
117
118 connection master;
119
120 # NOTE: Rpl_semi_sync_master_client will only be updated when
121 # semi-sync slave has started binlog dump request
122 let $status_var= Rpl_semi_sync_master_clients;
123 let $status_var_value= 1;
124 source include/wait_for_status_var.inc;
125
126 echo [ initial master state after the semi-sync slave connected ];
127 show status like 'Rpl_semi_sync_master_clients';
128 show status like 'Rpl_semi_sync_master_status';
129 show status like 'Rpl_semi_sync_master_no_tx';
130 show status like 'Rpl_semi_sync_master_yes_tx';
131
132 replace_result $engine_type ENGINE_TYPE;
133 eval create table t1(a int) engine = $engine_type;
134
135 echo [ master state after CREATE TABLE statement ];
136 show status like 'Rpl_semi_sync_master_status';
137 show status like 'Rpl_semi_sync_master_no_tx';
138 show status like 'Rpl_semi_sync_master_yes_tx';
139
140 # After fix of BUG#45848, semi-sync slave should not create any extra
141 # connections on master.
142 let $_connections_semisync_slave= query_get_value(SHOW STATUS LIKE 'Threads_connected', Value, 1);
143 replace_result $_connections_normal_slave CONNECTIONS_NORMAL_SLAVE $_connections_semisync_slave CONNECTIONS_SEMISYNC_SLAVE;
144 eval select $_connections_semisync_slave - $_connections_normal_slave as 'Should be 0';
145
146 echo [ insert records to table ];
147 insert t1 values (10);
148 insert t1 values (9);
149 insert t1 values (8);
150 insert t1 values (7);
151 insert t1 values (6);
152 insert t1 values (5);
153 insert t1 values (4);
154 insert t1 values (3);
155 insert t1 values (2);
156 insert t1 values (1);
157
158 echo [ master status after inserts ];
159 show status like 'Rpl_semi_sync_master_status';
160 show status like 'Rpl_semi_sync_master_no_tx';
161 show status like 'Rpl_semi_sync_master_yes_tx';
162
163 sync_slave_with_master;
164
165 echo [ slave status after replicated inserts ];
166 show status like 'Rpl_semi_sync_slave_status';
167
168 select count(distinct a) from t1;
169 select min(a) from t1;
170 select max(a) from t1;
171
172 --echo
173 --echo # BUG#50157
174 --echo # semi-sync replication crashes when replicating a transaction which
175 --echo # include 'CREATE TEMPORARY TABLE `MyISAM_t` SELECT * FROM `Innodb_t` ;
176
177 connection master;
178 SET SESSION AUTOCOMMIT= 0;
179 CREATE TABLE t2(c1 INT) ENGINE=innodb;
180 sync_slave_with_master;
181
182 connection master;
183 BEGIN;
184 --echo
185 --echo # Even though it is in a transaction, this statement is binlogged into binlog
186 --echo # file immediately.
187 --disable_warnings
188 CREATE TEMPORARY TABLE t3 SELECT c1 FROM t2 where 1=1;
189 --enable_warnings
190 --echo
191 --echo # These statements will not be binlogged until the transaction is committed
192 INSERT INTO t2 VALUES(11);
193 INSERT INTO t2 VALUES(22);
194 COMMIT;
195
196 DROP TABLE t2, t3;
197 SET SESSION AUTOCOMMIT= 1;
198 sync_slave_with_master;
199
200
201 --echo #
202 --echo # Test semi-sync master will switch OFF after one transaction
203 --echo # timeout waiting for slave reply.
204 --echo #
205
206 connection master;
207 show status like "Rpl_semi_sync_master_status";
208
209 connection slave;
210 source include/stop_slave.inc;
211
212 connection master;
213 --source include/kill_binlog_dump_threads.inc
214 set global rpl_semi_sync_master_timeout= 2000;
215
216 # The first semi-sync check should be on because after slave stop,
217 # there are no transactions on the master.
218 echo [ master status should be ON ];
219
220 let $status_var= Rpl_semi_sync_master_status;
221 let $status_var_value= ON;
222 source include/wait_for_status_var.inc;
223
224 let $status_var= Rpl_semi_sync_master_clients;
225 let $status_var_value= 0;
226 source include/wait_for_status_var.inc;
227
228 show status like 'Rpl_semi_sync_master_no_tx';
229 show status like 'Rpl_semi_sync_master_yes_tx';
230
231 echo [ semi-sync replication of these transactions will fail ];
232 insert into t1 values (500);
233
234 # Wait for the semi-sync replication of this transaction to timeout
235 let $status_var= Rpl_semi_sync_master_status;
236 let $status_var_value= OFF;
237 source include/wait_for_status_var.inc;
238
239 # The second semi-sync check should be off because one transaction
240 # times out during waiting.
241 echo [ master status should be OFF ];
242 show status like 'Rpl_semi_sync_master_status';
243 show status like 'Rpl_semi_sync_master_no_tx';
244 show status like 'Rpl_semi_sync_master_yes_tx';
245
246 # Semi-sync status on master is now ON, but there are no slaves attached,
247 # so all these transactions will be replicated asynchronously.
248 delete from t1 where a=10;
249 delete from t1 where a=9;
250 delete from t1 where a=8;
251 delete from t1 where a=7;
252 delete from t1 where a=6;
253 delete from t1 where a=5;
254 delete from t1 where a=4;
255 delete from t1 where a=3;
256 delete from t1 where a=2;
257 delete from t1 where a=1;
258
259 insert into t1 values (100);
260
261 echo [ master status should be OFF ];
262 show status like 'Rpl_semi_sync_master_status';
263 show status like 'Rpl_semi_sync_master_no_tx';
264 show status like 'Rpl_semi_sync_master_yes_tx';
265
266 --echo #
267 --echo # Test semi-sync status on master will be ON again when slave catches up
268 --echo #
269
270 # Save the master position for later use.
271 save_master_pos;
272
273 connection slave;
274
275 echo [ slave status should be OFF ];
276 show status like 'Rpl_semi_sync_slave_status';
277 source include/start_slave.inc;
278 sync_with_master;
279
280 echo [ slave status should be ON ];
281 show status like 'Rpl_semi_sync_slave_status';
282
283 select count(distinct a) from t1;
284 select min(a) from t1;
285 select max(a) from t1;
286
287 connection master;
288
289 # The master semi-sync status should be on again after slave catches up.
290 echo [ master status should be ON again after slave catches up ];
291
292 let $status_var= Rpl_semi_sync_master_status;
293 let $status_var_value= ON;
294 source include/wait_for_status_var.inc;
295 show status like 'Rpl_semi_sync_master_no_tx';
296 show status like 'Rpl_semi_sync_master_yes_tx';
297 show status like 'Rpl_semi_sync_master_clients';
298
299 --echo #
300 --echo # Test disable/enable master semi-sync on the fly.
301 --echo #
302
303 drop table t1;
304 sync_slave_with_master;
305
306 source include/stop_slave.inc;
307
308 --echo #
309 --echo # Flush status
310 --echo #
311 connection master;
312 echo [ Semi-sync master status variables before FLUSH STATUS ];
313 SHOW STATUS LIKE 'Rpl_semi_sync_master_no_tx';
314 SHOW STATUS LIKE 'Rpl_semi_sync_master_yes_tx';
315 # Do not write the FLUSH STATUS to binlog, to make sure we'll get a
316 # clean status after this.
317 FLUSH NO_WRITE_TO_BINLOG GLOBAL STATUS;
318 echo [ Semi-sync master status variables after FLUSH STATUS ];
319 SHOW STATUS LIKE 'Rpl_semi_sync_master_no_tx';
320 SHOW STATUS LIKE 'Rpl_semi_sync_master_yes_tx';
321
322 connection master;
323
324 source include/show_master_logs.inc;
325 show variables like 'rpl_semi_sync_master_enabled';
326
327 echo [ disable semi-sync on the fly ];
328 set global rpl_semi_sync_master_enabled=0;
329 show variables like 'rpl_semi_sync_master_enabled';
330 show status like 'Rpl_semi_sync_master_status';
331
332 echo [ enable semi-sync on the fly ];
333 set global rpl_semi_sync_master_enabled=1;
334 show variables like 'rpl_semi_sync_master_enabled';
335 show status like 'Rpl_semi_sync_master_status';
336
337 --echo #
338 --echo # Test RESET MASTER/SLAVE
339 --echo #
340
341 connection slave;
342
343 source include/start_slave.inc;
344
345 connection master;
346
347 replace_result $engine_type ENGINE_TYPE;
348 eval create table t1 (a int) engine = $engine_type;
349 drop table t1;
350
351 sync_slave_with_master;
352
353 echo [ test reset master ];
354 connection master;
355
356 reset master;
357
358 show status like 'Rpl_semi_sync_master_status';
359 show status like 'Rpl_semi_sync_master_no_tx';
360 show status like 'Rpl_semi_sync_master_yes_tx';
361
362 connection slave;
363
364 source include/stop_slave.inc;
365 --source include/reset_slave.inc
366
367 # Kill the dump thread on master for previous slave connection and
368 --source include/kill_binlog_dump_threads.inc
369
370 connection slave;
371 source include/start_slave.inc;
372
373 connection master;
374
375 # Wait for dump thread to start, Rpl_semi_sync_master_clients will be
376 # 1 after dump thread started.
377 let $status_var= Rpl_semi_sync_master_clients;
378 let $status_var_value= 1;
379 source include/wait_for_status_var.inc;
380
381 sync_slave_with_master;
382 connection master;
383
384 replace_result $engine_type ENGINE_TYPE;
385 eval create table t1 (a int) engine = $engine_type;
386 insert into t1 values (1);
387 insert into t1 values (2), (3);
388
389 sync_slave_with_master;
390
391 select * from t1;
392
393 connection master;
394
395 echo [ master semi-sync status should be ON ];
396 show status like 'Rpl_semi_sync_master_status';
397 show status like 'Rpl_semi_sync_master_no_tx';
398 show status like 'Rpl_semi_sync_master_yes_tx';
399
400 --echo #
401 --echo # Start semi-sync replication without SUPER privilege
402 --echo #
403 connection slave;
404 source include/stop_slave.inc;
405 --source include/reset_slave.inc
406 connection master;
407 reset master;
408
409 # Kill the dump thread on master for previous slave connection and wait for it to exit
410 --source include/kill_binlog_dump_threads.inc
411
412 # Do not binlog the following statement because it will generate
413 # different events for ROW and STATEMENT format
414 set sql_log_bin=0;
415 grant replication slave on *.* to [email protected] identified by 'rpl_password';
416 flush privileges;
417 set sql_log_bin=1;
418 connection slave;
419 grant replication slave on *.* to [email protected] identified by 'rpl_password';
420 flush privileges;
421 change master to master_user='rpl',master_password='rpl_password';
422 source include/start_slave.inc;
423 show status like 'Rpl_semi_sync_slave_status';
424 connection master;
425
426 # Wait for the semi-sync binlog dump thread to start
427 let $status_var= Rpl_semi_sync_master_clients;
428 let $status_var_value= 1;
429 source include/wait_for_status_var.inc;
430
431 sync_slave_with_master;
432 connection master;
433
434 echo [ master semi-sync should be ON ];
435 show status like 'Rpl_semi_sync_master_clients';
436 show status like 'Rpl_semi_sync_master_status';
437 show status like 'Rpl_semi_sync_master_no_tx';
438 show status like 'Rpl_semi_sync_master_yes_tx';
439 insert into t1 values (4);
440 insert into t1 values (5);
441 echo [ master semi-sync should be ON ];
442 show status like 'Rpl_semi_sync_master_clients';
443 show status like 'Rpl_semi_sync_master_status';
444 show status like 'Rpl_semi_sync_master_no_tx';
445 show status like 'Rpl_semi_sync_master_yes_tx';
446
447 --echo #
448 --echo # Test semi-sync slave connect to non-semi-sync master
449 --echo #
450
451 # Disable semi-sync on master
452 connection slave;
453 source include/stop_slave.inc;
454 SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
455
456 connection master;
457
458 # Kill the dump thread on master for previous slave connection and wait for it to exit
459 --source include/kill_binlog_dump_threads.inc
460
461 echo [ Semi-sync status on master should be ON ];
462 let $status_var= Rpl_semi_sync_master_clients;
463 let $status_var_value= 0;
464 source include/wait_for_status_var.inc;
465 show status like 'Rpl_semi_sync_master_status';
466 let $status_var= Rpl_semi_sync_master_status;
467 let $status_var_value= ON;
468 source include/wait_for_status_var.inc;
469 set global rpl_semi_sync_master_enabled= 0;
470
471 connection slave;
472 SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
473 source include/start_slave.inc;
474 connection master;
475 insert into t1 values (8);
476 let $status_var= Rpl_semi_sync_master_clients;
477 let $status_var_value= 1;
478 source include/wait_for_status_var.inc;
479 echo [ master semi-sync clients should be 1, status should be OFF ];
480 show status like 'Rpl_semi_sync_master_clients';
481 show status like 'Rpl_semi_sync_master_status';
482 sync_slave_with_master;
483 show status like 'Rpl_semi_sync_slave_status';
484
485 # Uninstall semi-sync plugin on master
486 connection slave;
487 source include/stop_slave.inc;
488 connection master;
489 set global rpl_semi_sync_master_enabled= 0;
490
491 connection slave;
492 SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
493 source include/start_slave.inc;
494
495 connection master;
496 insert into t1 values (10);
497 sync_slave_with_master;
498
499 --echo #
500 --echo # Test non-semi-sync slave connect to semi-sync master
501 --echo #
502
503 connection master;
504 set global rpl_semi_sync_master_timeout= 5000; # 5s
505 set global rpl_semi_sync_master_enabled= 1;
506
507 connection slave;
508 source include/stop_slave.inc;
509 SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
510
511 echo [ uninstall semi-sync slave plugin ];
512 set global rpl_semi_sync_slave_enabled= 0;
513
514 echo [ reinstall semi-sync slave plugin and disable semi-sync ];
515 SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
516 SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
517 source include/start_slave.inc;
518 SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
519
520 --echo #
521 --echo # Clean up
522 --echo #
523
524 connection slave;
525 source include/stop_slave.inc;
526 set global rpl_semi_sync_slave_enabled= 0;
527
528 connection master;
529 set global rpl_semi_sync_master_enabled= 0;
530
531 connection slave;
532 change master to master_user='root',master_password='';
533 source include/start_slave.inc;
534
535 connection master;
536 drop table t1;
537 sync_slave_with_master;
538
539 connection master;
540 drop user [email protected];
541 flush privileges;
542 set global rpl_semi_sync_master_timeout= default;
543 --source include/rpl_end.inc