Debian Codegraph @

mysql-test/suite/group_replication/t/gr_primary_failover_consistency_hold_from_master.test

raw
1 ###############################################################################
2 #
3 # A member of group have a slave connection to a server outside the group, if
4 # the connection has group_replication_consistency with value
5 # BEFORE_ON_PRIMARY_FAILOVER, when an election occur all statements from slave
6 # connection will be held until all backlog is applied
7 #
8 # Test:
9 # 0. This test requires three servers, two on multi primary mode
10 # 1. Bootstrap group on server 1
11 # 2. Join server2 to group
12 # 3. Set group_replication_consistency to BEFORE_ON_PRIMARY_FAILOVER on
13 # global scope, so new connections have it
14 # 4. On server 2 create a slave connection to server 3
15 # 5. Create table t1 an t2 on server3 and replicate to group
16 # 6. Pause applier threads to hold primary election (on wait
17 # for stabilizing transactions from former primaries)
18 # 7. Execute transaction on group
19 # 8. Server2 will certify transaction but won't apply due to
20 # paused applier threads.
21 # 9. Execute group_replication_switch_to_single_primary_mode to appoint
22 # server2 as primary on single primary mode group
23 # 10. Validate that primary election is executing
24 # 11. A read statement to new primary will be put on hold until all
25 # backlog's are applied
26 # 12. Validate statement is on hold
27 # 13. Statement executed on server3
28 # 14. Transaction from server3 will be held until backlog is applied
29 # 15. Table t2 will be empty until backlog is applied
30 # 16. UNLOCK tables to allow backlog to be applied
31 # 17. Reap with success read of last value inserted on group
32 # 18. Reap with success execution of set as primary server2
33 # 19. Server2 applied all backlog, table t2 has the data
34 # 20. Cleanup
35 #
36 ###############################################################################
37
38 --source include/have_debug_sync.inc
39 --source include/have_group_replication_plugin.inc
40
41 --let $rpl_server_count= 3
42 --let $rpl_skip_group_replication_start= 1
43 --source include/group_replication.inc
44
45 --echo
46 --echo # 1. Bootstrap group on server 1
47
48 --let $rpl_connection_name= server1
49 --source include/rpl_connection.inc
50
51 --source include/start_and_bootstrap_group_replication.inc
52
53 --echo
54 --echo # 2. Join server2 to group
55
56 --let $rpl_connection_name= server_2
57 --source include/rpl_connection.inc
58
59 --source include/start_group_replication.inc
60
61 --let $member2_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
62
63 --echo
64 --echo # 3. Set group_replication_consistency to BEFORE_ON_PRIMARY_FAILOVER on
65 --echo # global scope, so new connections have it
66
67 SET @@GLOBAL.group_replication_consistency= BEFORE_ON_PRIMARY_FAILOVER;
68
69 --echo
70 --echo # 4. On server 2 create a slave connection to server 3
71
72 --replace_result $SERVER_MYPORT_3 SERVER_3_PORT
73 --eval CHANGE REPLICATION SOURCE TO SOURCE_HOST='localhost', SOURCE_USER='root', SOURCE_PORT=$SERVER_MYPORT_3 for channel 'ch3_2'
74
75 --let $rpl_channel_name='ch3_2'
76 --source include/start_slave.inc
77 --let $rpl_channel_name=
78
79 SET @@GLOBAL.group_replication_consistency= EVENTUAL;
80
81 --echo
82 --echo # 5. Create table t1 an t2 on server3 and replicate to group
83
84 --let $rpl_connection_name= server3
85 --source include/rpl_connection.inc
86
87 CREATE TABLE test.t1 (a int primary key);
88 CREATE TABLE test.t2 (a int primary key);
89
90 --let $sync_slave_connection= server1
91 --source include/sync_slave_sql_with_master.inc
92 --connection server3
93 --let $sync_slave_connection= server2
94 --source include/sync_slave_sql_with_master.inc
95
96 --echo
97 --echo # 6. Pause applier threads to hold primary election (on wait
98 --echo # for stabilizing transactions from former primaries)
99
100 --let $rpl_connection_name= server_2
101 --source include/rpl_connection.inc
102
103 SET @@GLOBAL.DEBUG='+d,block_applier_updates';
104
105 --echo
106 --echo # 7. Execute transaction on group
107
108 --let $rpl_connection_name= server1
109 --source include/rpl_connection.inc
110
111 INSERT INTO t1 VALUES (1);
112
113 --echo
114 --echo # 8. Server2 will certify transaction but won't apply due to
115 --echo # paused applier threads.
116
117 --let $rpl_connection_name= server2
118 --source include/rpl_connection.inc
119
120 SET DEBUG_SYNC = "now WAIT_FOR applier_read_blocked";
121
122 --let $wait_condition= SELECT COUNT(*) = 1 FROM performance_schema.replication_group_member_stats WHERE member_id='$member2_uuid' AND count_transactions_checked = 3 AND count_transactions_remote_in_applier_queue = 1
123 --source include/wait_condition.inc
124
125 --echo
126 --echo # 9. Execute group_replication_switch_to_single_primary_mode to appoint
127 --echo # server2 as primary on single primary mode group
128
129 --let $rpl_connection_name= server1
130 --source include/rpl_connection.inc
131
132 --replace_result $member2_uuid MEMBER2_UUID
133 --send_eval SELECT group_replication_switch_to_single_primary_mode("$member2_uuid")
134
135 --echo
136 --echo # 10. Validate that primary election is executing
137
138 --let $rpl_connection_name= server2
139 --source include/rpl_connection.inc
140
141 --let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election: stabilizing transactions from former primaries"
142 --source include/wait_condition.inc
143
144 --echo
145 --echo # 11. A read statement to new primary will be put on hold until all
146 --echo # backlog's are applied
147
148 SET @@SESSION.group_replication_consistency= BEFORE_ON_PRIMARY_FAILOVER;
149
150 --send SELECT COUNT(*)=1 FROM t1 WHERE a = 1
151
152 --echo
153 --echo # 12. Validate statement is on hold
154
155 --let $rpl_connection_name= server_2
156 --source include/rpl_connection.inc
157
158 --let $wait_condition= SELECT COUNT(*)=1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE='Executing hook on transaction begin.' AND INFO='SELECT COUNT(*)=1 FROM t1 WHERE a = 1'
159 --source include/wait_condition.inc
160
161 # Before resume applier threads, lock table t1 to allow verify
162 # @@SESSION.group_replication_consistency to handle `INSERT INTO t2 VALUES (1)`
163 LOCK TABLES t1 READ;
164
165 SET @@GLOBAL.DEBUG='-d,block_applier_updates';
166 SET DEBUG_SYNC = "now SIGNAL resume_applier_read";
167
168 --echo
169 --echo # 13. Statement executed on server3
170
171 --let $rpl_connection_name= server3
172 --source include/rpl_connection.inc
173
174 INSERT INTO t2 VALUES (1);
175
176 --echo
177 --echo # 14. Transaction from server3 will be held until backlog is applied
178
179 --let $rpl_connection_name= server_2_1
180 --source include/rpl_connection.inc
181
182 --let $wait_condition= SELECT COUNT(*)=2 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE='Executing hook on transaction begin.'
183 --source include/wait_condition.inc
184
185 --echo
186 --echo # 15. Table t2 will be empty until backlog is applied
187
188 --let $assert_text= 'There are no values in table t2'
189 --let $assert_cond= [SELECT COUNT(*) AS count FROM t2, count, 1] = 0
190 --source include/assert.inc
191
192 --echo
193 --echo # 16. UNLOCK tables to allow backlog to be applied
194
195 --let $rpl_connection_name= server_2
196 --source include/rpl_connection.inc
197
198 UNLOCK TABLES;
199
200 --echo
201 --echo # 17. Reap with success read of last value inserted on group
202
203 --let $rpl_connection_name= server2
204 --source include/rpl_connection.inc
205
206 --reap
207
208 SET @@SESSION.group_replication_consistency= DEFAULT;
209
210 --let $rpl_connection_name= server_2
211 --source include/rpl_connection.inc
212 SET DEBUG_SYNC= 'RESET';
213
214 --echo
215 --echo # 18. Reap with success execution of set as primary server2
216
217 --let $rpl_connection_name= server1
218 --source include/rpl_connection.inc
219
220 --replace_result $member2_uuid MEMBER2_UUID
221 --reap
222
223 --echo
224 --echo # 19. Server2 applied all backlog, table t2 has the data
225
226 --let $wait_condition= SELECT COUNT(*) = 1 FROM t2;
227 --source include/wait_condition.inc
228
229 --echo
230 --echo # 20. Cleanup
231
232 --let $rpl_connection_name= server3
233 --source include/rpl_connection.inc
234
235 DROP TABLE t1;
236 DROP TABLE t2;
237
238 --let $sync_slave_connection= server1
239 --source include/sync_slave_sql_with_master.inc
240
241 --let $rpl_connection_name= server3
242 --source include/rpl_connection.inc
243
244 --let $sync_slave_connection= server2
245 --source include/sync_slave_sql_with_master.inc
246
247 --let $rpl_connection_name= server2
248 --source include/rpl_connection.inc
249
250 SET @@GLOBAL.group_replication_consistency= DEFAULT;
251
252 STOP REPLICA FOR CHANNEL 'ch3_2';
253 RESET REPLICA ALL FOR CHANNEL 'ch3_2';
254
255 --let $rpl_connection_name= server3
256 --source include/rpl_connection.inc
257
258 RESET MASTER;
259
260 --let $rpl_group_replication_single_primary_mode=1
261 --let $rpl_group_replication_reset_persistent_vars=1
262 --source include/group_replication_end.inc