Debian Codegraph @

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

raw
1 --echo *** Test STOP SLAVE in parallel mode ***
2
3 --source include/have_innodb.inc
4 --source include/have_debug.inc
5 --source include/have_debug_sync.inc
6 --source include/have_binlog_format_statement.inc
7 --source include/master-slave.inc
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=10;
14 SET GLOBAL slave_parallel_mode='conservative';
15
16 CHANGE MASTER TO master_use_gtid=slave_pos;
17 --source include/start_slave.inc
18 --connect (con_temp1,127.0.0.1,root,,test,$SERVER_MYPORT_2,)
19 --connect (con_temp2,127.0.0.1,root,,test,$SERVER_MYPORT_2,)
20
21 --connection server_1
22 ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
23 CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=MyISAM;
24 CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=InnoDB;
25 CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
26 # MDEV-515 takes X-lock on the table for the first insert.
27 # So concurrent insert won't happen on the table
28 INSERT INTO t2 VALUES(100);
29 INSERT INTO t3 VALUES(100, 100);
30 --save_master_pos
31
32 --connection server_2
33 --sync_with_master
34 --source include/stop_slave.inc
35
36 --connection server_1
37 # Set up a couple of transactions. The first will be blocked halfway
38 # through on a lock, and while it is blocked we initiate STOP SLAVE.
39 # We then test that the halfway-initiated transaction is allowed to
40 # complete, but no subsequent ones.
41 # We have to use statement-based mode and set
42 # binlog_direct_non_transactional_updates=0; otherwise the binlog will
43 # be split into two event groups, one for the MyISAM part and one for the
44 # InnoDB part.
45 SET binlog_direct_non_transactional_updates=0;
46 SET sql_log_bin=0;
47 CALL mtr.add_suppression("Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction");
48 SET sql_log_bin=1;
49 BEGIN;
50 INSERT INTO t2 VALUES (20);
51 --disable_warnings
52 INSERT INTO t1 VALUES (20);
53 --enable_warnings
54 INSERT INTO t2 VALUES (21);
55 INSERT INTO t3 VALUES (20, 20);
56 COMMIT;
57 INSERT INTO t3 VALUES(21, 21);
58 INSERT INTO t3 VALUES(22, 22);
59 --save_master_pos
60 --let $master_pos= query_get_value(SHOW MASTER STATUS, Position, 1)
61
62 # Start a connection that will block the replicated transaction halfway.
63 --connection con_temp1
64 BEGIN;
65 INSERT INTO t2 VALUES (21);
66
67 --connection server_2
68
69 #
70 # Parallel replication will complete any in-progress event group at STOP SLAVE,
71 # but only if the event group is already queued up for the worker thread. If
72 # the SQL driver thread is delayed in queueing up events, the parallel worker
73 # thread can abort the event group, leaving the non-transactional update to the
74 # MyISAM table that cannot be rolled back (MDEV-7432). If this happens the test
75 # would fail with duplicate key error after slave restart.
76 #
77 # To avoid this, we here wait for the IO thread to read all master events, and
78 # for the SQL driver thread to queue all the events for workers. This wait
79 # should be removed if/when MDEV-7432 is fixed.
80 #
81 START SLAVE IO_THREAD;
82 --let $slave_param= Read_Master_Log_Pos
83 --let $slave_param_value= $master_pos
84 --source include/wait_for_slave_param.inc
85 START SLAVE SQL_THREAD;
86 --let $wait_condition= SELECT COUNT(*)=1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE State LIKE '%Slave has read all relay log; waiting for more updates%'
87 --source include/wait_condition.inc
88
89 # Wait for the MyISAM change to be visible, after which replication will wait
90 # for con_temp1 to roll back.
91 --let $wait_condition= SELECT COUNT(*) = 1 FROM t1 WHERE a=20
92 --source include/wait_condition.inc
93
94 --connection con_temp2
95 # Initiate slave stop. It will have to wait for the current event group
96 # to complete.
97 # The dbug injection causes debug_sync to signal 'wait_for_done_waiting'
98 # when the SQL driver thread is ready.
99 SET @old_dbug= @@GLOBAL.debug_dbug;
100 SET GLOBAL debug_dbug="+d,rpl_parallel_wait_for_done_trigger";
101 send STOP SLAVE;
102
103 --connection con_temp1
104 SET debug_sync='now WAIT_FOR wait_for_done_waiting';
105 ROLLBACK;
106
107 --connection con_temp2
108 reap;
109 SET GLOBAL debug_dbug=@old_dbug;
110 SET debug_sync='RESET';
111
112 --connection server_2
113 --source include/wait_for_slave_to_stop.inc
114 # We should see the first transaction applied, but not the two others.
115 SELECT * FROM t1 WHERE a >= 20 ORDER BY a;
116 SELECT * FROM t2 WHERE a >= 20 ORDER BY a;
117 SELECT * FROM t3 WHERE a >= 20 ORDER BY a;
118
119 --source include/start_slave.inc
120 --sync_with_master
121 SELECT * FROM t1 WHERE a >= 20 ORDER BY a;
122 SELECT * FROM t2 WHERE a >= 20 ORDER BY a;
123 SELECT * FROM t3 WHERE a >= 20 ORDER BY a;
124
125 --connection server_2
126 # Respawn all worker threads to clear any left-over debug_sync or other stuff.
127 --source include/stop_slave.inc
128 SET GLOBAL slave_parallel_mode=@old_parallel_mode;
129 SET GLOBAL slave_parallel_threads=@old_parallel_threads;
130 --source include/start_slave.inc
131 SET DEBUG_SYNC= 'RESET';
132 --disconnect con_temp1
133 --disconnect con_temp2
134
135 --connection server_1
136 DROP TABLE t1,t2,t3;
137 SET DEBUG_SYNC= 'RESET';
138
139 --source include/rpl_end.inc