Debian Codegraph @

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

raw
1 --source include/have_innodb.inc
2 --source include/have_debug.inc
3 --source include/have_debug_sync.inc
4 --source include/have_binlog_format_mixed.inc
5 --source include/master-slave.inc
6
7 --connection slave
8 --source include/stop_slave.inc
9 SET @old_parallel_threads= @@GLOBAL.slave_parallel_threads;
10 SET GLOBAL slave_parallel_threads=3;
11 SET @old_parallel_mode= @@GLOBAL.slave_parallel_mode;
12 SET GLOBAL slave_parallel_mode=aggressive;
13 SET @old_dbug= @@GLOBAL.debug_dbug;
14 CHANGE MASTER TO master_use_gtid=slave_pos;
15 --source include/start_slave.inc
16
17 --echo *** MDEV-31509: Lost data with FTWRL and STOP SLAVE
18 # The bug was as follows:
19 # 1. Event groups T1 and T2 are queued but not started yet.
20 # 2. FLUSH TABLE WITH READ LOCKS starts, sets rpl_parallel_entry::pause_sub_id
21 # 3. T2 Sees pause_sub_id, goes to wait for the pause to complete.
22 # 4. FTWRL completes, UNLOCK TABLES is run.
23 # 5. STOP SLAVE is run, sets rpl_parallel_entry::stop_sub_id.
24 # 6. T2 wakes up after FTWRL pause, only now sets
25 # rpl_parallel_entry::largest_started_sub_id. This is the bug,
26 # largest_started_sub_id is set too late here.
27 # 7. T1 starts, it sees stop_sub_id<T1, so T1 is skipped due to STOP SLAVE.
28 # 8. T2 continues, its check for stop_sub_id was before STOP SLAVE. So T2 is
29 # wrongly applied, silently losing transaction T1.
30
31
32 --connection master
33 ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
34 CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
35 CREATE TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=MyISAM;
36 INSERT INTO t1 VALUES (0,0);
37 INSERT INTO t2 VALUES (0,0);
38 --source include/save_master_gtid.inc
39
40 --connection slave
41 --source include/sync_with_master_gtid.inc
42
43 --connection slave
44 --echo *** Arrange for T1 to delay before entering GCO wait.
45 SET GLOBAL debug_dbug="+d,gco_wait_delay_gtid_0_x_99";
46 --echo *** Arrange for T2 to wait for FTWRL to start.
47 SET GLOBAL debug_dbug="+d,hold_worker_on_schedule";
48 --echo *** Arrange for T2 to delay wakeup from FTWRL pause.
49 SET GLOBAL debug_dbug="+d,delay_ftwrl_wait_gtid_0_x_100";
50
51 --connection master
52 --echo *** Event group T1
53 SET SESSION gtid_seq_no=99;
54 INSERT INTO t1 VALUES (1,1);
55
56 --connection slave
57 --echo *** 1a. Wait for T1 to be queued.
58 SET debug_sync="now WAIT_FOR gco_wait_paused";
59
60 --connection master
61 --echo *** Event group T2
62 SET SESSION gtid_seq_no=100;
63 INSERT INTO t2 VALUES (2,2);
64
65 --connection slave
66 --echo *** 1b. Wait for T2 to be queued.
67 SET debug_sync= "now WAIT_FOR reached_pause";
68
69 --connection slave1
70 --echo *** 2. Run FTWRL
71 SET GLOBAL debug_dbug= "+d,pause_for_ftwrl_wait";
72 send FLUSH TABLES WITH READ LOCK;
73
74 --connection slave
75 SET debug_sync= "now WAIT_FOR pause_ftwrl_waiting";
76
77 --echo *** 3. Wait for T2 to be waiting for FTWRL pause
78 SET debug_sync= "now SIGNAL continue_worker";
79 --let $wait_condition= SELECT count(*) = 1 FROM information_schema.processlist WHERE state LIKE "%Waiting due to global read lock%" and command="Slave_worker";
80 --source include/wait_condition.inc
81
82 --echo *** 4. FTWRL completes, UNLOCK TABLES.
83 SET debug_sync="now SIGNAL pause_ftwrl_cont";
84
85 --connection slave1
86 reap;
87 UNLOCK TABLES;
88
89 --connection slave
90 --echo *** T2 is now ready to proceed after FTWRL pause, but did not wake up yet.
91 SET debug_sync="now WAIT_FOR pause_wait_started";
92
93 --echo *** 5. STOP SLAVE is run.
94 --connection slave1
95 SET GLOBAL debug_dbug="+d,rpl_parallel_wait_for_done_trigger";
96 send STOP SLAVE;
97
98 --connection slave
99 SET debug_sync="now WAIT_FOR wait_for_done_waiting";
100
101 --echo *** 5. T2 wakes up after FTWRL pause, reaches wait_for_prior_commit().
102 SET debug_sync="now SIGNAL pause_wait_continue";
103 --let $wait_condition= SELECT count(*) = 1 FROM information_schema.processlist WHERE state LIKE "%Waiting for prior transaction to commit%" and command="Slave_worker";
104 --source include/wait_condition.inc
105
106 --echo *** 6. T1 starts.
107 SET debug_sync="now SIGNAL gco_wait_cont";
108
109 --connection slave1
110 reap;
111
112 --connection slave
113 --source include/wait_for_slave_to_stop.inc
114
115 --connection master
116 SELECT * FROM t1 ORDER BY a;
117 SELECT * FROM t2 ORDER BY a;
118 --source include/save_master_gtid.inc
119
120 --connection slave
121 --source include/start_slave.inc
122 --source include/sync_with_master_gtid.inc
123
124 # The bug here was that T2 was errorneously replicated while T1 was
125 # being skipped due to STOP SLAVE. So the @@gtid_slave_pos was at T2,
126 # but we were missing the data from T1.
127 SELECT @@GLOBAL.gtid_slave_pos;
128 SELECT * FROM t1 ORDER BY a;
129 SELECT * FROM t2 ORDER BY a;
130
131 --echo *** Clean up.
132 --connection slave
133 --source include/stop_slave.inc
134 SET DEBUG_SYNC= "RESET";
135 SET GLOBAL slave_parallel_threads= @old_parallel_threads;
136 SET GLOBAL slave_parallel_mode= @old_parallel_mode;
137 SET GLOBAL debug_dbug=@old_dbug;
138 --source include/start_slave.inc
139
140 --connection master
141 DROP TABLE t1, t2;
142
143 --source include/rpl_end.inc