| 1 |
############################################################################## |
| 2 |
# |
| 3 |
# All actions shall allow the DBA to check its progress. |
| 4 |
# |
| 5 |
# Test: |
| 6 |
# 0. 2 servers. Test starts in Single primary mode with server1 as the primary |
| 7 |
# |
| 8 |
# Phase 1: Online Primary Change |
| 9 |
# 1.1 Lock table on the new primary (server 2) and get a transaction stuck |
| 10 |
# Execute a primary change to server 2. |
| 11 |
# Check the new primary is in the applying buffered transactions stage |
| 12 |
# Others are in waiting on current primary transaction execution stage |
| 13 |
# 1.2 Lock a table on the old primary (server1) and execute a transaction |
| 14 |
# This will block the read mode enabling query on the now secondary |
| 15 |
# Unblock the table on the new primary (server2) |
| 16 |
# Check election is on Waiting for members to enable super_read_only stage |
| 17 |
# 1.3 Lock table on the new primary (server 2) |
| 18 |
# Unlock the table on the secondary (server1) that will block on server2 |
| 19 |
# Check election is on Stabilizing transactions from former primaries stage |
| 20 |
# 1.4 Unblock to end the action. |
| 21 |
# |
| 22 |
# Phase 2: Failover elections |
| 23 |
# 2.0 Set the weights so server 1 is the new primary when server 2 leaves. |
| 24 |
# Lock a table on the new primary (server1) |
| 25 |
# 2.1 Execute a transaction that will be stuck on server1 |
| 26 |
# Stop server 2 so it leaves the group and a new election happens |
| 27 |
# Check the election stage on the new primary: applying buffered transactions |
| 28 |
# Check the election stage on secondary: waiting on current primary transaction execution |
| 29 |
# 2.2 Unblock the table |
| 30 |
# Check the election ends and there are no more stages. |
| 31 |
# |
| 32 |
# 3. Cleanup |
| 33 |
# |
| 34 |
############################################################################## |
| 35 |
|
| 36 |
--source include/big_test.inc |
| 37 |
--source include/have_group_replication_plugin.inc |
| 38 |
--let $rpl_skip_group_replication_start= 1 |
| 39 |
--let $rpl_group_replication_single_primary_mode=1 |
| 40 |
--let $rpl_server_count= 3 |
| 41 |
--source include/group_replication.inc |
| 42 |
|
| 43 |
--echo |
| 44 |
--echo # 0. Test starts in Single primary mode with server1 as the primary |
| 45 |
|
| 46 |
--let $server1_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1) |
| 47 |
|
| 48 |
--source include/start_and_bootstrap_group_replication.inc |
| 49 |
|
| 50 |
--source include/gr_assert_primary_member.inc |
| 51 |
|
| 52 |
CREATE TABLE t1(a int primary key); |
| 53 |
|
| 54 |
--let $rpl_connection_name= server2 |
| 55 |
--source include/rpl_connection.inc |
| 56 |
|
| 57 |
--let $server2_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1) |
| 58 |
|
| 59 |
--source include/start_group_replication.inc |
| 60 |
|
| 61 |
--let $rpl_connection_name= server3 |
| 62 |
--source include/rpl_connection.inc |
| 63 |
|
| 64 |
--source include/start_group_replication.inc |
| 65 |
|
| 66 |
--echo |
| 67 |
--echo # 1.1 Lock table on the new primary (server 2) and get a transaction stuck |
| 68 |
--echo # Execute a primary change to server 2. |
| 69 |
--echo # Check the new primary is in the applying buffered transactions stage |
| 70 |
--echo # Others are in waiting on current primary transaction execution stage |
| 71 |
|
| 72 |
--let $rpl_connection_name= server_2 |
| 73 |
--source include/rpl_connection.inc |
| 74 |
|
| 75 |
SET @@GLOBAL.read_only= 0; |
| 76 |
LOCK TABLE t1 READ; |
| 77 |
|
| 78 |
--let $rpl_connection_name= server1 |
| 79 |
--source include/rpl_connection.inc |
| 80 |
|
| 81 |
INSERT INTO t1 VALUES (1); |
| 82 |
|
| 83 |
--replace_result $server2_uuid MEMBER2_UUID |
| 84 |
--send_eval SELECT group_replication_set_as_primary("$server2_uuid") |
| 85 |
|
| 86 |
--let $rpl_connection_name= server2 |
| 87 |
--source include/rpl_connection.inc |
| 88 |
|
| 89 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%" |
| 90 |
--source include/wait_condition.inc |
| 91 |
|
| 92 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%";` |
| 93 |
--let $assert_text= The stage should be "Primary Election: applying buffered transactions" |
| 94 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Election: applying buffered transactions" |
| 95 |
--source include/assert.inc |
| 96 |
|
| 97 |
--let $work_estimated= `SELECT work_estimated FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%";` |
| 98 |
--let $assert_text= The estimated work is 1 |
| 99 |
--let $assert_cond= "$work_estimated" = "1" |
| 100 |
--source include/assert.inc |
| 101 |
|
| 102 |
--let $work_completed= `SELECT work_completed FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%";` |
| 103 |
--let $assert_text= The completed work is 0 |
| 104 |
--let $assert_cond= "$work_completed" = "0" |
| 105 |
--source include/assert.inc |
| 106 |
|
| 107 |
--let $rpl_connection_name= server_1 |
| 108 |
--source include/rpl_connection.inc |
| 109 |
|
| 110 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%" |
| 111 |
--source include/wait_condition.inc |
| 112 |
|
| 113 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%";` |
| 114 |
--let $assert_text= The stage should be "Primary Election: waiting on current primary transaction execution" |
| 115 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Election: waiting on current primary transaction execution" |
| 116 |
--source include/assert.inc |
| 117 |
|
| 118 |
--let $work_estimated= `SELECT work_estimated FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%";` |
| 119 |
--let $assert_text= The estimated work is 1 |
| 120 |
--let $assert_cond= "$work_estimated" = "1" |
| 121 |
--source include/assert.inc |
| 122 |
|
| 123 |
--let $work_completed= `SELECT work_completed FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%";` |
| 124 |
--let $assert_text= The completed work is 0 |
| 125 |
--let $assert_cond= "$work_completed" = "0" |
| 126 |
--source include/assert.inc |
| 127 |
|
| 128 |
--echo |
| 129 |
--echo # 1.2 Lock a table on the old primary (server1) and execute a transaction |
| 130 |
--echo # This will block the read mode enabling query on the now secondary |
| 131 |
--echo # Unblock the table on the new primary (server2) |
| 132 |
--echo # Check they are on Waiting for members to enable super_read_only |
| 133 |
|
| 134 |
--let $rpl_connection_name= server_1 |
| 135 |
--source include/rpl_connection.inc |
| 136 |
|
| 137 |
LOCK TABLE t1 READ; |
| 138 |
|
| 139 |
--let $rpl_connection_name= server_1_1 |
| 140 |
--source include/rpl_connection.inc |
| 141 |
|
| 142 |
--send INSERT INTO t1 VALUES (2) |
| 143 |
|
| 144 |
--let $rpl_connection_name= server_2 |
| 145 |
--source include/rpl_connection.inc |
| 146 |
|
| 147 |
UNLOCK TABLES; |
| 148 |
|
| 149 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%super_read_only%" and work_completed=2 |
| 150 |
--source include/wait_condition.inc |
| 151 |
|
| 152 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%super_read_only%";` |
| 153 |
--let $assert_text= The stage should be "Primary Election: waiting for members to enable super_read_only" |
| 154 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Election: waiting for members to enable super_read_only" |
| 155 |
--source include/assert.inc |
| 156 |
|
| 157 |
--let $work_estimated= `SELECT work_estimated FROM performance_schema.events_stages_current WHERE event_name LIKE "%super_read_only%";` |
| 158 |
--let $assert_text= The estimated work is 3 |
| 159 |
--let $assert_cond= "$work_estimated" = "3" |
| 160 |
--source include/assert.inc |
| 161 |
|
| 162 |
--let $work_completed= `SELECT work_completed FROM performance_schema.events_stages_current WHERE event_name LIKE "%super_read_only%";` |
| 163 |
--let $assert_text= The completed work is 2 |
| 164 |
--let $assert_cond= "$work_completed" = "2" |
| 165 |
--source include/assert.inc |
| 166 |
|
| 167 |
# There is no stage on server1 as the read mode process un-sets the election thread stage. |
| 168 |
# So we use server 3 |
| 169 |
|
| 170 |
--let $rpl_connection_name= server3 |
| 171 |
--source include/rpl_connection.inc |
| 172 |
|
| 173 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%super_read_only%" and work_completed=2 |
| 174 |
--source include/wait_condition.inc |
| 175 |
|
| 176 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%super_read_only%";` |
| 177 |
--let $assert_text= The stage should be "Primary Election: waiting for members to enable super_read_only" |
| 178 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Election: waiting for members to enable super_read_only" |
| 179 |
--source include/assert.inc |
| 180 |
|
| 181 |
--let $work_estimated= `SELECT work_estimated FROM performance_schema.events_stages_current WHERE event_name LIKE "%super_read_only%";` |
| 182 |
--let $assert_text= The estimated work is 3 |
| 183 |
--let $assert_cond= "$work_estimated" = "3" |
| 184 |
--source include/assert.inc |
| 185 |
|
| 186 |
--let $work_completed= `SELECT work_completed FROM performance_schema.events_stages_current WHERE event_name LIKE "%super_read_only%";` |
| 187 |
--let $assert_text= The completed work is 2 |
| 188 |
--let $assert_cond= "$work_completed" = "2" |
| 189 |
--source include/assert.inc |
| 190 |
|
| 191 |
--echo |
| 192 |
--echo # 1.3 Lock table on the new primary (server 2) |
| 193 |
--echo # Unlock the table on the secondary (server1) that will block on server2 |
| 194 |
--echo # Check election is on Stabilizing transactions from former primaries stage |
| 195 |
|
| 196 |
--let $rpl_connection_name= server_2 |
| 197 |
--source include/rpl_connection.inc |
| 198 |
|
| 199 |
LOCK TABLE t1 READ; |
| 200 |
|
| 201 |
--let $rpl_connection_name= server_1 |
| 202 |
--source include/rpl_connection.inc |
| 203 |
|
| 204 |
UNLOCK TABLES; |
| 205 |
|
| 206 |
--let $rpl_connection_name= server_1_1 |
| 207 |
--source include/rpl_connection.inc |
| 208 |
|
| 209 |
--reap |
| 210 |
|
| 211 |
--let $rpl_connection_name= server2 |
| 212 |
--source include/rpl_connection.inc |
| 213 |
|
| 214 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Stabilizing transactions%" |
| 215 |
--source include/wait_condition.inc |
| 216 |
|
| 217 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%Stabilizing transactions%";` |
| 218 |
--let $assert_text= The stage should be "Primary Election: stabilizing transactions from former primaries" |
| 219 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Election: stabilizing transactions from former primaries" |
| 220 |
--source include/assert.inc |
| 221 |
|
| 222 |
--let $work_estimated= `SELECT work_estimated FROM performance_schema.events_stages_current WHERE event_name LIKE "%Stabilizing transactions%";` |
| 223 |
--let $assert_text= The estimated work is 1 |
| 224 |
--let $assert_cond= "$work_estimated" = "1" |
| 225 |
--source include/assert.inc |
| 226 |
|
| 227 |
--let $work_completed= `SELECT work_completed FROM performance_schema.events_stages_current WHERE event_name LIKE "%Stabilizing transactions%";` |
| 228 |
--let $assert_text= The completed work is 0 |
| 229 |
--let $assert_cond= "$work_completed" = "0" |
| 230 |
--source include/assert.inc |
| 231 |
|
| 232 |
--let $rpl_connection_name= server_1 |
| 233 |
--source include/rpl_connection.inc |
| 234 |
|
| 235 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Stabilizing transactions%" |
| 236 |
--source include/wait_condition.inc |
| 237 |
|
| 238 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%Stabilizing transactions%";` |
| 239 |
--let $assert_text= The stage should be "Primary Election: stabilizing transactions from former primaries" |
| 240 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Election: stabilizing transactions from former primaries" |
| 241 |
--source include/assert.inc |
| 242 |
|
| 243 |
--let $work_estimated= `SELECT work_estimated FROM performance_schema.events_stages_current WHERE event_name LIKE "%Stabilizing transactions%";` |
| 244 |
--let $assert_text= The estimated work is 1 |
| 245 |
--let $assert_cond= "$work_estimated" = "1" |
| 246 |
--source include/assert.inc |
| 247 |
|
| 248 |
--let $work_completed= `SELECT work_completed FROM performance_schema.events_stages_current WHERE event_name LIKE "%Stabilizing transactions%";` |
| 249 |
--let $assert_text= The completed work is 0 |
| 250 |
--let $assert_cond= "$work_completed" = "0" |
| 251 |
--source include/assert.inc |
| 252 |
|
| 253 |
--echo |
| 254 |
--echo # 1.4 Unblock to end the action. |
| 255 |
|
| 256 |
--let $rpl_connection_name= server_2 |
| 257 |
--source include/rpl_connection.inc |
| 258 |
|
| 259 |
UNLOCK TABLES; |
| 260 |
|
| 261 |
--let $rpl_connection_name= server1 |
| 262 |
--source include/rpl_connection.inc |
| 263 |
|
| 264 |
--replace_result $server2_uuid MEMBER2_UUID |
| 265 |
--reap |
| 266 |
|
| 267 |
--echo |
| 268 |
--echo # 2.0 Set the weights so server 1 is the new primary when server 2 leaves. |
| 269 |
--echo # Lock a table on the new primary (server1) |
| 270 |
|
| 271 |
--let $rpl_connection_name= server1 |
| 272 |
--source include/rpl_connection.inc |
| 273 |
|
| 274 |
# set member weight |
| 275 |
--eval SET GLOBAL group_replication_member_weight= 100 |
| 276 |
|
| 277 |
SET @@GLOBAL.read_only= 0; |
| 278 |
LOCK TABLE t1 READ; |
| 279 |
|
| 280 |
--let $rpl_connection_name= server3 |
| 281 |
--source include/rpl_connection.inc |
| 282 |
|
| 283 |
# set member weight |
| 284 |
--eval SET GLOBAL group_replication_member_weight= 1 |
| 285 |
|
| 286 |
--echo |
| 287 |
--echo # 2.1 Execute a transaction that will be stuck on server1 |
| 288 |
--echo # Stop server 2 so it leaves the group and a new election happens |
| 289 |
--echo # Check the election stage on the new primary: applying buffered transactions |
| 290 |
--echo # Check the election stage on secondary: waiting on current primary transaction execution |
| 291 |
|
| 292 |
--let $rpl_connection_name= server2 |
| 293 |
--source include/rpl_connection.inc |
| 294 |
|
| 295 |
INSERT INTO t1 VALUES (3); |
| 296 |
|
| 297 |
--source include/stop_group_replication.inc |
| 298 |
|
| 299 |
--let $rpl_connection_name= server_1 |
| 300 |
--source include/rpl_connection.inc |
| 301 |
|
| 302 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%" |
| 303 |
--source include/wait_condition.inc |
| 304 |
|
| 305 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%";` |
| 306 |
--let $assert_text= The stage should be "Primary Election: applying buffered transactions" |
| 307 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Election: applying buffered transactions" |
| 308 |
--source include/assert.inc |
| 309 |
|
| 310 |
--let $work_estimated= `SELECT work_estimated FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%";` |
| 311 |
--let $assert_text= The estimated work is 1 |
| 312 |
--let $assert_cond= "$work_estimated" = "1" |
| 313 |
--source include/assert.inc |
| 314 |
|
| 315 |
--let $work_completed= `SELECT work_completed FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%";` |
| 316 |
--let $assert_text= The completed work is 0 |
| 317 |
--let $assert_cond= "$work_completed" = "0" |
| 318 |
--source include/assert.inc |
| 319 |
|
| 320 |
--let $rpl_connection_name= server3 |
| 321 |
--source include/rpl_connection.inc |
| 322 |
|
| 323 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%" |
| 324 |
--source include/wait_condition.inc |
| 325 |
|
| 326 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%";` |
| 327 |
--let $assert_text= The stage should be "Primary Election: waiting on current primary transaction execution" |
| 328 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Election: waiting on current primary transaction execution" |
| 329 |
--source include/assert.inc |
| 330 |
|
| 331 |
--let $work_estimated= `SELECT work_estimated FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%";` |
| 332 |
--let $assert_text= The estimated work is 1 |
| 333 |
--let $assert_cond= "$work_estimated" = "1" |
| 334 |
--source include/assert.inc |
| 335 |
|
| 336 |
--let $work_completed= `SELECT work_completed FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election:%";` |
| 337 |
--let $assert_text= The completed work is 0 |
| 338 |
--let $assert_cond= "$work_completed" = "0" |
| 339 |
--source include/assert.inc |
| 340 |
|
| 341 |
--echo |
| 342 |
--echo # 2.2 Unblock the table |
| 343 |
--echo # Check the election ends and there are no more stages. |
| 344 |
|
| 345 |
--let $rpl_connection_name= server1 |
| 346 |
--source include/rpl_connection.inc |
| 347 |
|
| 348 |
UNLOCK TABLES; |
| 349 |
|
| 350 |
--source include/gr_assert_primary_member.inc |
| 351 |
|
| 352 |
#Stages sometimes linger for a brief time after the action terminated |
| 353 |
--let $wait_condition=SELECT COUNT(*)=0 FROM performance_schema.events_stages_current WHERE event_name LIKE "%stage/group_rpl%" AND event_name NOT LIKE "%stage/group_rpl/Group Replication%" |
| 354 |
--source include/wait_condition.inc |
| 355 |
|
| 356 |
--let $stages_present= `SELECT COUNT(*) FROM performance_schema.events_stages_current WHERE event_name LIKE "%stage/group_rpl%" AND event_name NOT LIKE "%stage/group_rpl/Group Replication%";` |
| 357 |
--let $assert_text= There is no stage present |
| 358 |
--let $assert_cond= "$stages_present" = "0" |
| 359 |
--source include/assert.inc |
| 360 |
|
| 361 |
--let $rpl_connection_name= server3 |
| 362 |
--source include/rpl_connection.inc |
| 363 |
|
| 364 |
#Stages sometimes linger for a brief time after the action terminated |
| 365 |
--let $wait_condition=SELECT COUNT(*)=0 FROM performance_schema.events_stages_current WHERE event_name LIKE "%stage/group_rpl%" AND event_name NOT LIKE "%stage/group_rpl/Group Replication%" |
| 366 |
--source include/wait_condition.inc |
| 367 |
|
| 368 |
--let $stages_present= `SELECT COUNT(*) FROM performance_schema.events_stages_current WHERE event_name LIKE "%stage/group_rpl%" AND event_name NOT LIKE "%stage/group_rpl/Group Replication%";` |
| 369 |
--let $assert_text= There is no stage present |
| 370 |
--let $assert_cond= "$stages_present" = "0" |
| 371 |
--source include/assert.inc |
| 372 |
|
| 373 |
--echo |
| 374 |
--echo # 3. Clean up |
| 375 |
|
| 376 |
--let $rpl_connection_name= server2 |
| 377 |
--source include/rpl_connection.inc |
| 378 |
|
| 379 |
--source include/start_group_replication.inc |
| 380 |
|
| 381 |
--let $rpl_connection_name= server1 |
| 382 |
--source include/rpl_connection.inc |
| 383 |
|
| 384 |
SET @@GLOBAL.group_replication_member_weight= DEFAULT; |
| 385 |
|
| 386 |
DROP TABLE t1; |
| 387 |
|
| 388 |
--let $rpl_connection_name= server3 |
| 389 |
--source include/rpl_connection.inc |
| 390 |
|
| 391 |
SET @@GLOBAL.group_replication_member_weight= DEFAULT; |
| 392 |
|
| 393 |
--let $rpl_group_replication_reset_persistent_vars=1 |
| 394 |
--source include/group_replication_end.inc |