Debian Codegraph @

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

raw
1 ###########################################################################################################
2 # This test checks the behavior of following functions on GR channels:
3 # SELECT SOURCE_POS_WAIT()
4 # WAIT_FOR_EXECUTED_GTID_SET()
5 # WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS().
6 #
7 # Test :
8 # 0. This test requires 3 servers.
9 # 1. Start two servers (server1 and server2) and form a group.
10 # 2. Create a table and insert 100 records on server1.
11 # 3. Check the status of gtids using WAIT_FOR_EXECUTED_GTID_SET on server1.
12 # 4. Add a server (server3) to the group using start group_replication command.
13 # 5. Wait for recovery channel to be created for a newly added member and call
14 # SOURCE_POS_WAIT function to wait for gtid set to reach a stored value and
15 # data to be synced.
16 # 6. Stop gr on server3 and validate some error cases for SOURCE_POS_WAIT
17 # function when channels are not present.
18 # 7. Create a table t2 on server2 and insert 50 records.
19 # 8. Start the group replication on server3.
20 # 9. Use the WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS and WAIT_FOR_EXECUTED_GTID_SET
21 # function calls to make sure data is synced (which is inserted in step6).
22 # 10. Check the status of all the nodes and validate the records in server2 and
23 # server3.
24 ############################################################################################################
25 --source include/big_test.inc
26 --source include/have_debug_sync.inc
27 --source include/have_group_replication_plugin.inc
28 --let $rpl_skip_group_replication_start= 1
29 --let $rpl_server_count= 3
30 --source include/group_replication.inc
31
32 # Suprress the warning on server1, which is logged due to
33 # STOP/START SLAVE SQL_THREAD FOR CHANNEL "group_replication_applier"
34 # command execution
35 SET SESSION sql_log_bin= 0;
36 call mtr.add_suppression("'It is not possible to ensure the proper order when logging the view change log event.'");
37 SET SESSION sql_log_bin= 1;
38
39 #
40 # Start group replication on two servers
41 #
42 --echo
43 --let $rpl_connection_name= server1
44 --source include/rpl_connection.inc
45 --source include/start_and_bootstrap_group_replication.inc
46
47 --echo
48 --let $rpl_connection_name= server2
49 --source include/rpl_connection.inc
50 --source include/start_group_replication.inc
51
52 # Suprress the warning on server1, which is logged due to
53 # STOP/START SLAVE SQL_THREAD FOR CHANNEL "group_replication_applier"
54 # command execution
55 SET SESSION sql_log_bin= 0;
56 call mtr.add_suppression("'It is not possible to ensure the proper order when logging the view change log event.'");
57 SET SESSION sql_log_bin= 1;
58
59 # Create a table t1 on server1 and insert 100 records
60 --let $rpl_connection_name= server1
61 --source include/rpl_connection.inc
62 CREATE TABLE test.t1 ( a int primary key);
63 --source include/rpl_sync.inc
64 --disable_query_log
65 --let $i=100
66 while($i)
67 {
68 --EVAL INSERT INTO t1 VALUES ($i)
69 --dec $i
70 }
71 --enable_query_log
72
73 # Call and wait for gtid set to reach 103 using WAIT_FOR_EXECUTED_GTID_SET(),
74 # After 100 inserts and all the operations gtid executed will be 103 for server
75 --replace_result $group_replication_group_name GROUP_REPLICATION_GROUP_NAME
76 eval SELECT WAIT_FOR_EXECUTED_GTID_SET('$group_replication_group_name:1-103');
77
78 # This call should wait for 5 seconds and come out as gtid set
79 # will not reach the value 106, and returns 1
80 --replace_result $group_replication_group_name GROUP_REPLICATION_GROUP_NAME
81 eval SELECT WAIT_FOR_EXECUTED_GTID_SET('$group_replication_group_name:1-120',5);
82 --source include/rpl_sync.inc
83
84 --let $rpl_connection_name= server1
85 --source include/rpl_connection.inc
86 # Store the master binlog name and position , which will be used later
87 # for calling SOURCE_POS_WAIT function
88 --let $m1_saved_file= query_get_value(SHOW MASTER STATUS, File, 1)
89 --let $m1_saved_pos= query_get_value(SHOW MASTER STATUS, Position, 1)
90 --let $server1_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
91
92 SET @@GLOBAL.DEBUG='+d,block_applier_updates';
93
94 --let $rpl_connection_name= server2
95 --source include/rpl_connection.inc
96 # Store the master binlog name and position , which will be used later
97 # for calling SOURCE_POS_WAIT function
98 --let $m2_saved_file= query_get_value(SHOW MASTER STATUS, File, 1)
99 --let $m2_saved_pos= query_get_value(SHOW MASTER STATUS, Position, 1)
100 --let $server2_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
101
102 SET @@GLOBAL.DEBUG='+d,block_applier_updates';
103
104 --let $rpl_connection_name= server3
105 --source include/rpl_connection.inc
106
107 SET SESSION sql_log_bin= 0;
108 call mtr.add_suppression("Error while sending message in the group replication incremental recovery process");
109 SET SESSION sql_log_bin= 1;
110
111 --replace_result $group_replication_group_name GROUP_REPLICATION_GROUP_NAME
112 --eval SET GLOBAL group_replication_group_name= "$group_replication_group_name"
113 --source include/start_group_replication_command.inc
114
115 # Make sure that recovery channel is created
116 --let $wait_condition= SELECT COUNT(*)=1 FROM performance_schema.replication_connection_status where CHANNEL_NAME="group_replication_recovery" and SERVICE_STATE="ON"
117 --source include/wait_condition.inc
118
119 --let $group_replication_member_state= RECOVERING
120 --source include/gr_wait_for_member_state.inc
121
122 #Find which member is the donor
123 --let $m3_saved_file= $m1_saved_file
124 --let $m3_saved_pos= $m1_saved_pos
125 if (`SELECT COUNT(*)=1 FROM performance_schema.replication_connection_status WHERE channel_name='group_replication_recovery' AND service_state='ON' AND source_uuid='$server2_uuid'`)
126 {
127 --let $m3_saved_file= $m2_saved_file
128 --let $m3_saved_pos= $m2_saved_pos
129 }
130
131 # Use SOURCE_POS_WAIT() for a server which is getting added and
132 # wait till it synchs to certain position.
133 # Result log has been disabled because, it prints the difference of positions synced.
134 # which may not be same across different runs
135 --disable_result_log
136 --replace_result $m3_saved_pos SAVED_POS
137 --eval SELECT SOURCE_POS_WAIT('$m3_saved_file',$m3_saved_pos, 0,'group_replication_recovery')
138 --enable_result_log
139
140 --let $rpl_connection_name= server1
141 --source include/rpl_connection.inc
142 SET DEBUG_SYNC = "now WAIT_FOR applier_read_blocked";
143 SET @@GLOBAL.DEBUG='-d,block_applier_updates';
144 SET DEBUG_SYNC = "now SIGNAL resume_applier_read";
145
146 --let $rpl_connection_name= server2
147 --source include/rpl_connection.inc
148 SET DEBUG_SYNC = "now WAIT_FOR applier_read_blocked";
149 SET @@GLOBAL.DEBUG='-d,block_applier_updates';
150 SET DEBUG_SYNC = "now SIGNAL resume_applier_read";
151
152
153 # Stop the group replication
154 --let $rpl_connection_name= server3
155 --source include/rpl_connection.inc
156 --source include/stop_group_replication.inc
157
158 # Calling SOURCE_POS_WAIT in error cases, It should return NULL for both the calls
159 --replace_result $m3_saved_pos SAVED_POS
160 --eval SELECT SOURCE_POS_WAIT('$m3_saved_file',$m3_saved_pos, 0,'group_replication_recovery')
161 --replace_result $m3_saved_pos SAVED_POS
162 --eval SELECT SOURCE_POS_WAIT('$m3_saved_file',$m3_saved_pos, 2,'group_replication_applier')
163
164 # Connect to server2 and create table and perform insert
165 --echo
166 --let $rpl_connection_name= server2
167 --source include/rpl_connection.inc
168 CREATE TABLE test.t2 ( a int primary key);
169
170 --source include/rpl_sync.inc
171 --disable_query_log
172 --let $i=50
173 while($i)
174 {
175 --EVAL INSERT INTO t2 VALUES ($i)
176 --dec $i
177 }
178 --enable_query_log
179 --source include/rpl_sync.inc
180
181 --let $rpl_connection_name= server1
182 --source include/rpl_connection.inc
183 SET @@GLOBAL.DEBUG='+d,block_applier_updates';
184
185 --let $rpl_connection_name= server2
186 --source include/rpl_connection.inc
187 SET @@GLOBAL.DEBUG='+d,block_applier_updates';
188
189 --let $rpl_connection_name= server3
190 --source include/rpl_connection.inc
191 --replace_result $group_replication_group_name GROUP_REPLICATION_GROUP_NAME
192 --eval SET GLOBAL group_replication_group_name= "$group_replication_group_name"
193 --source include/start_group_replication_command.inc
194
195 # Make sure that recovery channel is created
196 --let $wait_condition= SELECT COUNT(*)=1 FROM performance_schema.replication_connection_status where CHANNEL_NAME="group_replication_recovery" and SERVICE_STATE="ON"
197 --source include/wait_condition.inc
198
199 --let $group_replication_member_state= RECOVERING
200 --source include/gr_wait_for_member_state.inc
201
202 # Call and wait for 20 seconds, for gtid set to reach 126 using WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS()
203 # Result log has been disabled because, it prints the difference of gtids synced.
204 # which may not be same across different runs
205
206 --disable_result_log
207 --replace_result $group_replication_group_name GROUP_REPLICATION_GROUP_NAME
208 eval SELECT WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS("$group_replication_group_name:126", 20, "group_replication_recovery");
209 --enable_result_log
210
211 # Call and wait for 10 seconds, for gtid set to reach 136 using WAIT_FOR_EXECUTED_GTID_SET()
212 --disable_result_log
213 --replace_result $group_replication_group_name GROUP_REPLICATION_GROUP_NAME
214 eval SELECT WAIT_FOR_EXECUTED_GTID_SET('$group_replication_group_name:1-136',10);
215 --enable_result_log
216
217 # This call should wait for gtid set to reach 155(wait_time 0 means, wait for
218 # infinite time till the gtid values is reached)
219
220 # Result log has been disabled because, it prints the difference of gtids synced.
221 # which may not be same across different runs
222 --disable_result_log
223 --replace_result $group_replication_group_name GROUP_REPLICATION_GROUP_NAME
224 eval SELECT WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS("$group_replication_group_name:1-155", 0, "group_replication_recovery");
225 --enable_result_log
226
227 # Check the gtid executed using WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS on group
228 --replace_result $group_replication_group_name GROUP_REPLICATION_GROUP_NAME
229 eval SELECT WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS("$group_replication_group_name:1-155", 10, "group_replication_applier");
230
231 # Resume appliers on server1 and server2 to assist server3 come out of recovery
232 # Wait till all the servers are online
233 --let $rpl_connection_name= server1
234 --source include/rpl_connection.inc
235 SET DEBUG_SYNC = "now WAIT_FOR applier_read_blocked";
236 SET @@GLOBAL.DEBUG='-d,block_applier_updates';
237 SET DEBUG_SYNC = "now SIGNAL resume_applier_read";
238
239 --let $rpl_connection_name= server2
240 --source include/rpl_connection.inc
241 SET DEBUG_SYNC = "now WAIT_FOR applier_read_blocked";
242 SET @@GLOBAL.DEBUG='-d,block_applier_updates';
243 SET DEBUG_SYNC = "now SIGNAL resume_applier_read";
244
245 --let $rpl_connection_name= server3
246 --source include/rpl_connection.inc
247 let $wait_condition=
248 SELECT COUNT(*)=3 FROM performance_schema.replication_group_members where MEMBER_STATE="ONLINE";
249 --source include/wait_condition.inc
250
251 # Validate the record count in server3
252 --let $assert_text= 'Checking the number of records in test.t1'
253 --let $assert_cond= [SELECT COUNT(*) as count FROM test.t1,count, 1] = 100
254 --source include/assert.inc
255
256 --let $assert_text= 'Checking the number of records in test.t2'
257 --let $assert_cond= [SELECT COUNT(*) as count FROM test.t2,count, 1] = 50
258 --source include/assert.inc
259
260 # Validate the record count in server2
261 --let $rpl_connection_name= server2
262 --source include/rpl_connection.inc
263 --let $assert_text= 'Checking the number of records in test.t1'
264 --let $assert_cond= [SELECT COUNT(*) as count FROM test.t1,count, 1] = 100
265 --source include/assert.inc
266
267 --let $assert_text= 'Checking the number of records in test.t2'
268 --let $assert_cond= [SELECT COUNT(*) as count FROM test.t2,count, 1] = 50
269 --source include/assert.inc
270
271 # Cleanup
272 --echo ## Cleanup ##
273 --let $rpl_connection_name= server1
274 --source include/rpl_connection.inc
275 SET DEBUG_SYNC= 'RESET';
276
277 --let $rpl_connection_name= server2
278 --source include/rpl_connection.inc
279 SET DEBUG_SYNC= 'RESET';
280 DROP TABLE test.t1;
281 DROP TABLE test.t2;
282
283 --let $slave_timeout= 120
284 --source include/rpl_sync.inc
285
286 --source include/group_replication_end.inc
287