| 1 |
############################################################################### |
| 2 |
# |
| 3 |
# When changing mode to single primary with an appointed primary, P, |
| 4 |
# if P leaves or fails under a majority, when the primary election began |
| 5 |
# but is not yet over, the change will not abort and |
| 6 |
# adapt to the new elected primary throwing a warning. |
| 7 |
# |
| 8 |
# Also: |
| 9 |
# When the plugin is stopped or leaves in error, while changing |
| 10 |
# from multi primary mode to single primary mode, if the member did |
| 11 |
# not set the single primary mode flag to true, then update |
| 12 |
# everywhere checks shall remain true. |
| 13 |
# |
| 14 |
# Test: |
| 15 |
# 0. This test needs three servers |
| 16 |
# 1. Create table for tests on a multi primary group |
| 17 |
# 2. Lock table on a server that will be a secondary and set its |
| 18 |
# weight to be chosen as primary on single primary mode |
| 19 |
# 3. Insert a row on a group |
| 20 |
# 4. Invoke a change to single primary selecting server3 as new primary |
| 21 |
# 5. Check that the other members are waiting to enable |
| 22 |
# super_read_only and executing primary election |
| 23 |
# 6. Stop server 3 |
| 24 |
# 7. Wait group detect exit of server3 |
| 25 |
# 8. Unblock table on member that is blocked |
| 26 |
# 9. Check that the action finishes |
| 27 |
# 10. Confirm server2 is the new primary due its weight on member |
| 28 |
# election |
| 29 |
# 11. Check that Single primary mode is false on the stuck member and the |
| 30 |
# update everywhere checks are true |
| 31 |
# 12. Clean up |
| 32 |
# |
| 33 |
############################################################################### |
| 34 |
|
| 35 |
--source include/big_test.inc |
| 36 |
--source include/have_group_replication_plugin.inc |
| 37 |
--let $rpl_server_count= 3 |
| 38 |
--source include/group_replication.inc |
| 39 |
|
| 40 |
--echo |
| 41 |
--echo # 1. Create table for tests on a multi primary group |
| 42 |
|
| 43 |
set session sql_log_bin=0; |
| 44 |
call mtr.add_suppression("Error while executing a group configuration operation: This operation was locally aborted and for that reason terminated."); |
| 45 |
set session sql_log_bin=1; |
| 46 |
|
| 47 |
CREATE TABLE test.t1 (a INT PRIMARY KEY); |
| 48 |
|
| 49 |
--source include/rpl_sync.inc |
| 50 |
|
| 51 |
--let $rpl_connection_name= server3 |
| 52 |
--source include/rpl_connection.inc |
| 53 |
|
| 54 |
set session sql_log_bin=0; |
| 55 |
call mtr.add_suppression("Error while executing a group configuration operation: This operation was locally aborted and for that reason terminated."); |
| 56 |
set session sql_log_bin=1; |
| 57 |
|
| 58 |
--let $server3_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1) |
| 59 |
|
| 60 |
--echo |
| 61 |
--echo # 2. Lock table on a server that will be a secondary and set its |
| 62 |
--echo # weight to be chosen as primary on single primary mode |
| 63 |
|
| 64 |
--let $rpl_connection_name= server2 |
| 65 |
--source include/rpl_connection.inc |
| 66 |
|
| 67 |
set session sql_log_bin=0; |
| 68 |
call mtr.add_suppression("Error while executing a group configuration operation: The appointed primary for election left the group, this operation will be aborted.*"); |
| 69 |
set session sql_log_bin=1; |
| 70 |
|
| 71 |
SET @@GLOBAL.group_replication_member_weight= 90; |
| 72 |
|
| 73 |
LOCK TABLE t1 READ; |
| 74 |
|
| 75 |
--echo |
| 76 |
--echo # 3. Insert a row on a group |
| 77 |
|
| 78 |
--let $rpl_connection_name= server1 |
| 79 |
--source include/rpl_connection.inc |
| 80 |
|
| 81 |
--let $server1_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1) |
| 82 |
|
| 83 |
--eval INSERT INTO t1 VALUES (1) |
| 84 |
|
| 85 |
--echo |
| 86 |
--echo # 4. Invoke a change to single primary selecting server3 as new primary |
| 87 |
|
| 88 |
--replace_result $server3_uuid MEMBER3_UUID |
| 89 |
--send_eval SELECT group_replication_switch_to_single_primary_mode("$server3_uuid") |
| 90 |
|
| 91 |
--echo |
| 92 |
--echo # 5. Check that the other members are waiting to enable |
| 93 |
--echo # super_read_only and executing primary election |
| 94 |
|
| 95 |
--let $rpl_connection_name= server2 |
| 96 |
--source include/rpl_connection.inc |
| 97 |
|
| 98 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%stage/sql/Waiting for global read lock%" |
| 99 |
--source include/wait_condition.inc |
| 100 |
|
| 101 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%Single-primary Switch%";` |
| 102 |
--let $assert_text= The stage should be "Single-primary Switch: executing Primary election" |
| 103 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Single-primary Switch: executing Primary election" |
| 104 |
--source include/assert.inc |
| 105 |
|
| 106 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%global read lock%";` |
| 107 |
--let $assert_text= The stage should be "stage/sql/Waiting for global read lock" |
| 108 |
--let $assert_cond= "$stage_name" = "stage/sql/Waiting for global read lock" |
| 109 |
--source include/assert.inc |
| 110 |
|
| 111 |
--let $rpl_connection_name= server_1 |
| 112 |
--source include/rpl_connection.inc |
| 113 |
|
| 114 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Waiting for members to enable super_read_only%" |
| 115 |
--source include/wait_condition.inc |
| 116 |
|
| 117 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%Single-primary Switch%";` |
| 118 |
--let $assert_text= The stage should be "Single-primary Switch: executing Primary election" |
| 119 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Single-primary Switch: executing Primary election" |
| 120 |
--source include/assert.inc |
| 121 |
|
| 122 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%super_read_only%";` |
| 123 |
--let $assert_text= The stage should be "Primary Election: waiting for members to enable super_read_only" |
| 124 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Election: waiting for members to enable super_read_only" |
| 125 |
--source include/assert.inc |
| 126 |
|
| 127 |
--echo |
| 128 |
--echo # 6. Stop server 3 |
| 129 |
|
| 130 |
--let $rpl_connection_name= server3 |
| 131 |
--source include/rpl_connection.inc |
| 132 |
|
| 133 |
--source include/stop_group_replication.inc |
| 134 |
|
| 135 |
# Wait a few seconds for the message to appear in the log |
| 136 |
# When stop returns the write command was already executed, still it can fail |
| 137 |
--sleep 2 |
| 138 |
|
| 139 |
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.3.err |
| 140 |
--let $assert_count = 1 |
| 141 |
--let $assert_select = Error while executing a group configuration operation: This operation was locally aborted and for that reason terminated. |
| 142 |
--let $assert_text = Found the expected error about the operation abort |
| 143 |
--source include/assert_grep.inc |
| 144 |
|
| 145 |
--let $assert_text= group_replication_enforce_update_everywhere_checks is ON |
| 146 |
--let $assert_cond= "[SELECT @@GLOBAL.group_replication_enforce_update_everywhere_checks]" = 1 |
| 147 |
--source include/assert.inc |
| 148 |
|
| 149 |
--let $assert_text= The single primary mode should be 0 here. |
| 150 |
--let $assert_cond= "[SELECT @@GLOBAL.group_replication_single_primary_mode]" = 0; |
| 151 |
--source include/assert.inc |
| 152 |
|
| 153 |
--echo |
| 154 |
--echo # 7. Wait group detect exit of server3 |
| 155 |
|
| 156 |
--let $rpl_connection_name= server2 |
| 157 |
--source include/rpl_connection.inc |
| 158 |
|
| 159 |
--let $server2_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1) |
| 160 |
|
| 161 |
--let $group_replication_number_of_members= 2 |
| 162 |
--source include/gr_wait_for_number_of_members.inc |
| 163 |
|
| 164 |
--echo |
| 165 |
--echo # 8. Unblock table on member that is blocked |
| 166 |
|
| 167 |
UNLOCK TABLES; |
| 168 |
|
| 169 |
--echo |
| 170 |
--echo # 9. Check that the action finishes |
| 171 |
|
| 172 |
--let $rpl_connection_name= server1 |
| 173 |
--source include/rpl_connection.inc |
| 174 |
|
| 175 |
--replace_result $server3_uuid MEMBER3_UUID |
| 176 |
--reap |
| 177 |
|
| 178 |
--echo |
| 179 |
--echo # 10. Confirm server2 is the new primary due its weight on member |
| 180 |
--echo # election |
| 181 |
|
| 182 |
--let $rpl_connection_name= server2 |
| 183 |
--source include/rpl_connection.inc |
| 184 |
|
| 185 |
--source include/gr_assert_primary_member.inc |
| 186 |
|
| 187 |
--echo # 11. Check that Single primary mode is false on the stuck member and the |
| 188 |
--echo # update everywhere checks are true |
| 189 |
|
| 190 |
--let $rpl_connection_name= server3 |
| 191 |
--source include/rpl_connection.inc |
| 192 |
|
| 193 |
--let $assert_text= group_replication_enforce_update_everywhere_checks is ON |
| 194 |
--let $assert_cond= "[SELECT @@GLOBAL.group_replication_enforce_update_everywhere_checks]" = "1" |
| 195 |
--source include/assert.inc |
| 196 |
|
| 197 |
--let $assert_text= The single primary mode should be 0 here. |
| 198 |
--let $assert_cond= "[SELECT @@GLOBAL.group_replication_single_primary_mode]" = 0; |
| 199 |
|
| 200 |
--echo |
| 201 |
--echo # 12. Clean up |
| 202 |
|
| 203 |
SET GLOBAL group_replication_enforce_update_everywhere_checks= FALSE; |
| 204 |
SET GLOBAL group_replication_single_primary_mode= TRUE; |
| 205 |
|
| 206 |
--source include/start_group_replication.inc |
| 207 |
|
| 208 |
|
| 209 |
--let $rpl_connection_name= server2 |
| 210 |
--source include/rpl_connection.inc |
| 211 |
|
| 212 |
SET @@GLOBAL.group_replication_member_weight= DEFAULT; |
| 213 |
|
| 214 |
DROP TABLE t1; |
| 215 |
|
| 216 |
--let $rpl_group_replication_single_primary_mode=1 |
| 217 |
--let $rpl_group_replication_reset_persistent_vars=1 |
| 218 |
--source include/group_replication_end.inc |