Debian Codegraph @

mysql-test/suite/galera/t/galera_slave_replay.test

raw
1 #
2 # This test tests the operation of transaction replay for async replication slave.
3 # If a potentially conflicting galera transaction arrives at
4 # just the right time during the commit and has lock conflict with async replication transaction
5 # applied by slave SQL thread, then the async replication transaction should either abort
6 # or rollback and replay (depending on the nature of lock conflict).
7 #
8
9 --source include/galera_cluster.inc
10 --source include/have_innodb.inc
11 --source include/have_log_bin.inc
12 --source include/have_debug.inc
13 --source include/have_debug_sync.inc
14 --source include/galera_have_debug_sync.inc
15
16 --connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2
17 --connection node_2a
18
19 ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
20
21 #
22 # node 3 is native MariaDB server operating as async replication master
23 #
24 --connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3
25 --connection node_3
26 RESET MASTER;
27
28 --connection node_2a
29 #
30 # count the number of wsrep replay's done in the node
31 #
32 --let $wsrep_local_replays_old = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'`
33
34 #
35 # nodes 1 and 2 form a galera cluster, node 2 operates as slave for native MariaDB master in node 3
36 #
37 --disable_query_log
38 --eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_USER='root', MASTER_SSL_VERIFY_SERVER_CERT=0, MASTER_PORT=$NODE_MYPORT_3;
39 --enable_query_log
40 START SLAVE;
41
42 --connection node_3
43 CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 CHAR(1)) engine=innodb;
44 INSERT INTO t1 VALUES (1, 'a');
45 INSERT INTO t1 VALUES (3, 'a');
46
47 #
48 # use statement format replication to cause a false positive conflict with async replication transaction
49 # and galera replication. The conflict will be on GAP lock, and slave SQL thread should rollback
50 # and replay
51 #
52 set binlog_format=STATEMENT;
53
54 SET AUTOCOMMIT=ON;
55 START TRANSACTION;
56
57 SELECT * FROM t1 FOR UPDATE;
58 UPDATE t1 SET f2 = 'c' WHERE f1 > 1;
59
60 --connection node_2a
61 # wait for create table and inserts to be replicated from master
62 SET SESSION wsrep_sync_wait = 0;
63 --let $wait_condition = SELECT COUNT(*) = 2 FROM test.t1;
64 --source include/wait_condition.inc
65
66 # wait for create table and inserts to be replicated in cluster
67 --connection node_1
68 SET SESSION wsrep_sync_wait = 0;
69 --let $wait_condition = SELECT COUNT(*) = 2 FROM test.t1;
70 --source include/wait_condition.inc
71
72 --connection node_2a
73 # Block the future commit of async replication
74 --let $galera_sync_point = commit_monitor_master_enter_sync
75 --source include/galera_set_sync_point.inc
76
77 # block also the applier before applying begins
78 SET GLOBAL debug_dbug = "d,sync.wsrep_apply_cb";
79
80 #
81 # now inject a conflicting insert from node 1, it will replicate with
82 # earlier seqno (than async transaction) and pause before applying in node 2
83 #
84 --connection node_1
85 INSERT INTO test.t1 VALUES (2, 'b');
86
87 #
88 # send the update from master, this will succeed here, beceuase of async replication.
89 # async replication will apply this in node 2 and pause before commit phase,
90 --connection node_3
91 --error 0
92 COMMIT;
93
94 # Wait until async slave commit is blocked in node_2
95 --connection node_2a
96 --source include/galera_wait_sync_point.inc
97
98 #
99 # release the applier
100 # note: have to clear wsrep_apply_cb sync point first, as async replication will go for replay
101 # and as this sync point, after BF applier is released to progress
102 #
103 SET GLOBAL debug_dbug = "";
104 SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb";
105
106 # Unblock the async slave commit
107 --connection node_2a
108 --source include/galera_clear_sync_point.inc
109 --source include/galera_signal_sync_point.inc
110
111 --connection node_3
112
113 SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'a';
114 SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'c';
115 SELECT * FROM t1;
116
117 --connection node_2a
118
119 # wsrep_local_replays has increased by 1
120 set session wsrep_sync_wait=15;
121 --let $wsrep_local_replays_new = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'`
122 set session wsrep_sync_wait=0;
123
124 --disable_query_log
125 --eval SELECT $wsrep_local_replays_new - $wsrep_local_replays_old = 1 AS wsrep_local_replays;
126 --enable_query_log
127
128 #
129 # replaying of async transaction should be effective, and row 3 having 'c' in f2
130 #
131 SELECT * FROM t1;
132 SET DEBUG_SYNC = "RESET";
133
134 #********************************************************************************
135 # test phase 2
136 #********************************************************************************
137
138 --echo #
139 --echo # test phase with real abort
140 --echo #
141
142 --connection node_3
143
144 set binlog_format=ROW;
145
146 insert into t1 values (4, 'd');
147
148 SET AUTOCOMMIT=ON;
149 START TRANSACTION;
150
151 UPDATE t1 SET f2 = 'd' WHERE f1 = 3;
152
153 --connection node_2a
154 # wait for the last insert to be replicated from master
155 --let $wait_condition = SELECT COUNT(*) = 4 FROM test.t1;
156 --source include/wait_condition.inc
157
158 # block applier
159 SET GLOBAL debug_dbug = "d,sync.wsrep_apply_cb";
160
161 # Inject a conflicting update from node 1
162 --connection node_1
163 UPDATE test.t1 SET f2 = 'e' WHERE f1 = 3;
164
165 --connection node_2a
166 # wait until applier has reached the sync point
167 SET SESSION DEBUG_SYNC = "now WAIT_FOR sync.wsrep_apply_cb_reached";
168 --let $expected_cert_failures = `SELECT VARIABLE_VALUE+1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_cert_failures'`
169
170 # send the update from master
171 --connection node_3
172 --error 0
173 COMMIT;
174
175 --connection node_2a
176 --let $wait_condition = SELECT VARIABLE_VALUE = $expected_cert_failures FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_cert_failures'
177 --source include/wait_condition.inc
178
179 # release the applier from node 1
180 SET GLOBAL debug_dbug = "";
181 SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb";
182
183 --connection node_2a
184
185 set session wsrep_sync_wait=15;
186 SELECT COUNT(*) = 1 FROM test.t1 WHERE f2 = 'e';
187 set session wsrep_sync_wait=0;
188
189 STOP SLAVE;
190 RESET SLAVE;
191 SET DEBUG_SYNC = "RESET";
192
193 DROP TABLE t1;
194
195 --connection node_3
196 DROP TABLE t1;
197 RESET MASTER;
198
199 --connection node_1
200 --disconnect node_2a
201 --disconnect node_3