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