Debian Codegraph @

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

raw
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 # Test:
9 # 0. This test needs three servers
10 # 1. Members in Multi Primary Mode, create two tables and rpl_sync
11 # 2. On a member server2 that will be secondary lock a table t1
12 # 3. On other member insert value on table locked on server2
13 # 4. Execute action to change to single primary with server1 as primary
14 # 5. Check that the other members are waiting for members to be in read
15 # mode. Stages should be
16 # - Primary Election: waiting for members to enable super_read_only
17 # - Single-primary Switch: executing Primary election - completed work 0
18 # 6. Lock a table t2 on the primary server1
19 # 7. Insert something on t2 on server2, the locked secondary
20 # 8. Unlock table t1 on server2, the locked secondary
21 # 9. Stage should be
22 # - Single-primary Switch: executing Primary election - completed work 1
23 # 10. Kill the new primary server1
24 # 11. Check that the action finishes
25 # 12. Check server2 was able to insert value
26 # 13. Using weights one can assert here that primary is now server3
27 # 14. Cleanup
28 #
29 ###############################################################################
30
31 --source include/have_group_replication_plugin.inc
32 --source include/not_valgrind.inc
33 --let $rpl_server_count= 3
34 --source include/group_replication.inc
35
36 --echo
37 --echo # 1. Members in Multi Primary Mode, create two tables and rpl_sync
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 CREATE TABLE test.t2 (a INT PRIMARY KEY);
43
44 --source include/rpl_sync.inc
45
46 --echo
47 --echo # 2. On a member server2 that will be secondary lock a table t1
48
49 --let $rpl_connection_name= server2
50 --source include/rpl_connection.inc
51
52 LOCK TABLE t1 READ;
53
54 --echo
55 --echo # 3. On other member insert value on table locked on server2
56
57 --let $rpl_connection_name= server_3
58 --source include/rpl_connection.inc
59
60 --let $server3_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
61
62 SET @@GLOBAL.group_replication_member_weight= 90;
63
64 INSERT INTO t1 VALUES (1);
65
66 --let $rpl_connection_name= server_2
67 --source include/rpl_connection.inc
68
69 --let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%Waiting for table metadata lock%"
70 --source include/wait_condition.inc
71
72 --echo
73 --echo # 4. Execute action to change to single primary with server1 as primary
74
75 --let $rpl_connection_name= server3
76 --source include/rpl_connection.inc
77
78 --replace_result $server1_uuid MEMBER1_UUID
79 --send_eval SELECT group_replication_switch_to_single_primary_mode("$server1_uuid")
80
81 --let $rpl_connection_name= server_3
82 --source include/rpl_connection.inc
83
84 --echo
85 --echo # 5. Check that the other members are waiting for members to be in read
86 --echo # mode. Stages should be
87 --echo # - Primary Election: waiting for members to enable super_read_only
88 --echo # - Single-primary Switch: executing Primary election - completed work 0
89
90 --let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.events_stages_current WHERE event_name LIKE "%super_read_only%"
91 --source include/wait_condition.inc
92
93 --let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%Single-primary Switch%" AND work_completed=0;`
94 --let $assert_text= The stage should be "Single-primary Switch: executing Primary election"
95 --let $assert_cond= "$stage_name" = "stage/group_rpl/Single-primary Switch: executing Primary election"
96 --source include/assert.inc
97
98 --let $stage_name= `SELECT event_name FROM performance_schema.events_stages_current WHERE event_name LIKE "%super_read_only%";`
99 --let $assert_text= The stage should be "Primary Election: waiting for members to enable super_read_only"
100 --let $assert_cond= "$stage_name" = "stage/group_rpl/Primary Election: waiting for members to enable super_read_only"
101 --source include/assert.inc
102
103 --echo
104 --echo # 6. Lock a table t2 on the primary server1
105
106 --let $rpl_connection_name= server1
107 --source include/rpl_connection.inc
108
109 LOCK TABLE t2 READ;
110
111 --echo
112 --echo # 7. Insert something on t2 on server2, the locked secondary
113
114 --let $rpl_connection_name= server_2_1
115 --source include/rpl_connection.inc
116
117 --send INSERT INTO t2 VALUES (1)
118
119 --echo
120 --echo # 8. Unlock table t1 on server2, the locked secondary
121
122 --let $rpl_connection_name= server2
123 --source include/rpl_connection.inc
124
125 # Insert might not have started, UNLOCK will unblock internal SET READ_ONLY
126 --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"
127 --source include/wait_condition.inc
128
129 UNLOCK TABLES;
130
131 --echo
132 --echo # 9. Stage should be
133 --echo # - Single-primary Switch: executing Primary election - completed work 1
134
135 --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
136 --source include/wait_condition.inc
137
138 --echo
139 --echo # 10. Kill the new primary server1
140
141 --let $rpl_connection_name= server1
142 --source include/rpl_connection.inc
143
144 --let $_group_replication_local_address= `SELECT @@GLOBAL.group_replication_local_address`
145 --let $_group_replication_group_seeds= `SELECT @@GLOBAL.group_replication_group_seeds`
146
147 --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
148 --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
149 --source include/kill_and_restart_mysqld.inc
150
151 --let $rpl_server_number= 1
152 --source include/rpl_reconnect.inc
153
154 --echo
155 --echo # 11. Check that the action finishes
156
157 --let $rpl_connection_name= server2
158 --source include/rpl_connection.inc
159
160 --let $group_replication_number_of_members= 2
161 --source include/gr_wait_for_number_of_members.inc
162
163 --echo
164 --echo # 12. Check server2 was able to insert value
165
166 --let $rpl_connection_name= server_2_1
167 --source include/rpl_connection.inc
168
169 --reap
170
171 --echo
172 --echo # 13. Using weights one can assert here that primary is now server3
173
174 --let $rpl_connection_name= server3
175 --source include/rpl_connection.inc
176
177 --replace_result $server1_uuid MEMBER1_UUID
178 --reap
179
180 --source include/gr_assert_primary_member.inc
181
182 --echo
183 --echo # 14. Cleanup
184
185 --let $rpl_connection_name= server1
186 --source include/rpl_connection.inc
187 --source include/start_group_replication.inc
188
189 --let $rpl_connection_name= server3
190 --source include/rpl_connection.inc
191 SET @@GLOBAL.group_replication_member_weight= DEFAULT;
192
193 DROP TABLE t1;
194 DROP TABLE t2;
195
196 --let $rpl_group_replication_single_primary_mode=1
197 --let $rpl_group_replication_reset_persistent_vars=1
198
199 --source include/group_replication_end.inc