| 1 |
############################################################################### |
| 2 |
# |
| 3 |
# When switching to a primary server or changing mode to single primary |
| 4 |
# with an appointed primary, P, if P leaves or fails under a majority, |
| 5 |
# before the election starts, the configuration change must abort. |
| 6 |
# |
| 7 |
# Test: |
| 8 |
# 0. This test requires three servers |
| 9 |
# 1. Multi Primary |
| 10 |
# 1.1. On server1 enable group_replication_block_group_action debug |
| 11 |
# point |
| 12 |
# 1.2. On server2 execute action to change to single primary with |
| 13 |
# server1 as primary |
| 14 |
# 1.3. Verify that server2 is checking group pre-conditions |
| 15 |
# 1.4. Kill and restart server1 |
| 16 |
# 1.5. Reap action to switch to single primary and it returns error as |
| 17 |
# server1 was killed |
| 18 |
# 1.6. Add suppression on server3 for action failure |
| 19 |
# 1.7. Confirm that group replication is on Multi primary server |
| 20 |
# 1.8. Cleanup to run Single Primary test |
| 21 |
# |
| 22 |
# 2. Single Primary |
| 23 |
# 2.1. Execute action to switch to single primary with server1 as |
| 24 |
# primary |
| 25 |
# 2.2. Create table on Group Replication |
| 26 |
# 2.3. Begin a transaction on server1 |
| 27 |
# 2.4. Execute action to set as primary server2 |
| 28 |
# 2.5. Verify server is waiting for pending transactions to finish in |
| 29 |
# order to conclude action |
| 30 |
# 2.6. Kill and restart server2, it would be the new primary |
| 31 |
# 2.7. Verify the action executed on server1 failed, server selected |
| 32 |
# exited from the group |
| 33 |
# 2.8. Assert server1 is the new primary |
| 34 |
# 2.9. Cleanup |
| 35 |
# |
| 36 |
############################################################################### |
| 37 |
|
| 38 |
--source include/big_test.inc |
| 39 |
--source include/have_debug.inc |
| 40 |
--source include/have_group_replication_plugin.inc |
| 41 |
--source include/not_valgrind.inc |
| 42 |
--let $rpl_server_count= 3 |
| 43 |
--source include/group_replication.inc |
| 44 |
|
| 45 |
|
| 46 |
--echo |
| 47 |
--echo # 1. Multi Primary |
| 48 |
|
| 49 |
--echo |
| 50 |
--echo # 1.1. On server1 enable group_replication_block_group_action debug |
| 51 |
--echo # point |
| 52 |
|
| 53 |
SET @@GLOBAL.DEBUG= '+d,group_replication_block_group_action'; |
| 54 |
--let $server1_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1) |
| 55 |
|
| 56 |
set session sql_log_bin=0; |
| 57 |
call mtr.add_suppression("The function 'group_replication_set_as_primary' failed. Primary assigned for election left the group, this operation will be aborted*"); |
| 58 |
set session sql_log_bin=1; |
| 59 |
|
| 60 |
--echo |
| 61 |
--echo # 1.2. On server2 execute action to change to single primary with |
| 62 |
--echo # server1 as primary |
| 63 |
|
| 64 |
--let $rpl_connection_name= server2 |
| 65 |
--source include/rpl_connection.inc |
| 66 |
|
| 67 |
--let $server2_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1) |
| 68 |
|
| 69 |
set session sql_log_bin=0; |
| 70 |
call mtr.add_suppression("The function 'group_replication_switch_to_single_primary_mode' failed. Primary assigned for election left the group, this operation will be aborted."); |
| 71 |
set session sql_log_bin=1; |
| 72 |
|
| 73 |
--replace_result $server1_uuid MEMBER1_UUID |
| 74 |
--send_eval SELECT group_replication_switch_to_single_primary_mode("$server1_uuid") |
| 75 |
|
| 76 |
--echo |
| 77 |
--echo # 1.3. Verify that server2 is checking group pre-conditions |
| 78 |
|
| 79 |
--let $rpl_connection_name= server_2 |
| 80 |
--source include/rpl_connection.inc |
| 81 |
|
| 82 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Single-primary Switch: checking%" |
| 83 |
--source include/wait_condition.inc |
| 84 |
|
| 85 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%stage/group_rpl%" AND event_name NOT LIKE "%stage/group_rpl/Group Replication%";` |
| 86 |
--let $assert_text= stage/group_rpl/Single-primary Switch: checking group pre-conditions |
| 87 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Single-primary Switch: checking group pre-conditions" |
| 88 |
--source include/assert.inc |
| 89 |
|
| 90 |
--echo |
| 91 |
--echo # 1.4. Kill and restart server1 |
| 92 |
|
| 93 |
--let $rpl_connection_name= server_1 |
| 94 |
--source include/rpl_connection.inc |
| 95 |
|
| 96 |
--let $group_replication_local_address= `SELECT @@GLOBAL.group_replication_local_address` |
| 97 |
--let $group_replication_group_seeds= `SELECT @@GLOBAL.group_replication_group_seeds` |
| 98 |
--let $restart_parameters=restart:--group_replication_local_address=$group_replication_local_address --group_replication_group_seeds=$group_replication_group_seeds --group_replication_group_name=$group_replication_group_name |
| 99 |
--replace_result $group_replication_local_address GROUP_REPLICATION_LOCAL_ADDRESS $group_replication_group_seeds GROUP_REPLICATION_GROUP_SEEDS $group_replication_group_name GROUP_REPLICATION_GROUP_NAME |
| 100 |
--source include/kill_and_restart_mysqld.inc |
| 101 |
|
| 102 |
--let $rpl_server_number= 1 |
| 103 |
--source include/rpl_reconnect.inc |
| 104 |
|
| 105 |
--echo |
| 106 |
--echo # 1.5. Reap action to switch to single primary and it returns error as |
| 107 |
--echo # server1 was killed |
| 108 |
|
| 109 |
--let $rpl_connection_name= server2 |
| 110 |
--source include/rpl_connection.inc |
| 111 |
|
| 112 |
--error ER_GRP_RPL_UDF_ERROR |
| 113 |
--reap |
| 114 |
|
| 115 |
--echo |
| 116 |
--echo # 1.6. Add suppression on server3 for action failure |
| 117 |
|
| 118 |
--let $rpl_connection_name= server3 |
| 119 |
--source include/rpl_connection.inc |
| 120 |
|
| 121 |
set session sql_log_bin=0; |
| 122 |
call mtr.add_suppression("Error while executing a group configuration operation: Primary assigned for election left the group, this operation will be aborted."); |
| 123 |
set session sql_log_bin=1; |
| 124 |
|
| 125 |
--echo |
| 126 |
--echo # 1.7. Confirm that group replication is on Multi primary server |
| 127 |
|
| 128 |
--source include/gr_assert_multi_primary_mode.inc |
| 129 |
|
| 130 |
--let $rpl_connection_name= server2 |
| 131 |
--source include/rpl_connection.inc |
| 132 |
|
| 133 |
--source include/gr_assert_multi_primary_mode.inc |
| 134 |
|
| 135 |
--echo |
| 136 |
--echo # 1.8. Cleanup to run Single Primary test |
| 137 |
|
| 138 |
--let $rpl_connection_name= server1 |
| 139 |
--source include/rpl_connection.inc |
| 140 |
|
| 141 |
--source include/start_group_replication.inc |
| 142 |
|
| 143 |
--echo |
| 144 |
--echo # 2. Single Primary |
| 145 |
|
| 146 |
--echo |
| 147 |
--echo # 2.1. Execute action to switch to single primary with server1 as |
| 148 |
--echo # primary |
| 149 |
|
| 150 |
--replace_result $server1_uuid MEMBER1_UUID |
| 151 |
--eval SELECT group_replication_switch_to_single_primary_mode("$server1_uuid") |
| 152 |
|
| 153 |
--echo |
| 154 |
--echo # 2.2. Create table on Group Replication |
| 155 |
|
| 156 |
CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY , b INT); |
| 157 |
|
| 158 |
--echo |
| 159 |
--echo # 2.3. Begin a transaction on server1 |
| 160 |
|
| 161 |
BEGIN; |
| 162 |
INSERT INTO test.t1 (b) VALUES (1); |
| 163 |
|
| 164 |
--echo |
| 165 |
--echo # 2.4. Execute action to set as primary server2 |
| 166 |
|
| 167 |
--let $rpl_connection_name= server_1_1 |
| 168 |
--source include/rpl_connection.inc |
| 169 |
|
| 170 |
--replace_result $server2_uuid MEMBER2_UUID |
| 171 |
--send_eval SELECT group_replication_set_as_primary("$server2_uuid") |
| 172 |
|
| 173 |
--echo |
| 174 |
--echo # 2.5. Verify server is waiting for pending transactions to finish in |
| 175 |
--echo # order to conclude action |
| 176 |
|
| 177 |
--let $rpl_connection_name= server_1 |
| 178 |
--source include/rpl_connection.inc |
| 179 |
|
| 180 |
#Give it time so the select doesn't appear in the result |
| 181 |
--sleep 2 |
| 182 |
|
| 183 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%stage/group_rpl%" AND event_name NOT LIKE "%stage/group_rpl/Group Replication%";` |
| 184 |
--let $assert_text= stage/group_rpl/Primary Switch: waiting for pending transactions to finish |
| 185 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Switch: waiting for pending transactions to finish" |
| 186 |
--source include/assert.inc |
| 187 |
|
| 188 |
#The UDF execution query is not taken into account. |
| 189 |
--let $work_estimated= `SELECT work_estimated FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Switch:%";` |
| 190 |
--let $assert_text= The estimated work is 1 |
| 191 |
--let $assert_cond= "$work_estimated" = "1" |
| 192 |
--source include/assert.inc |
| 193 |
|
| 194 |
--let $work_completed= `SELECT work_completed FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Switch:%";` |
| 195 |
--let $assert_text= The completed work is 0 |
| 196 |
--let $assert_cond= "$work_completed" = "0" |
| 197 |
--source include/assert.inc |
| 198 |
|
| 199 |
--echo |
| 200 |
--echo # 2.6. Kill and restart server2, it would be the new primary |
| 201 |
|
| 202 |
--let $rpl_connection_name= server2 |
| 203 |
--source include/rpl_connection.inc |
| 204 |
|
| 205 |
--let $group_replication_local_address= `SELECT @@GLOBAL.group_replication_local_address` |
| 206 |
--let $group_replication_group_seeds= `SELECT @@GLOBAL.group_replication_group_seeds` |
| 207 |
--let $restart_parameters=restart:--group_replication_local_address=$group_replication_local_address --group_replication_group_seeds=$group_replication_group_seeds --group_replication_group_name=$group_replication_group_name |
| 208 |
--replace_result $group_replication_local_address GROUP_REPLICATION_LOCAL_ADDRESS $group_replication_group_seeds GROUP_REPLICATION_GROUP_SEEDS $group_replication_group_name GROUP_REPLICATION_GROUP_NAME |
| 209 |
--source include/kill_and_restart_mysqld.inc |
| 210 |
|
| 211 |
--let $rpl_server_number= 2 |
| 212 |
--source include/rpl_reconnect.inc |
| 213 |
|
| 214 |
--echo |
| 215 |
--echo # 2.7. Verify the action executed on server1 failed, server selected |
| 216 |
--echo # exited from the group |
| 217 |
|
| 218 |
--let $rpl_connection_name= server_1_1 |
| 219 |
--source include/rpl_connection.inc |
| 220 |
|
| 221 |
--error ER_GRP_RPL_UDF_ERROR |
| 222 |
--reap |
| 223 |
|
| 224 |
--echo |
| 225 |
--echo # 2.8. Assert server1 is the new primary |
| 226 |
|
| 227 |
--source include/gr_assert_primary_member.inc |
| 228 |
|
| 229 |
--echo |
| 230 |
--echo # 2.9. Cleanup |
| 231 |
|
| 232 |
--let $rpl_connection_name= server1 |
| 233 |
--source include/rpl_connection.inc |
| 234 |
|
| 235 |
COMMIT; |
| 236 |
|
| 237 |
DROP TABLE t1; |
| 238 |
|
| 239 |
--let $rpl_connection_name= server2 |
| 240 |
--source include/rpl_connection.inc |
| 241 |
|
| 242 |
DROP TABLE t1; |
| 243 |
|
| 244 |
--let $rpl_group_replication_single_primary_mode=1 |
| 245 |
--let $rpl_group_replication_reset_persistent_vars=1 |
| 246 |
--source include/group_replication_end.inc |