| 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 |
# after the election finalizes, change terminates and the |
| 6 |
# group elects a new primary. A warning is thrown to the user. |
| 7 |
# |
| 8 |
# When the plugin is stopped or leaves in error, while changing |
| 9 |
# from multi primary mode to single primary mode, if the member did |
| 10 |
# already set the single primary mode flag to true, then update |
| 11 |
# everywhere checks shall be false after stop. |
| 12 |
# |
| 13 |
# Test: |
| 14 |
# 0. This test requires three servers |
| 15 |
# 1. Members in Multy Primary Mode, create two tables and rpl_sync |
| 16 |
# 2. On a member server2 that will be secondary lock a table t1 |
| 17 |
# 3. On other member insert value on table locked on server2 |
| 18 |
# 4. Execute action to change to single primary with server1 as primary |
| 19 |
# 5. Check that the other members are waiting for members to be in read |
| 20 |
# mode. Stages should be |
| 21 |
# - Primary Election: waiting for members to enable super_read_only |
| 22 |
# - Single-primary Switch: executing Primary election - completed work 0 |
| 23 |
# 6. Lock a table t2 on the primary server1 |
| 24 |
# 7. Insert something on t2 on server2, the locked secondary |
| 25 |
# 8. Unlock table t1 on server2, the locked secondary |
| 26 |
# 9. Stage should be |
| 27 |
# - Single-primary Switch: executing Primary election - completed work 1 |
| 28 |
# 10. Stop the new primary server1 |
| 29 |
# 11. Check that the action finishes |
| 30 |
# 12. Check server2 was able to insert value |
| 31 |
# 13. Using weights one can assert here that primary is now server3 |
| 32 |
# 14. Cleanup |
| 33 |
# |
| 34 |
############################################################################### |
| 35 |
|
| 36 |
--source include/force_restart.inc |
| 37 |
--source include/have_group_replication_plugin.inc |
| 38 |
--let $rpl_server_count= 3 |
| 39 |
--source include/group_replication.inc |
| 40 |
|
| 41 |
--echo |
| 42 |
--echo # 1. Members in Multy Primary Mode, create two tables and rpl_sync |
| 43 |
|
| 44 |
set session sql_log_bin=0; |
| 45 |
call mtr.add_suppression("Error while executing a group configuration operation: This operation was locally aborted and for that reason terminated. However the*"); |
| 46 |
set session sql_log_bin=1; |
| 47 |
|
| 48 |
--let $server1_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1) |
| 49 |
|
| 50 |
CREATE TABLE test.t1 (a INT PRIMARY KEY); |
| 51 |
CREATE TABLE test.t2 (a INT PRIMARY KEY); |
| 52 |
|
| 53 |
--source include/rpl_sync.inc |
| 54 |
|
| 55 |
--echo |
| 56 |
--echo # 2. On a member server2 that will be secondary lock a table t1 |
| 57 |
|
| 58 |
--let $rpl_connection_name= server2 |
| 59 |
--source include/rpl_connection.inc |
| 60 |
|
| 61 |
LOCK TABLE t1 READ; |
| 62 |
|
| 63 |
--echo |
| 64 |
--echo # 3. On other member insert value on table locked on server2 |
| 65 |
|
| 66 |
--let $rpl_connection_name= server_3 |
| 67 |
--source include/rpl_connection.inc |
| 68 |
|
| 69 |
--let $server3_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1) |
| 70 |
|
| 71 |
SET @@GLOBAL.group_replication_member_weight= 90; |
| 72 |
|
| 73 |
INSERT INTO t1 VALUES (1); |
| 74 |
|
| 75 |
--let $rpl_connection_name= server_2 |
| 76 |
--source include/rpl_connection.inc |
| 77 |
|
| 78 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Waiting for table metadata lock%" |
| 79 |
--source include/wait_condition.inc |
| 80 |
|
| 81 |
--echo |
| 82 |
--echo # 4. Execute action to change to single primary with server1 as primary |
| 83 |
|
| 84 |
--let $rpl_connection_name= server3 |
| 85 |
--source include/rpl_connection.inc |
| 86 |
|
| 87 |
--replace_result $server1_uuid MEMBER1_UUID |
| 88 |
--send_eval SELECT group_replication_switch_to_single_primary_mode("$server1_uuid") |
| 89 |
|
| 90 |
--let $rpl_connection_name= server_3 |
| 91 |
--source include/rpl_connection.inc |
| 92 |
|
| 93 |
--echo |
| 94 |
--echo # 5. Check that the other members are waiting for members to be in read |
| 95 |
--echo # mode. Stages should be |
| 96 |
--echo # - Primary Election: waiting for members to enable super_read_only |
| 97 |
--echo # - Single-primary Switch: executing Primary election - completed work 0 |
| 98 |
|
| 99 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%super_read_only%" |
| 100 |
--source include/wait_condition.inc |
| 101 |
|
| 102 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%Single-primary Switch%" AND work_completed=0;` |
| 103 |
--let $assert_text= The stage should be "Single-primary Switch: executing Primary election" |
| 104 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Single-primary Switch: executing Primary election" |
| 105 |
--source include/assert.inc |
| 106 |
|
| 107 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%super_read_only%";` |
| 108 |
--let $assert_text= The stage should be "Primary Election: waiting for members to enable super_read_only" |
| 109 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Election: waiting for members to enable super_read_only" |
| 110 |
--source include/assert.inc |
| 111 |
|
| 112 |
--echo |
| 113 |
--echo # 6. Lock a table t2 on the primary server1 |
| 114 |
|
| 115 |
--let $rpl_connection_name= server1 |
| 116 |
--source include/rpl_connection.inc |
| 117 |
|
| 118 |
LOCK TABLE t2 READ; |
| 119 |
|
| 120 |
--echo |
| 121 |
--echo # 7. Insert something on t2 on server2, the locked secondary |
| 122 |
|
| 123 |
--let $rpl_connection_name= server_2_1 |
| 124 |
--source include/rpl_connection.inc |
| 125 |
|
| 126 |
--send INSERT INTO t2 VALUES (1) |
| 127 |
|
| 128 |
--echo |
| 129 |
--echo # 8. Unlock table t1 on server2, the locked secondary |
| 130 |
|
| 131 |
--let $rpl_connection_name= server2 |
| 132 |
--source include/rpl_connection.inc |
| 133 |
|
| 134 |
# Insert might not have started, UNLOCK will unblock internal SET READ_ONLY |
| 135 |
--let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist WHERE state LIKE "%Waiting for global read lock%" AND info lIKE "%INSERT INTO t2%" AND USER="root" |
| 136 |
--source include/wait_condition.inc |
| 137 |
|
| 138 |
UNLOCK TABLES; |
| 139 |
|
| 140 |
--echo |
| 141 |
--echo # 9. Stage should be |
| 142 |
--echo # - Single-primary Switch: executing Primary election - completed work 1 |
| 143 |
|
| 144 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Single-primary Switch: executing Primary election%" AND work_completed=1 |
| 145 |
--source include/wait_condition.inc |
| 146 |
|
| 147 |
--echo |
| 148 |
--echo # 10. Stop the new primary server1 |
| 149 |
|
| 150 |
--let $rpl_connection_name= server_1 |
| 151 |
--source include/rpl_connection.inc |
| 152 |
|
| 153 |
--send STOP GROUP_REPLICATION |
| 154 |
|
| 155 |
--let $rpl_connection_name= server2 |
| 156 |
--source include/rpl_connection.inc |
| 157 |
|
| 158 |
--let $group_replication_number_of_members= 2 |
| 159 |
--source include/gr_wait_for_number_of_members.inc |
| 160 |
|
| 161 |
--let $rpl_connection_name= server1 |
| 162 |
--source include/rpl_connection.inc |
| 163 |
|
| 164 |
UNLOCK TABLES; |
| 165 |
|
| 166 |
--let $rpl_connection_name= server_1 |
| 167 |
--source include/rpl_connection.inc |
| 168 |
|
| 169 |
--reap |
| 170 |
|
| 171 |
--let $group_replication_member_state= OFFLINE |
| 172 |
--source include/gr_wait_for_member_state.inc |
| 173 |
|
| 174 |
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err |
| 175 |
--let $assert_count = 1 |
| 176 |
--let $assert_select = Error while executing a group configuration operation: This operation was locally aborted and for that reason terminated. |
| 177 |
--let $assert_text = Found the expected error about the operation abort |
| 178 |
--source include/assert_grep.inc |
| 179 |
|
| 180 |
--let $assert_text= group_replication_enforce_update_everywhere_checks is OFF |
| 181 |
--let $assert_cond= "[SELECT @@GLOBAL.group_replication_enforce_update_everywhere_checks]" = 0 |
| 182 |
--source include/assert.inc |
| 183 |
|
| 184 |
--let $assert_text= The primary mode should be 1 here. |
| 185 |
--let $assert_cond= "[SELECT @@GLOBAL.group_replication_single_primary_mode]" = 1; |
| 186 |
--source include/assert.inc |
| 187 |
|
| 188 |
--echo |
| 189 |
--echo # 11. Check that the action finishes |
| 190 |
|
| 191 |
--let $rpl_connection_name= server2 |
| 192 |
--source include/rpl_connection.inc |
| 193 |
|
| 194 |
--let $group_replication_number_of_members= 2 |
| 195 |
--source include/gr_wait_for_number_of_members.inc |
| 196 |
|
| 197 |
--echo |
| 198 |
--echo # 12. Check server2 was able to insert value |
| 199 |
|
| 200 |
--let $rpl_connection_name= server_2_1 |
| 201 |
--source include/rpl_connection.inc |
| 202 |
|
| 203 |
--reap |
| 204 |
|
| 205 |
--echo |
| 206 |
--echo # 13. Using weights one can assert here that primary is now server3 |
| 207 |
|
| 208 |
--let $rpl_connection_name= server3 |
| 209 |
--source include/rpl_connection.inc |
| 210 |
|
| 211 |
--replace_result $server1_uuid MEMBER1_UUID |
| 212 |
--reap |
| 213 |
|
| 214 |
--source include/gr_assert_primary_member.inc |
| 215 |
|
| 216 |
--echo |
| 217 |
--echo # 14. Cleanup |
| 218 |
|
| 219 |
|
| 220 |
--let $rpl_connection_name= server1 |
| 221 |
--source include/rpl_connection.inc |
| 222 |
|
| 223 |
--source include/start_group_replication.inc |
| 224 |
|
| 225 |
--let $rpl_connection_name= server3 |
| 226 |
--source include/rpl_connection.inc |
| 227 |
|
| 228 |
SET @@GLOBAL.group_replication_member_weight= DEFAULT; |
| 229 |
|
| 230 |
DROP TABLE t1; |
| 231 |
DROP TABLE t2; |
| 232 |
|
| 233 |
--let $rpl_group_replication_single_primary_mode=1 |
| 234 |
--let $rpl_group_replication_reset_persistent_vars=1 |
| 235 |
--source include/group_replication_end.inc |