| 1 |
############################################################################### |
| 2 |
# |
| 3 |
# When primary member is proposed |
| 4 |
# - 1: A new election shall happen in all members appointing the |
| 5 |
# proposed member as the new primary |
| 6 |
# - 2: While all updates from the old primary previous to the |
| 7 |
# election are not applied, the new primary must stay in read mode. |
| 8 |
# - 3: While updates from the old and new primaries are in the |
| 9 |
# group, any transactional conflict between them must abort. |
| 10 |
# |
| 11 |
# Test: |
| 12 |
# 0. This test requires two servers in single primary mode |
| 13 |
# 1. Bootstrap the group with server1 and create table test.t1 and test.t2 |
| 14 |
# 2. Start server2 and lock writes to table t1 |
| 15 |
# 3. Insert values on table t1 on server 1 |
| 16 |
# 4. Set server2 as primary |
| 17 |
# 5. Consult stages to guarantee that server2 is waiting on the execution |
| 18 |
# of server 1 transactions. |
| 19 |
# Server2 must be in read mode |
| 20 |
# 6. Send a transaction to table2 on server1. Block it on sending. |
| 21 |
# 7. Unlock the table1 on server2. The member shall unset the read mode |
| 22 |
# The member shall now wait for server1 to be in read mode |
| 23 |
# 8. Send a transaction to table2 on server2. Block it on sending. |
| 24 |
# 9. Unblock the transaction on server1 |
| 25 |
# 10. Check the status of server2 transaction. It should have failed |
| 26 |
# 11. The group_replication_set_as_primary will succeed |
| 27 |
# 12. Server2 is the new primary |
| 28 |
# 13. Cleanup |
| 29 |
# |
| 30 |
############################################################################### |
| 31 |
|
| 32 |
--source include/have_debug_sync.inc |
| 33 |
--source include/have_group_replication_plugin.inc |
| 34 |
--let $rpl_skip_group_replication_start= 1 |
| 35 |
--let $rpl_group_replication_single_primary_mode=1 |
| 36 |
--source include/group_replication.inc |
| 37 |
|
| 38 |
--echo |
| 39 |
--echo # 1. Bootstrap the group with server1 and create table test.t1 and test.t2 |
| 40 |
|
| 41 |
--source include/start_and_bootstrap_group_replication.inc |
| 42 |
|
| 43 |
CREATE TABLE test.t1 (a INT PRIMARY KEY); |
| 44 |
CREATE TABLE test.t2 (a INT PRIMARY KEY); |
| 45 |
|
| 46 |
--echo |
| 47 |
--echo # 2. Start server2 and lock writes to table t1 |
| 48 |
|
| 49 |
--let $rpl_connection_name= server2 |
| 50 |
--source include/rpl_connection.inc |
| 51 |
--source include/start_group_replication.inc |
| 52 |
|
| 53 |
--let $server2_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1) |
| 54 |
|
| 55 |
LOCK TABLE t1 READ; |
| 56 |
|
| 57 |
--echo |
| 58 |
--echo # 3. Insert values on table t1 on server 1 |
| 59 |
|
| 60 |
--let $rpl_connection_name= server1 |
| 61 |
--source include/rpl_connection.inc |
| 62 |
|
| 63 |
INSERT INTO t1 VALUES (1); |
| 64 |
INSERT INTO t1 VALUES (2); |
| 65 |
|
| 66 |
--echo |
| 67 |
--echo # 4. Set server2 as primary |
| 68 |
|
| 69 |
--replace_result $server2_uuid MEMBER2_UUID |
| 70 |
--send_eval SELECT group_replication_set_as_primary("$server2_uuid") |
| 71 |
|
| 72 |
--let $rpl_connection_name= server_1 |
| 73 |
--source include/rpl_connection.inc |
| 74 |
|
| 75 |
--let $assert_text= The super_read_only mode should be 0 here. |
| 76 |
--let $assert_cond= "[SELECT @@GLOBAL.super_read_only]" = 0; |
| 77 |
--source include/assert.inc |
| 78 |
|
| 79 |
--echo |
| 80 |
--echo # 5. Consult stages to guarantee that server2 is |
| 81 |
--echo # waiting on the execution of serve 1 transactions. |
| 82 |
--echo # Server2 must be in read mode |
| 83 |
|
| 84 |
--let $rpl_connection_name= server2 |
| 85 |
--source include/rpl_connection.inc |
| 86 |
|
| 87 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Primary Election: applying buffered transactions%" |
| 88 |
--source include/wait_condition.inc |
| 89 |
|
| 90 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%stage/group_rpl/Primary Election%";` |
| 91 |
--let $assert_text= stage/group_rpl/Primary Election: applying buffered transactions |
| 92 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Election: applying buffered transactions" |
| 93 |
--source include/assert.inc |
| 94 |
|
| 95 |
--let $received_transaction_set= query_get_value(SELECT received_transaction_set FROM performance_schema.replication_connection_status WHERE channel_name="group_replication_applier", received_transaction_set, 1) |
| 96 |
--let $assert_text= The value of received_transaction_set must contain the 2 creates and 2 inserts |
| 97 |
--let $assert_cond= "$received_transaction_set" = "$group_replication_group_name:4-6" |
| 98 |
--source include/assert.inc |
| 99 |
|
| 100 |
--let $assert_text= The super_read_only mode should be 1 here. |
| 101 |
--let $assert_cond= "[SELECT @@GLOBAL.super_read_only]" = 1; |
| 102 |
--source include/assert.inc |
| 103 |
|
| 104 |
--echo |
| 105 |
--echo # 6. Send a transaction to table2 on server1. |
| 106 |
--echo # Block it on sending |
| 107 |
|
| 108 |
--let $rpl_connection_name= server_1 |
| 109 |
--source include/rpl_connection.inc |
| 110 |
|
| 111 |
SET @@GLOBAL.DEBUG='+d,group_replication_before_message_broadcast'; |
| 112 |
|
| 113 |
--let $rpl_connection_name= server_1_1 |
| 114 |
--source include/rpl_connection.inc |
| 115 |
|
| 116 |
--send INSERT INTO t2 VALUES (1) |
| 117 |
|
| 118 |
--let $rpl_connection_name= server_1 |
| 119 |
--source include/rpl_connection.inc |
| 120 |
|
| 121 |
--let $wait_condition=SELECT COUNT(*)=1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE State = 'debug sync point: now' |
| 122 |
--source include/wait_condition.inc |
| 123 |
|
| 124 |
--echo |
| 125 |
--echo # 7. Unlock the table1 on server2 |
| 126 |
--echo # The member shall unset the read mode |
| 127 |
--echo # The member shall now wait for server1 to be in read mode |
| 128 |
|
| 129 |
--let $rpl_connection_name= server2 |
| 130 |
--source include/rpl_connection.inc |
| 131 |
|
| 132 |
UNLOCK TABLES; |
| 133 |
|
| 134 |
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%super_read_only%" |
| 135 |
--source include/wait_condition.inc |
| 136 |
|
| 137 |
--let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%stage/group_rpl/Primary Election%";` |
| 138 |
--let $assert_text= stage/group_rpl/Primary Election: waiting for members to enable super_read_only |
| 139 |
--let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Election: waiting for members to enable super_read_only" |
| 140 |
--source include/assert.inc |
| 141 |
|
| 142 |
--let $assert_text= The super_read_only mode should be 0 here. |
| 143 |
--let $assert_cond= "[SELECT @@GLOBAL.super_read_only]" = 0; |
| 144 |
--source include/assert.inc |
| 145 |
|
| 146 |
--echo |
| 147 |
--echo # 8. Send a transaction to table2 on server2. |
| 148 |
--echo # Block it on sending |
| 149 |
|
| 150 |
--let $rpl_connection_name= server_2 |
| 151 |
--source include/rpl_connection.inc |
| 152 |
|
| 153 |
SET @@GLOBAL.DEBUG='+d,group_replication_before_message_broadcast'; |
| 154 |
|
| 155 |
--let $rpl_connection_name= server_2_1 |
| 156 |
--source include/rpl_connection.inc |
| 157 |
|
| 158 |
--send INSERT INTO t2 VALUES (1) |
| 159 |
|
| 160 |
--let $rpl_connection_name= server_2 |
| 161 |
--source include/rpl_connection.inc |
| 162 |
|
| 163 |
--let $wait_condition=SELECT COUNT(*)=1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE State = 'debug sync point: now' |
| 164 |
--source include/wait_condition.inc |
| 165 |
|
| 166 |
--echo |
| 167 |
--echo # 9. Unblock the transaction on server1 |
| 168 |
|
| 169 |
--let $rpl_connection_name= server_1 |
| 170 |
--source include/rpl_connection.inc |
| 171 |
|
| 172 |
SET DEBUG_SYNC='now SIGNAL waiting'; |
| 173 |
SET @@GLOBAL.DEBUG='-d,group_replication_before_message_broadcast'; |
| 174 |
|
| 175 |
--let $rpl_connection_name= server_1_1 |
| 176 |
--source include/rpl_connection.inc |
| 177 |
|
| 178 |
--reap |
| 179 |
|
| 180 |
--echo |
| 181 |
--echo # 10. Check the status of server2 transaction. |
| 182 |
--echo # It should have failed |
| 183 |
|
| 184 |
--let $rpl_connection_name= server_2 |
| 185 |
--source include/rpl_connection.inc |
| 186 |
|
| 187 |
SET DEBUG_SYNC='now SIGNAL waiting'; |
| 188 |
SET @@GLOBAL.DEBUG='-d,group_replication_before_message_broadcast'; |
| 189 |
|
| 190 |
--let $rpl_connection_name= server_2_1 |
| 191 |
--source include/rpl_connection.inc |
| 192 |
|
| 193 |
--error ER_TRANSACTION_ROLLBACK_DURING_COMMIT |
| 194 |
--reap |
| 195 |
|
| 196 |
--echo |
| 197 |
--echo # 11. The group_replication_set_as_primary will succeed |
| 198 |
|
| 199 |
--let $rpl_connection_name= server1 |
| 200 |
--source include/rpl_connection.inc |
| 201 |
|
| 202 |
--replace_result $server2_uuid MEMBER2_UUID |
| 203 |
--reap |
| 204 |
|
| 205 |
--echo |
| 206 |
--echo # 12. Server2 is the new primary |
| 207 |
|
| 208 |
--let $rpl_connection_name= server2 |
| 209 |
--source include/rpl_connection.inc |
| 210 |
|
| 211 |
--source include/gr_assert_primary_member.inc |
| 212 |
|
| 213 |
--let $rpl_connection_name= server1 |
| 214 |
--source include/rpl_connection.inc |
| 215 |
|
| 216 |
--source include/gr_assert_secondary_member.inc |
| 217 |
|
| 218 |
--echo |
| 219 |
--echo # 13. Cleanup |
| 220 |
|
| 221 |
--let $rpl_connection_name= server2 |
| 222 |
--source include/rpl_connection.inc |
| 223 |
|
| 224 |
DROP TABLE t1; |
| 225 |
DROP TABLE t2; |
| 226 |
|
| 227 |
--let $rpl_group_replication_reset_persistent_vars=1 |
| 228 |
--source include/group_replication_end.inc |