| 1 |
############################################################################### |
| 2 |
# |
| 3 |
# When switching to a primary server, P, if P leaves or fails under a majority, |
| 4 |
# when the primary election began but is not yet over, the configuration change |
| 5 |
# will abort and the old primary will be elected if available. |
| 6 |
# If not another member will be elected. |
| 7 |
# |
| 8 |
# Test: |
| 9 |
# 0. This test needs three servers |
| 10 |
# 1. Start single primary group and create table |
| 11 |
# 2. Disable read only to action be stuck on setting read only |
| 12 |
# 3. Go to a member that will be a secondary and lock a table |
| 13 |
# 4. Insert a row on the old primary |
| 14 |
# 5. Execute action to change primary to server2 |
| 15 |
# 6. Check that the other members are waiting for members to be in |
| 16 |
# super_read_only and executing primary election |
| 17 |
# 7. Stop the new primary server1 |
| 18 |
# 8. Wait group detect exit of server1 |
| 19 |
# 9. Unlock table on server3 |
| 20 |
# 10. Reap insertion of data on server2 |
| 21 |
# 11. Check that the action returns failure |
| 22 |
# 12. Confirm server2 is the new primary because it was the old primary |
| 23 |
# 13. Clean up |
| 24 |
# |
| 25 |
############################################################################### |
| 26 |
|
| 27 |
|
| 28 |
--source include/big_test.inc |
| 29 |
--source include/have_group_replication_plugin.inc |
| 30 |
--let $rpl_server_count= 3 |
| 31 |
--let $rpl_skip_group_replication_start= 1 |
| 32 |
--let $rpl_group_replication_single_primary_mode=1 |
| 33 |
--source include/group_replication.inc |
| 34 |
|
| 35 |
--echo |
| 36 |
--echo # 1. Start single primary group and create table |
| 37 |
|
| 38 |
--source include/start_and_bootstrap_group_replication.inc |
| 39 |
|
| 40 |
--let $server1_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1) |
| 41 |
|
| 42 |
CREATE TABLE test.t1 (a INT PRIMARY KEY); |
| 43 |
|
| 44 |
--source include/rpl_sync.inc |
| 45 |
|
| 46 |
--let $rpl_connection_name= server2 |
| 47 |
--source include/rpl_connection.inc |
| 48 |
--source include/start_group_replication.inc |
| 49 |
|
| 50 |
--let $server2_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1) |
| 51 |
|
| 52 |
--echo |
| 53 |
--echo # 2. Disable read only to action be stuck on setting read only |
| 54 |
|
| 55 |
--let $rpl_connection_name= server3 |
| 56 |
--source include/rpl_connection.inc |
| 57 |
|
| 58 |
set session sql_log_bin=0; |
| 59 |
call mtr.add_suppression("The function 'group_replication_set_as_primary' failed. The appointed primary for election left the group, this operation will be aborted*"); |
| 60 |
set session sql_log_bin=1; |
| 61 |
|
| 62 |
--source include/start_group_replication.inc |
| 63 |
|
| 64 |
SET GLOBAL read_only= 0; |
| 65 |
|
| 66 |
--echo |
| 67 |
--echo # 3. Go to a member that will be a secondary and lock a table |
| 68 |
|
| 69 |
--let $rpl_connection_name= server_3 |
| 70 |
--source include/rpl_connection.inc |
| 71 |
|
| 72 |
LOCK TABLE t1 READ; |
| 73 |
|
| 74 |
--echo |
| 75 |
--echo # 4. Insert a row on the old primary |
| 76 |
|
| 77 |
--let $rpl_connection_name= server1 |
| 78 |
--source include/rpl_connection.inc |
| 79 |
|
| 80 |
--send INSERT INTO t1 VALUES (1) |
| 81 |
|
| 82 |
--let $rpl_connection_name= server2 |
| 83 |
--source include/rpl_connection.inc |
| 84 |
|
| 85 |
--let $wait_condition=SELECT COUNT(*)=1 FROM test.t1 |
| 86 |
--source include/wait_condition.inc |
| 87 |
|
| 88 |
--echo |
| 89 |
--echo # 5. Execute action to change primary to server2 |
| 90 |
|
| 91 |
--let $rpl_connection_name= server3 |
| 92 |
--source include/rpl_connection.inc |
| 93 |
|
| 94 |
--replace_result $server2_uuid MEMBER2_UUID |
| 95 |
--send_eval SELECT group_replication_set_as_primary("$server2_uuid") |
| 96 |
|
| 97 |
--echo |
| 98 |
--echo # 6. Check that the other members are waiting for members to be in |
| 99 |
--echo # super_read_only and executing primary election |
| 100 |
|
| 101 |
--let $rpl_connection_name= server_2 |
| 102 |
--source include/rpl_connection.inc |
| 103 |
|
| 104 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election: waiting for members to enable super_read_only%" |
| 105 |
--source include/wait_condition.inc |
| 106 |
|
| 107 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "stage/group_rpl/Primary Switch: executing Primary election" |
| 108 |
--source include/wait_condition.inc |
| 109 |
|
| 110 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%stage/group_rpl/Primary Election%";` |
| 111 |
--let $assert_text= stage/group_rpl/Primary Election: waiting for members to enable super_read_only |
| 112 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Election: waiting for members to enable super_read_only" |
| 113 |
--source include/assert.inc |
| 114 |
|
| 115 |
--echo |
| 116 |
--echo # 7. Stop the new primary server2 |
| 117 |
|
| 118 |
--let $rpl_connection_name= server2 |
| 119 |
--source include/rpl_connection.inc |
| 120 |
|
| 121 |
--source include/stop_group_replication.inc |
| 122 |
|
| 123 |
--echo |
| 124 |
--echo # 8. Wait group detect exit of server2 |
| 125 |
|
| 126 |
--let $rpl_connection_name= server_1 |
| 127 |
--source include/rpl_connection.inc |
| 128 |
|
| 129 |
--let $group_replication_number_of_members= 2 |
| 130 |
--source include/gr_wait_for_number_of_members.inc |
| 131 |
|
| 132 |
--echo |
| 133 |
--echo # 9. Unlock table on server3 |
| 134 |
|
| 135 |
--let $rpl_connection_name= server_3 |
| 136 |
--source include/rpl_connection.inc |
| 137 |
|
| 138 |
UNLOCK TABLES; |
| 139 |
|
| 140 |
--echo |
| 141 |
--echo # 10. Reap insertion of data on server1 |
| 142 |
|
| 143 |
--let $rpl_connection_name= server1 |
| 144 |
--source include/rpl_connection.inc |
| 145 |
|
| 146 |
--reap |
| 147 |
|
| 148 |
--echo |
| 149 |
--echo # 11. Check that the action returns failure |
| 150 |
|
| 151 |
--let $rpl_connection_name= server3 |
| 152 |
--source include/rpl_connection.inc |
| 153 |
|
| 154 |
--error ER_GRP_RPL_UDF_ERROR |
| 155 |
--reap |
| 156 |
|
| 157 |
--echo |
| 158 |
--echo # 12. Confirm server1 is the new primary because it was the old primary |
| 159 |
|
| 160 |
--let $rpl_connection_name= server1 |
| 161 |
--source include/rpl_connection.inc |
| 162 |
|
| 163 |
--source include/gr_assert_primary_member.inc |
| 164 |
|
| 165 |
set session sql_log_bin=0; |
| 166 |
call mtr.add_suppression("Error while executing a group configuration operation: The appointed primary for election left the group, this operation will be aborted.*"); |
| 167 |
set session sql_log_bin=1; |
| 168 |
|
| 169 |
--echo |
| 170 |
--echo # 13. Clean up |
| 171 |
|
| 172 |
DROP TABLE t1; |
| 173 |
|
| 174 |
--let $rpl_connection_name= server2 |
| 175 |
--source include/rpl_connection.inc |
| 176 |
|
| 177 |
set session sql_log_bin=0; |
| 178 |
call mtr.add_suppression("Error while executing a group configuration operation: This operation was locally aborted and for that reason terminated."); |
| 179 |
set session sql_log_bin=1; |
| 180 |
|
| 181 |
--source include/start_group_replication.inc |
| 182 |
|
| 183 |
|
| 184 |
--let $rpl_group_replication_single_primary_mode=1 |
| 185 |
--let $rpl_group_replication_reset_persistent_vars=1 |
| 186 |
--source include/group_replication_end.inc |