Debian Codegraph @

mysql-test/suite/rpl/include/rpl_parallel_incorrect_relay_pos.inc

raw
1 --echo *** MDEV-7237: Parallel replication: incorrect relaylog position after stop/start the slave ***
2
3 --source include/have_innodb.inc
4 --source include/have_debug.inc
5 --source include/have_debug_sync.inc
6 --source include/master-slave.inc
7
8 --connection server_2
9 --source include/stop_slave.inc
10 CALL mtr.add_suppression("Commit failed due to failure of an earlier commit on which this one depends");
11 SET @old_parallel_threads=@@GLOBAL.slave_parallel_threads;
12 SET @old_parallel_mode=@@GLOBAL.slave_parallel_mode;
13 SET GLOBAL slave_parallel_threads=10;
14 # Test assumes that 'conservative' mode is in effect. i.e
15 # Do not start parallel execution of this event group until all prior groups
16 # have reached the commit phase. Upon execution of STOP SLAVE there can be one
17 # group which is executing and the rest are doing group commit order wait.
18 SET GLOBAL slave_parallel_mode='conservative';
19 CHANGE MASTER TO master_use_gtid=slave_pos;
20 --source include/start_slave.inc
21
22 --connection server_1
23 ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
24 CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB;
25 INSERT INTO t2 VALUES (40);
26 --save_master_pos
27
28 --connection server_2
29 --sync_with_master
30 --connect (con_temp2,127.0.0.1,root,,test,$SERVER_MYPORT_2,)
31 --source include/stop_slave.inc
32 CHANGE MASTER TO master_use_gtid=no;
33 SET @old_dbug= @@GLOBAL.debug_dbug;
34 # This DBUG injection causes a DEBUG_SYNC signal "scheduled_gtid_0_x_100" when
35 # GTID 0-1-100 has been scheduled for and fetched by a worker thread.
36 SET GLOBAL debug_dbug="+d,rpl_parallel_scheduled_gtid_0_x_100";
37 # This DBUG injection causes a DEBUG_SYNC signal "wait_for_done_waiting" when
38 # STOP SLAVE has signalled all worker threads to stop.
39 SET GLOBAL debug_dbug="+d,rpl_parallel_wait_for_done_trigger";
40 # Reset worker threads to make DBUG setting catch on.
41 SET GLOBAL slave_parallel_threads=0;
42 SET GLOBAL slave_parallel_threads=10;
43
44
45 --connection server_1
46 # Setup some transaction for the slave to replicate.
47 INSERT INTO t2 VALUES (41);
48 INSERT INTO t2 VALUES (42);
49 # Need to log the DELETE in statement format, so we can see it in processlist.
50 SET @old_format= @@binlog_format;
51 SET binlog_format= statement;
52 DELETE FROM t2 WHERE a=40;
53 SET binlog_format= @old_format;
54 INSERT INTO t2 VALUES (43);
55 INSERT INTO t2 VALUES (44);
56 # Force the slave to switch to a new relay log file.
57 FLUSH LOGS;
58 INSERT INTO t2 VALUES (45);
59 # Inject a GTID 0-1-100, which will trigger a DEBUG_SYNC signal when this
60 # transaction has been fetched by a worker thread.
61 SET gtid_seq_no=100;
62 INSERT INTO t2 VALUES (46);
63 --save_master_pos
64
65 --connection con_temp2
66 # Temporarily block the DELETE on a=40 from completing.
67 BEGIN;
68 SELECT * FROM t2 WHERE a=40 FOR UPDATE;
69
70 --connection server_2
71 --source include/start_slave.inc
72
73 # Wait for a worker thread to start on the DELETE that will be blocked
74 # temporarily by the SELECT FOR UPDATE.
75 --let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE state='updating' and info LIKE '%DELETE FROM t2 WHERE a=40%'
76 --source include/wait_condition.inc
77
78 # The DBUG injection set above will make the worker thread signal the following
79 # debug_sync when the GTID 0-1-100 has been reached by a worker thread.
80 # Thus, at this point, the SQL driver thread has reached the next
81 # relay log file name, while a worker thread is still processing a
82 # transaction in the previous relay log file, blocked on the SELECT FOR
83 # UPDATE.
84 SET debug_sync= 'now WAIT_FOR scheduled_gtid_0_x_100';
85 # At this point, the SQL driver thread is in the new relay log file, while
86 # the DELETE from the old relay log file is not yet complete. We will stop
87 # the slave at this point. The bug was that the DELETE statement would
88 # update the slave position to the _new_ relay log file name instead of
89 # its own old file name. Thus, by stoping and restarting the slave at this
90 # point, we would get an error at restart due to incorrect position. (If
91 # we would let the slave catch up before stopping, the incorrect position
92 # would be corrected by a later transaction).
93
94 send STOP SLAVE;
95
96 --connection con_temp2
97 # Wait for STOP SLAVE to have proceeded sufficiently that it has signalled
98 # all worker threads to stop; this ensures that we will stop after the DELETE
99 # transaction (and not after a later transaction that might have been able
100 # to set a fixed position).
101 SET debug_sync= 'now WAIT_FOR wait_for_done_waiting';
102 # Now release the row lock that was blocking the replication of DELETE.
103 ROLLBACK;
104
105 --connection server_2
106 reap;
107 --source include/wait_for_slave_sql_to_stop.inc
108 SELECT * FROM t2 WHERE a >= 40 ORDER BY a;
109 # Now restart the slave. With the bug present, this would start at an
110 # incorrect relay log position, causing relay log read error (or if unlucky,
111 # silently skip a number of events).
112 --source include/start_slave.inc
113 --sync_with_master
114 SELECT * FROM t2 WHERE a >= 40 ORDER BY a;
115
116 # Clean up.
117 --source include/stop_slave.inc
118 SET GLOBAL debug_dbug=@old_dbug;
119 SET DEBUG_SYNC= 'RESET';
120 SET GLOBAL slave_parallel_threads=@old_parallel_threads;
121 SET GLOBAL slave_parallel_mode=@old_parallel_mode;
122 CHANGE MASTER TO master_use_gtid=slave_pos;
123 --source include/start_slave.inc
124
125 --connection server_1
126 DROP TABLE t2;
127
128 --source include/rpl_end.inc