Debian Codegraph @

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

raw
1 ########################################################################
2 #
3 # This test validate that transactions executed when a primary election is
4 # running will be put hold until all backlog is applied
5 #
6 # Test:
7 # 0. This test requires two servers on single primary mode
8 # 1. Bootstrap group on server 1 and create table t1
9 # 2. Join server2 to group and lock tables t1
10 # 3. Execute transaction on primary server
11 # 4. Server2 will certify transaction but won't apply due lock tables
12 # 5. Execute group_replication_set_as_primary to appoint server2 as
13 # primary
14 # 6. Validate that primary election is executing
15 # 7. A read statement to new primary will be put on hold until all
16 # backlog's are applied
17 # 8. Validate statement is on hold
18 # 9. Statements aren't held when executed on a secondary
19 # 10. UNLOCK tables to allow backlog to be applied
20 # 11. Reap with success read of last value inserted on group
21 # 12. Reap with success execution of set as primary server2
22 # 13. Lock tables on next primary to have backlog to apply
23 # 14. Insert data on table to create backlog on server1
24 # 15. Server1 will certify transaction but won't apply due lock tables
25 # 16. Execute set as primary to run a primary election
26 # 17. Validate an primary election is executing
27 # 18. A write statement to new primary will be put on hold until apply all
28 # backlog
29 # 19. Validate statement is on hold
30 # 20. Statements aren't held when executed on a secondary
31 # 21. UNLOCK tables to allow apply backlog
32 # 22. Reap with success insert after backlog is applied
33 # 23. Cleanup
34 #
35 ########################################################################
36
37 --source include/have_debug.inc
38 --source include/have_group_replication_plugin.inc
39
40 --let $rpl_server_count= 2
41 --let $rpl_skip_group_replication_start= 1
42 --let $rpl_group_replication_single_primary_mode=1
43 --source include/group_replication.inc
44
45 --echo
46 --echo # 1. Bootstrap group on server 1 and create table t1
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 --let $member1_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
54
55 CREATE TABLE test.t1 (a int primary key);
56
57 INSERT INTO t1 VALUES (1);
58
59 --echo
60 --echo # 2. Join server2 to group and lock tables t1
61
62 --let $rpl_connection_name= server_2
63 --source include/rpl_connection.inc
64
65 --source include/start_group_replication.inc
66
67 --let $member2_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
68
69 LOCK TABLES t1 READ;
70
71 --echo
72 --echo # 3. Execute transaction on primary server
73
74 --let $rpl_connection_name= server1
75 --source include/rpl_connection.inc
76
77 INSERT INTO t1 VALUES (2);
78
79 --echo
80 --echo # 4. Server2 will certify transaction but won't apply due lock tables
81
82 --let $rpl_connection_name= server2
83 --source include/rpl_connection.inc
84
85 --let $wait_condition= SELECT COUNT(*) = 1 FROM performance_schema.replication_group_member_stats WHERE member_id='$member2_uuid' AND count_transactions_checked = 1 AND count_transactions_remote_in_applier_queue = 1
86 --source include/wait_condition.inc
87
88 --echo
89 --echo # 5. Execute group_replication_set_as_primary to appoint server2 as
90 --echo # primary
91
92 --let $rpl_connection_name= server1
93 --source include/rpl_connection.inc
94
95 --replace_result $member2_uuid MEMBER2_UUID
96 --send_eval SELECT group_replication_set_as_primary("$member2_uuid")
97
98 --echo
99 --echo # 6. Validate that primary election is executing
100
101 --let $rpl_connection_name= server2
102 --source include/rpl_connection.inc
103
104 --let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "stage/group_rpl/Primary Election: applying buffered transactions"
105 --source include/wait_condition.inc
106
107 --echo
108 --echo # 7. A read statement to new primary will be put on hold until all
109 --echo # backlog's are applied
110
111 SET @@SESSION.group_replication_consistency= BEFORE_ON_PRIMARY_FAILOVER;
112
113 --send SELECT COUNT(*)=1 FROM t1 WHERE a = 2
114
115 --echo
116 --echo # 8. Validate statement is on hold
117
118 --let $rpl_connection_name= server_2
119 --source include/rpl_connection.inc
120
121 --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 = 2'
122 --source include/wait_condition.inc
123
124 --echo # 9. Statements aren't held when executed on a secondary
125
126 --let $rpl_connection_name= server_1
127 --source include/rpl_connection.inc
128
129 # If command is held it will give timeout
130 SELECT * FROM t1;
131
132 --echo
133 --echo # 10. UNLOCK tables to allow backlog to be applied
134
135 --let $rpl_connection_name= server_2
136 --source include/rpl_connection.inc
137
138 UNLOCK TABLES;
139
140 --echo
141 --echo # 11. Reap with success read of last value inserted on group
142
143 --let $rpl_connection_name= server2
144 --source include/rpl_connection.inc
145
146 --reap
147
148 SET @@SESSION.group_replication_consistency= DEFAULT;
149
150 --echo
151 --echo # 12. Reap with success execution of set as primary server2
152
153 --let $rpl_connection_name= server1
154 --source include/rpl_connection.inc
155
156 --replace_result $member2_uuid MEMBER2_UUID
157 --reap
158
159 --echo
160 --echo # 13. Lock tables on next primary to have backlog to apply
161
162 --let $rpl_connection_name= server_1
163 --source include/rpl_connection.inc
164
165 LOCK TABLES t1 READ;
166
167 --echo
168 --echo # 14. Insert data on table to create backlog on server1
169
170 --let $rpl_connection_name= server2
171 --source include/rpl_connection.inc
172
173 INSERT INTO t1 VALUES (3);
174
175 --echo
176 --echo # 15. Server1 will certify transaction but won't apply due lock tables
177
178 --let $rpl_connection_name= server1
179 --source include/rpl_connection.inc
180
181 --let $wait_condition= SELECT COUNT(*) = 1 FROM performance_schema.replication_group_member_stats WHERE member_id='$member1_uuid' AND count_transactions_checked = 4 AND count_transactions_remote_in_applier_queue = 1
182 --source include/wait_condition.inc
183
184 --echo
185 --echo # 16. Execute set as primary to run a primary election
186
187 --let $rpl_connection_name= server2
188 --source include/rpl_connection.inc
189
190 --replace_result $member1_uuid MEMBER1_UUID
191 --send_eval SELECT group_replication_set_as_primary("$member1_uuid")
192
193 --echo
194 --echo # 17. Validate an primary election is executing
195
196 --let $rpl_connection_name= server1
197 --source include/rpl_connection.inc
198
199 --let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "stage/group_rpl/Primary Election: applying buffered transactions"
200 --source include/wait_condition.inc
201
202 --echo
203 --echo # 18. A write statement to new primary will be put on hold until apply all
204 --echo # backlog
205
206 SET @@SESSION.group_replication_consistency= BEFORE_ON_PRIMARY_FAILOVER;
207
208 --send INSERT INTO t1 VALUES (4);
209
210 --echo
211 --echo # 19. Validate statement is on hold
212
213 --let $rpl_connection_name= server_1
214 --source include/rpl_connection.inc
215
216 --let $wait_condition= SELECT COUNT(*)=1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE='Executing hook on transaction begin.' AND INFO='INSERT INTO t1 VALUES (4)'
217 --source include/wait_condition.inc
218
219 --echo # 20. Statements aren't held when executed on a secondary
220
221 --let $rpl_connection_name= server_2
222 --source include/rpl_connection.inc
223
224 # If command is held it will give timeout
225 SELECT * FROM t1;
226
227 --echo
228 --echo # 21. UNLOCK tables to allow apply backlog
229
230 --let $rpl_connection_name= server_1
231 --source include/rpl_connection.inc
232
233 UNLOCK TABLES;
234
235 --echo
236 --echo # 22. Reap with success insert after backlog is applied
237
238 --let $rpl_connection_name= server1
239 --source include/rpl_connection.inc
240
241 --reap
242
243 --echo
244 --echo # 23. Cleanup
245
246 SET @@SESSION.group_replication_consistency= DEFAULT;
247 DROP TABLE t1;
248
249 --let $rpl_connection_name= server2
250 --source include/rpl_connection.inc
251
252 # Read with success change of primary
253 --replace_result $member1_uuid MEMBER1_UUID
254 --reap
255
256 --source include/group_replication_end.inc