Debian Codegraph @

mysql-test/suite/group_replication/t/gr_primary_mode_group_operations_28.test

raw
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. Kill the new primary server2
18 # 8. Wait group detect exit of server2
19 # 9. Unlock table on server2
20 # 10. Reap insertion of data on server1
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 --source include/have_group_replication_plugin.inc
28 --source include/not_valgrind.inc
29 --let $rpl_server_count= 3
30 --let $rpl_skip_group_replication_start= 1
31 --let $rpl_group_replication_single_primary_mode=1
32 --source include/group_replication.inc
33
34 --echo
35 --echo # 1. Start single primary group and create table
36
37 --source include/start_and_bootstrap_group_replication.inc
38
39 --let $server1_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
40
41 CREATE TABLE test.t1 (a INT PRIMARY KEY);
42
43 --source include/rpl_sync.inc
44
45 --let $rpl_connection_name= server2
46 --source include/rpl_connection.inc
47 --source include/start_group_replication.inc
48
49 --let $server2_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
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("The function 'group_replication_set_as_primary' failed. The appointed primary for election left the group, this operation will be aborted*");
56 set session sql_log_bin=1;
57
58 --source include/start_group_replication.inc
59
60 --echo
61 --echo # 2. Disable read only to action be stuck on setting read only
62
63 SET GLOBAL read_only= 0;
64
65 --echo
66 --echo # 3. Go to a member that will be a secondary and lock a table
67
68 --let $rpl_connection_name= server_3
69 --source include/rpl_connection.inc
70
71 LOCK TABLE t1 READ;
72
73 --echo
74 --echo # 4. Insert a row on the old primary
75
76 --let $rpl_connection_name= server1
77 --source include/rpl_connection.inc
78
79 --send INSERT INTO t1 VALUES (1)
80
81 --let $rpl_connection_name= server2
82 --source include/rpl_connection.inc
83
84 --let $wait_condition=SELECT COUNT(*)=1 FROM test.t1
85 --source include/wait_condition.inc
86
87 --echo
88 --echo # 5. Execute action to change primary to server2
89
90 --let $rpl_connection_name= server3
91 --source include/rpl_connection.inc
92
93 --replace_result $server2_uuid MEMBER2_UUID
94 --send_eval SELECT group_replication_set_as_primary("$server2_uuid")
95
96 --echo
97 --echo # 6. Check that the other members are waiting for members to be in
98 --echo # super_read_only and executing primary election
99
100 --let $rpl_connection_name= server_1
101 --source include/rpl_connection.inc
102
103 --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%"
104 --source include/wait_condition.inc
105
106 --let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "stage/group_rpl/Primary Switch: executing Primary election"
107 --source include/wait_condition.inc
108
109 --let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%stage/group_rpl/Primary Election%";`
110 --let $assert_text= stage/group_rpl/Primary Election: waiting for members to enable super_read_only
111 --let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Election: waiting for members to enable super_read_only"
112 --source include/assert.inc
113
114 --echo
115 --echo # 7. Kill the new primary server2
116
117 --let $rpl_connection_name= server2
118 --source include/rpl_connection.inc
119
120 --let $_group_replication_local_address= `SELECT @@GLOBAL.group_replication_local_address`
121 --let $_group_replication_group_seeds= `SELECT @@GLOBAL.group_replication_group_seeds`
122
123 --replace_result $group_replication_group_name GROUP_REPLICATION_GROUP_NAME $_group_replication_local_address GROUP_REPLICATION_LOCAL_ADDRESS $_group_replication_group_seeds GROUP_REPLICATION_GROUP_SEEDS
124 --let $restart_parameters=restart:--group-replication-start-on-boot=0 --group-replication-group-name=$group_replication_group_name --group_replication_local_address=$_group_replication_local_address --group_replication_group_seeds=$_group_replication_group_seeds --group_replication_single_primary_mode=TRUE --group_replication_enforce_update_everywhere_checks=FALSE
125 --source include/kill_and_restart_mysqld.inc
126
127 --let $rpl_server_number= 2
128 --source include/rpl_reconnect.inc
129
130 --echo
131 --echo # 8. Wait group detect exit of server2
132
133 --let $rpl_connection_name= server_1
134 --source include/rpl_connection.inc
135
136 --let $group_replication_number_of_members= 2
137 --source include/gr_wait_for_number_of_members.inc
138
139 --echo
140 --echo # 9. Unlock table on server2
141
142 --let $rpl_connection_name= server_3
143 --source include/rpl_connection.inc
144
145 UNLOCK TABLES;
146
147 --echo
148 --echo # 10. Reap insertion of data on server1
149
150 --let $rpl_connection_name= server1
151 --source include/rpl_connection.inc
152
153 --reap
154
155 --echo
156 --echo # 11. Check that the action returns failure
157
158 --let $rpl_connection_name= server3
159 --source include/rpl_connection.inc
160
161 --error ER_GRP_RPL_UDF_ERROR
162 --reap
163
164 --echo
165 --echo # 12. Confirm server1 is the new primary because it was the old primary
166
167 --let $rpl_connection_name= server1
168 --source include/rpl_connection.inc
169
170 --let $group_replication_expected_uuid=$server1_uuid
171 --source include/gr_wait_primary_member_uuid.inc
172
173 # A member is first reported as primary and only then super_read_only
174 # and read_only are unset, so we need to also wait until the primary
175 # is writable.
176 --let $wait_condition= SELECT @@GLOBAL.read_only = '0'
177 --source include/wait_condition_or_abort.inc
178
179 --echo
180 --echo # 13. Clean up
181
182 DROP TABLE t1;
183
184 --let $rpl_connection_name= server2
185 --source include/rpl_connection.inc
186
187 DROP TABLE t1;
188
189 --let $rpl_connection_name= server1
190 --source include/rpl_connection.inc
191
192 set session sql_log_bin=0;
193 call mtr.add_suppression("Error while executing a group configuration operation: The appointed primary for election left the group, this operation will be aborted.*");
194 set session sql_log_bin=1;
195
196 --let $rpl_group_replication_single_primary_mode=1
197 --let $rpl_group_replication_reset_persistent_vars=1
198 --source include/group_replication_end.inc