summaryrefslogtreecommitdiffstats
path: root/mysql-test/suite/rpl/t/rpl_gtid_crash.test
blob: 283298318bef79a02781a864890f0bcd30c3c208 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
--source include/have_innodb.inc
--source include/have_debug.inc
# Valgrind does not work well with test that crashes the server
--source include/not_valgrind.inc

--let $rpl_topology=1->2
--source include/rpl_init.inc

--echo *** Test crashing master, causing slave IO thread to reconnect while SQL thread is running ***

--connection server_1
call mtr.add_suppression("Checking table:");
call mtr.add_suppression("client is using or hasn't closed the table properly");
call mtr.add_suppression("Table .* is marked as crashed and should be repaired");
flush tables;

ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1, 0);
--save_master_pos

--connection server_2
--sync_with_master
SET sql_log_bin=0;
call mtr.add_suppression('Master command COM_REGISTER_SLAVE failed: failed registering on master, reconnecting to try again');
SET sql_log_bin=1;
--source include/stop_slave.inc
--replace_result $MASTER_MYPORT MASTER_PORT
eval CHANGE MASTER TO master_host = '127.0.0.1', master_port = $MASTER_MYPORT,
     MASTER_USE_GTID=SLAVE_POS;

--connection server_1
INSERT INTO t1 VALUES (2,1);
INSERT INTO t1 VALUES (3,1);

--connection server_2
--source include/start_slave.inc

--connection server_1

--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
wait-rpl_gtid_crash.test
EOF

let $1=200;
--disable_query_log
while ($1)
{
  eval INSERT INTO t1 VALUES ($1 + 10, 2);
  dec $1;
}
--enable_query_log
--source include/save_master_gtid.inc

SET SESSION debug_dbug="+d,crash_dispatch_command_before";
--error 2006,2013
SELECT 1;
--source include/wait_until_disconnected.inc

--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart-rpl_gtid_crash.test
EOF

--enable_reconnect
--source include/wait_until_connected_again.inc

--connection server_2
--source include/sync_with_master_gtid.inc

--connection server_1
INSERT INTO t1 VALUES (1000, 3);
--source include/save_master_gtid.inc

--connection server_2
--source include/sync_with_master_gtid.inc

--connection server_1
DROP TABLE t1;
--save_master_pos

--echo *** Test crashing the master mysqld and check that binlog state is recovered. ***
--connection server_2
--sync_with_master
--source include/stop_slave.inc
RESET MASTER;
SET GLOBAL gtid_slave_pos='';

--connection server_1
RESET MASTER;
--replace_column 2 # 4 # 5 #
SHOW BINLOG EVENTS IN 'master-bin.000001' LIMIT 1,1;
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;

--connection server_2
--source include/start_slave.inc

--connection server_1
SET gtid_domain_id= 1;
INSERT INTO t1 VALUES (1);
INSERT INTO t1 VALUES (2);
FLUSH LOGS;
SET gtid_domain_id= 2;
INSERT INTO t1 VALUES (3);
FLUSH LOGS;
--source include/show_binary_logs.inc
--replace_column 2 # 4 # 5 # 6 #
SHOW BINLOG EVENTS IN 'master-bin.000003' LIMIT 1,1;

--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
wait
EOF

SET SESSION debug_dbug="+d,crash_dispatch_command_before";
--error 2006,2013
SELECT 1;
--source include/wait_until_disconnected.inc

--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart
EOF

--enable_reconnect
--source include/wait_until_connected_again.inc

--source include/show_binary_logs.inc
--replace_column 2 # 4 # 5 # 6 #
SHOW BINLOG EVENTS IN 'master-bin.000004' LIMIT 1,1;
--save_master_pos

--connection server_2
--sync_with_master
SELECT * FROM t1 ORDER BY a;


--echo *** Test crashing slave at various points and check that it recovers crash-safe. ***

# Crash the slave just before updating mysql.gtid_slave_pos table.
--source include/stop_slave.inc
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
wait
EOF
# We do not have to save @@GLOBAL.debug_dbug, it is reset when slave crashes.
SET GLOBAL debug_dbug="+d,inject_crash_before_write_rpl_slave_state";
START SLAVE;

--connection server_1
INSERT INTO t1 VALUES (4);
--source include/save_master_gtid.inc

--connection server_2
--source include/wait_until_disconnected.inc

--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
restart: --skip-slave-start=0
EOF

--enable_reconnect
--source include/wait_until_connected_again.inc

--source include/sync_with_master_gtid.inc

# Crash the slave just before committing.
--source include/stop_slave.inc
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
wait
EOF
START SLAVE;
--error 0,2006,2013
SET GLOBAL debug_dbug="+d,crash_commit_before";

--connection server_1
INSERT INTO t1 VALUES (5);
--source include/save_master_gtid.inc

--connection server_2
--source include/wait_until_disconnected.inc

--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
restart: --skip-slave-start=0
EOF

--enable_reconnect
--source include/wait_until_connected_again.inc

--source include/sync_with_master_gtid.inc

# Crash the slave just after committing.
--source include/stop_slave.inc
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
wait
EOF
START SLAVE;
--error 0,2006,2013
SET GLOBAL debug_dbug="+d,crash_commit_after";

--connection server_1
INSERT INTO t1 VALUES (6);
--source include/save_master_gtid.inc

--connection server_2
--source include/wait_until_disconnected.inc

--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
restart: --skip-slave-start=0
EOF

--enable_reconnect
--source include/wait_until_connected_again.inc

--source include/sync_with_master_gtid.inc

# Crash the slave just before updating relay-log.info
--source include/stop_slave.inc
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
wait
EOF
SET GLOBAL debug_dbug="+d,inject_crash_before_flush_rli";
--error 0,2006,2013
START SLAVE;

--connection server_1
INSERT INTO t1 VALUES (7);
--source include/save_master_gtid.inc

--connection server_2
--source include/wait_until_disconnected.inc

--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
restart: --skip-slave-start=0
EOF

--enable_reconnect
--source include/wait_until_connected_again.inc

--source include/sync_with_master_gtid.inc

# Crash the slave just after updating relay-log.info
--source include/stop_slave.inc
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
wait
EOF
SET GLOBAL debug_dbug="+d,inject_crash_after_flush_rli";
--error 0,2006,2013
START SLAVE;

--connection server_1
INSERT INTO t1 VALUES (8);
--source include/save_master_gtid.inc

--connection server_2
--source include/wait_until_disconnected.inc

--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
restart: --skip-slave-start=0
EOF

--enable_reconnect
--source include/wait_until_connected_again.inc

--source include/sync_with_master_gtid.inc


# Check that everything was replicated correctly.
SELECT * FROM t1 ORDER BY a;


--echo *** MDEV-4725: Incorrect recovery when crash in the middle of writing an event group ***

--connection server_2
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
wait
EOF

--let $old_gtid_strict= `SELECT @@gtid_strict_mode`
SET GLOBAL debug_dbug="+d,crash_before_writing_xid";

--connection server_1
INSERT INTO t1 VALUES (9), (10);
--let $saved_gtid=`SELECT @@last_gtid`
--save_master_pos

--connection server_2
--source include/wait_until_disconnected.inc

# The bug was that during crash recovery we would update the binlog state
# with the GTID of the half-written event group at the end of the slaves
# binlog, even though this event group was not committed.
# We restart the server with gtid_strict_mode; this way, we get an error
# about duplicate gtid when the slave re-executes the event group, if the
# binlog crash recovery is incorrect.
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
restart: --gtid_strict_mode=1
EOF

--enable_reconnect
--source include/wait_until_connected_again.inc

SHOW VARIABLES like 'gtid_strict_mode';
--source include/start_slave.inc
--sync_with_master
--disable_query_log
eval SET GLOBAL gtid_strict_mode= $old_gtid_strict;
--enable_query_log


--echo *** MDEV-6462: Incorrect recovery on a slave reconnecting to crashed master ***

--connection server_1
set sql_log_bin= 0;
call mtr.add_suppression("Error writing file 'master-bin'");
set sql_log_bin= 1;
--connection server_2
set sql_log_bin= 0;
call mtr.add_suppression("The server_id of master server changed in the middle of GTID");
call mtr.add_suppression("Unexpected change of master binlog file name in the middle of GTID");
set sql_log_bin= 1;

--connection server_1
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
wait
EOF

SET GLOBAL debug_dbug="+d,inject_error_writing_xid";
BEGIN;
INSERT INTO t1 VALUES (11);
--error ER_ERROR_ON_WRITE
COMMIT;
SET GLOBAL debug_dbug="+d,crash_dispatch_command_before";
--error 2006,2013
COMMIT;

--source include/wait_until_disconnected.inc

# Simulate that we reconnect to a different server (new server_id).
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart: --server-id=3
EOF

--enable_reconnect
--source include/wait_until_connected_again.inc

SELECT @@GLOBAL.server_id;
SELECT * from t1 WHERE a > 10 ORDER BY a;
--disable_query_log
eval SELECT IF(INSTR(@@gtid_binlog_pos, '$saved_gtid'), "Binlog pos ok", CONCAT("Unexpected binlog pos: ", @@gtid_binlog_pos, "; does not contain the GTID $saved_gtid.")) AS gtid_check;
--enable_query_log

--echo # Wait 60 seconds for SQL thread to catch up with IO thread
--connection server_2
--let $wait_timeout= 600
while ($wait_timeout != 0)
{
  --let $read_log_pos= query_get_value('SHOW SLAVE STATUS', Read_Master_Log_Pos, 1)
  --let $exec_log_pos= query_get_value('SHOW SLAVE STATUS', Exec_Master_Log_Pos, 1)
  if ($read_log_pos == $exec_log_pos)
  {
    --let $wait_timeout= 0
  }
  if ($read_log_pos != $exec_log_pos)
  {
    --sleep 0.1
    --dec $wait_timeout
  }
}
if ($read_log_pos != $exec_log_pos)
{
  --die Timeout wait for SQL thread to catch up with IO thread
}

SELECT * from t1 WHERE a > 10 ORDER BY a;
--disable_query_log
eval SELECT IF(INSTR(@@gtid_binlog_pos, '$saved_gtid'), "Binlog pos ok", CONCAT("Unexpected binlog pos: ", @@gtid_binlog_pos, "; does not contain the GTID $saved_gtid.")) AS gtid_check;
eval SELECT IF(INSTR(@@gtid_slave_pos, '$saved_gtid'), "Slave pos ok", CONCAT("Unexpected slave pos: ", @@gtid_slave_pos, "; does not contain the GTID $saved_gtid.")) AS gtid_check;
eval SELECT IF(INSTR(@@gtid_current_pos, '$saved_gtid'), "Current pos ok", CONCAT("Unexpected current pos: ", @@gtid_current_pos, "; does not contain the GTID $saved_gtid.")) AS gtid_check;
--enable_query_log

--echo # Repeat this with additional transactions on the master

--connection server_1
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
wait
EOF

SET GLOBAL debug_dbug="+d,inject_error_writing_xid";
BEGIN;
INSERT INTO t1 VALUES (12);
--error ER_ERROR_ON_WRITE
COMMIT;
SET GLOBAL debug_dbug="+d,crash_dispatch_command_before";
--error 2006,2013
COMMIT;

--source include/wait_until_disconnected.inc

# Simulate that we reconnect to a different server (new server_id).
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart: --server-id=1
EOF

--enable_reconnect
--source include/wait_until_connected_again.inc

SELECT @@GLOBAL.server_id;
INSERT INTO t1 VALUES (13);
INSERT INTO t1 VALUES (14);
--let $saved_gtid=`SELECT @@last_gtid`
SELECT * from t1 WHERE a > 10 ORDER BY a;
--source include/save_master_gtid.inc

--connection server_2
--source include/sync_with_master_gtid.inc
SELECT * from t1 WHERE a > 10 ORDER BY a;

--connection server_1
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
wait
EOF

SET GLOBAL debug_dbug="+d,inject_error_writing_xid";
BEGIN;
INSERT INTO t1 VALUES (21);
--error ER_ERROR_ON_WRITE
COMMIT;
SET GLOBAL debug_dbug="+d,crash_dispatch_command_before";
--error 2006,2013
COMMIT;

--source include/wait_until_disconnected.inc

# Simulate that we reconnect to the same server (same server_id).
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart
EOF

--enable_reconnect
--source include/wait_until_connected_again.inc

SELECT @@GLOBAL.server_id;
SELECT * from t1 WHERE a > 10 ORDER BY a;
--disable_query_log
eval SELECT IF(INSTR(@@gtid_binlog_pos, '$saved_gtid'), "Binlog pos ok", CONCAT("Unexpected binlog pos: ", @@gtid_binlog_pos, "; does not contain the GTID $saved_gtid.")) AS gtid_check;
eval SELECT IF(INSTR(@@gtid_current_pos, '$saved_gtid'), "Current pos ok", CONCAT("Unexpected current pos: ", @@gtid_current_pos, "; does not contain the GTID $saved_gtid.")) AS gtid_check;
--enable_query_log

--echo # Wait 60 seconds for SQL thread to catch up with IO thread
--connection server_2
--let $wait_timeout= 600
while ($wait_timeout != 0)
{
  --let $read_log_pos= query_get_value('SHOW SLAVE STATUS', Read_Master_Log_Pos, 1)
  --let $exec_log_pos= query_get_value('SHOW SLAVE STATUS', Exec_Master_Log_Pos, 1)
  if ($read_log_pos == $exec_log_pos)
  {
    --let $wait_timeout= 0
  }
  if ($read_log_pos != $exec_log_pos)
  {
    --sleep 0.1
    --dec $wait_timeout
  }
}
if ($read_log_pos != $exec_log_pos)
{
  --die Timeout wait for SQL thread to catch up with IO thread
}

SELECT * from t1 WHERE a > 10 ORDER BY a;
--disable_query_log
eval SELECT IF(INSTR(@@gtid_binlog_pos, '$saved_gtid'), "Binlog pos ok", CONCAT("Unexpected binlog pos: ", @@gtid_binlog_pos, "; does not contain the GTID $saved_gtid.")) AS gtid_check;
eval SELECT IF(INSTR(@@gtid_slave_pos, '$saved_gtid'), "Slave pos ok", CONCAT("Unexpected slave pos: ", @@gtid_slave_pos, "; does not contain the GTID $saved_gtid.")) AS gtid_check;
eval SELECT IF(INSTR(@@gtid_current_pos, '$saved_gtid'), "Current pos ok", CONCAT("Unexpected current pos: ", @@gtid_current_pos, "; does not contain the GTID $saved_gtid.")) AS gtid_check;
--enable_query_log

--echo # Repeat this with additional transactions on the master

--connection server_1
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
wait
EOF

SET GLOBAL debug_dbug="+d,inject_error_writing_xid";
BEGIN;
INSERT INTO t1 VALUES (22);
--error ER_ERROR_ON_WRITE
COMMIT;
SET GLOBAL debug_dbug="+d,crash_dispatch_command_before";
--error 2006,2013
COMMIT;

--source include/wait_until_disconnected.inc

--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart
EOF

--enable_reconnect
--source include/wait_until_connected_again.inc

INSERT INTO t1 VALUES (23);
INSERT INTO t1 VALUES (24);
--let $saved_gtid=`SELECT @@last_gtid`
SELECT * from t1 WHERE a > 10 ORDER BY a;
--source include/save_master_gtid.inc

--connection server_2
--source include/sync_with_master_gtid.inc
SELECT * from t1 WHERE a > 10 ORDER BY a;

--echo # Repeat this with slave restart

--connection server_1
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
wait
EOF

SET GLOBAL debug_dbug="+d,inject_error_writing_xid";
BEGIN;
INSERT INTO t1 VALUES (25);
--error ER_ERROR_ON_WRITE
COMMIT;
SET GLOBAL debug_dbug="+d,crash_dispatch_command_before";
--error 2006,2013
COMMIT;

--source include/wait_until_disconnected.inc

--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart
EOF

--connection server_1
--enable_reconnect
--source include/wait_until_connected_again.inc

--connection server_2
--echo # Wait 60 seconds for IO thread to connect and SQL thread to catch up
--echo # with IO thread.
--let $wait_timeout= 600
while ($wait_timeout != 0)
{
  --let $connected=`SELECT COUNT(*) > 0 FROM information_schema.processlist WHERE State = 'Waiting for master to send event'`
  if ($connected)
  {
    --let $read_log_pos= query_get_value('SHOW SLAVE STATUS', Read_Master_Log_Pos, 1)
    --let $exec_log_pos= query_get_value('SHOW SLAVE STATUS', Exec_Master_Log_Pos, 1)
    if ($read_log_pos == $exec_log_pos)
    {
      --let $wait_timeout= 0
    }
    if ($read_log_pos != $exec_log_pos)
    {
      --sleep 0.1
      --dec $wait_timeout
    }
  }
  if (!$connected)
  {
    --sleep 0.1
    --dec $wait_timeout
  }
}
if (`SELECT NOT $connected OR $read_log_pos != $exec_log_pos`)
{
  --die Timeout wait for IO thread to connect and SQL thread to catch up with IO thread
}

--source include/stop_slave.inc

--connection server_1
--disable_query_log
eval SELECT IF(INSTR(@@gtid_binlog_pos, '$saved_gtid'), "Binlog pos ok", CONCAT("Unexpected binlog pos: ", @@gtid_binlog_pos, "; does not contain the GTID $saved_gtid.")) AS gtid_check;
eval SELECT IF(INSTR(@@gtid_current_pos, '$saved_gtid'), "Current pos ok", CONCAT("Unexpected current pos: ", @@gtid_current_pos, "; does not contain the GTID $saved_gtid.")) AS gtid_check;
--enable_query_log
INSERT INTO t1 VALUES (26);
INSERT INTO t1 VALUES (27);
SELECT * from t1 WHERE a > 10 ORDER BY a;
--source include/save_master_gtid.inc

--connection server_2
--disable_query_log
eval SELECT IF(INSTR(@@gtid_binlog_pos, '$saved_gtid'), "Binlog pos ok", CONCAT("Unexpected binlog pos: ", @@gtid_binlog_pos, "; does not contain the GTID $saved_gtid.")) AS gtid_check;
eval SELECT IF(INSTR(@@gtid_slave_pos, '$saved_gtid'), "Slave pos ok", CONCAT("Unexpected slave pos: ", @@gtid_slave_pos, "; does not contain the GTID $saved_gtid.")) AS gtid_check;
eval SELECT IF(INSTR(@@gtid_current_pos, '$saved_gtid'), "Current pos ok", CONCAT("Unexpected current pos: ", @@gtid_current_pos, "; does not contain the GTID $saved_gtid.")) AS gtid_check;
--enable_query_log
--source include/start_slave.inc
--source include/sync_with_master_gtid.inc
SELECT * from t1 WHERE a > 10 ORDER BY a;


--echo *** MDEV-6391: GTID binlog state not recovered if mariadb-bin.state is removed ***

--connection server_2
--source include/stop_slave.inc

# Do some misc. transactions, stop the master, drop the master-bin.state file.
# Start the master back up, check that binlog state is correct.

--connection server_1

INSERT INTO t1 VALUES (30);
SET @old_server_id= @@server_id;
SET @old_domain_id= @@gtid_domain_id;

SET SESSION server_id= 10;
INSERT INTO t1 VALUES (31);
INSERT INTO t1 VALUES (32);
SET SESSION gtid_domain_id= 1;
SET SESSION server_id=11;
INSERT INTO t1 VALUES (33);
SET SESSION gtid_domain_id= 2;
INSERT INTO t1 VALUES (34);
SET SESSION server_id= 10;
INSERT INTO t1 VALUES (35);
INSERT INTO t1 VALUES (36);
SET SESSION gtid_domain_id= 0;
SET SESSION server_id= 12;
INSERT INTO t1 VALUES (37);
SET SESSION gtid_domain_id= @old_domain_id;
SET SESSION server_id= @old_server_id;
INSERT INTO t1 VALUES (38);
INSERT INTO t1 VALUES (39);
SELECT * FROM t1 WHERE a >= 30 ORDER BY a;
--source include/save_master_gtid.inc

--let OLD_STATE= `SELECT @@gtid_binlog_state`

--let $datadir= `SELECT @@datadir`

--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
wait
EOF
shutdown_server;
--source include/wait_until_disconnected.inc

--remove_file $datadir/master-bin.state

--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart
EOF
--enable_reconnect
--source include/wait_until_connected_again.inc

--let NEW_STATE= `SELECT @@gtid_binlog_state`

--perl
my $old= $ENV{'OLD_STATE'};
my $new= $ENV{'NEW_STATE'};
# Make them order-independent, for easy comparison.
$old= join(",", sort(split(",", $old)));
$new= join(",", sort(split(",", $new)));
die "ERROR: new binlog state '$new' differs from old '$old'\n"
  unless $old eq $new;
EOF

--connection server_2
--source include/start_slave.inc
--source include/sync_with_master_gtid.inc
SELECT * FROM t1 WHERE a >= 30 ORDER BY a;


--connection server_1
DROP TABLE t1;

--connection default
--enable_reconnect
--source include/wait_until_connected_again.inc

--source include/rpl_end.inc