Debian Codegraph @

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

raw
1 ###################################################################
2 # WL#9426: Single Primary Mode in Group Replication
3 #
4 # Validate that leader election takes place while creating
5 # the group and while shutting it down. When shutting down
6 # we do it by always stopping the primary first.
7 #
8 # Test:
9 #
10 # - Stage #1
11 # - create the group, one by one. The PRIMARY is the first
12 # server in the group
13 # - for each server check what its role is and whether
14 # it is RO or RW as expected
15 # - Check that there are 1 PRIMARY per iteration and that
16 # there are N secondaries as expected.
17 #
18 # - Stage #2
19 # - Find the primary server in the group
20 # - stop it
21 # - Find the next server still in the group
22 # - Count primaries and secondaries after the group installed
23 # a new view.
24 # - Find the new primary on the new view
25 # - assert that it is RW
26 # - assert that the PRIMARY has indeed changed.
27 #
28 # - Stage #3
29 # - clean up
30 #
31 ##################################################################
32
33 --source include/big_test.inc
34 --source include/have_group_replication_plugin.inc
35
36 --let $rpl_skip_group_replication_start= 1
37 --let $rpl_server_count= 4
38 --let $rpl_group_replication_single_primary_mode=1
39 --let $ceiling= `SELECT $rpl_server_count + 1`
40 --source include/group_replication.inc
41
42 --echo #
43 --echo # Stage 1. Watch PRIMARY and SECONDARIES being set as we grow the group.
44 --echo #
45
46 --let $i=1
47 while ($i < $ceiling)
48 {
49 --let $rpl_connection_name= server$i
50 --source include/rpl_connection.inc
51
52 # This assert can be turned into something that enforces
53 # super read only to RW. The point is to verify that the
54 # server later on is put into super_read_only mode
55 --let $assert_cond= "[SELECT @@GLOBAL.super_read_only]" = 0
56 --let $assert_text= Assert that before joining the group the server is RW.
57 --source include/assert.inc
58
59 #
60 # 1. Start the group and check that the server that started it
61 # has become the PRIMARY
62 #
63 if (`SELECT $i=1`)
64 {
65 --let $read_only= 0
66 --let $assert_text= Assert that PRIMARY is now RW.
67 --let $primary_server_id=`SELECT @@server_id`
68 --let $primary_server_uuid=`SELECT @@server_uuid`
69
70 --source include/start_and_bootstrap_group_replication.inc
71 }
72
73 #
74 # 2,3,4. Add another servers to the group and make sure that
75 # they are added as SECONDARY
76 #
77 if ($i > 1)
78 {
79 --let $read_only= 1
80 --let $assert_text= Assert that SECONDARY is now RO.
81
82 --source include/start_group_replication.inc
83 }
84
85 # wait for the member to point PRIMARY node
86 # 1 - PRIMARY / 2,3,4 - SECONDARY
87 --let $group_replication_expected_uuid=$primary_server_uuid
88 --source include/gr_wait_primary_member_uuid.inc
89
90 # check that the server has turned ON/OFF the expected super_read_only flag
91 # we wait since the setting of the role and unsetting of super_read_only
92 # is not atomic
93 --let $wait_condition= SELECT @@super_read_only = $read_only
94 --source include/wait_condition_or_abort.inc
95
96 # Lets count secondaries and primaries in the group
97 --let $group_replication_primaries_count_in_var= 1
98 --let $group_replication_secondaries_count_in_var= `SELECT $i-1`
99 --source include/gr_wait_for_role_count.inc
100
101 # Lets assert that the primary continues RW
102 --source include/gr_find_a_primary.inc
103 if ($group_replication_found_primary_out_var)
104 {
105 --let $rpl_connection_name= $group_replication_primary_connection_out_var
106 --source include/rpl_connection.inc
107 }
108 if (!$group_replication_found_primary_out_var)
109 {
110 --echo performance_schema.replication_group_members
111 --echo --------------------------------------------
112 --query_vertical SELECT * FROM performance_schema.replication_group_members
113 --die "Unable to find PRIMARY server!!"
114 }
115
116 --let $assert_cond= "[SELECT @@GLOBAL.super_read_only]" = 0
117 --let $assert_text= Assert that PRIMARY has not changed its super_read_only setting.
118 --source include/assert.inc
119
120 # Lets assert that the current primary has not changed
121 --let $assert_cond= "[SELECT @@GLOBAL.server_id]" = $primary_server_id
122 --let $assert_text= Assert that PRIMARY server has not changed.
123 --source include/assert.inc
124
125 --inc $i
126 }
127
128 --echo #
129 --echo # Stage 2. Watch the primary rotate as we tear down the group.
130 --echo # Always stopping the primary first - worst case scenario.
131 --echo #
132
133 # the PRIMARY server connection may not be deterministic
134 --let $rpl_connection_silent=1
135
136 --let $i= 1
137 while($i < $ceiling)
138 {
139 # find a primary server and switch connection to it
140 --source include/gr_find_a_primary.inc
141 if ($group_replication_found_primary_out_var)
142 {
143 --let $rpl_connection_name= $group_replication_primary_connection_out_var
144 --source include/rpl_connection.inc
145 --let $primary_server_id=`SELECT @@server_id`
146 }
147
148 if (!$group_replication_found_primary_out_var)
149 {
150 --echo performance_schema.replication_group_members
151 --echo --------------------------------------------
152 --query_vertical SELECT * FROM performance_schema.replication_group_members
153 --die "Unable to find PRIMARY server!!"
154 }
155
156 # stop current primary
157 --source include/stop_group_replication.inc
158
159 if ($i<$rpl_server_count)
160 {
161
162 # find the next server in the group that is ONLINE
163 --let $i_next_server= 1
164 while ($i_next_server < $ceiling)
165 {
166 --let $rpl_connection_name= server$i_next_server
167 --source include/rpl_connection.inc
168
169 --let $member_id= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
170 let $is_online=`SELECT COUNT(*)=1
171 FROM performance_schema.replication_group_members
172 WHERE member_id="$member_id" AND
173 member_state="ONLINE"`;
174
175 if ($is_online)
176 {
177 --let $i_next_server=$ceiling
178 }
179
180 if (!$is_online)
181 {
182 --inc $i_next_server
183 }
184 }
185
186 if (!$is_online)
187 {
188 --die "Unable to find the next ONLINE server in the group!!"
189 }
190
191 # wait for the view to be installed
192 --let $group_replication_number_of_members= `SELECT 5 - $i - 1`
193 --source include/gr_wait_for_number_of_members.inc
194
195 # Lets count secondaries and primaries in the group
196 --let $group_replication_primaries_count_in_var= 1
197 --let $group_replication_secondaries_count_in_var= `SELECT 5 - $i - 2`
198 --source include/gr_wait_for_role_count.inc
199
200 # Lets assert that the primary continues RW
201 --source include/gr_find_a_primary.inc
202 if ($group_replication_found_primary_out_var)
203 {
204 --let $rpl_connection_name= $group_replication_primary_connection_out_var
205 --source include/rpl_connection.inc
206 }
207 if (!$group_replication_found_primary_out_var)
208 {
209 --die "Unable to find PRIMARY server!!"
210 }
211
212 --let $assert_cond= "[SELECT @@GLOBAL.super_read_only]" = 0
213 --let $assert_text= Assert that PRIMARY changed its super_read_only setting from RO to RW.
214 --source include/assert.inc
215
216 # Lets assert that the current primary HAS changed
217 --let $assert_cond= "[SELECT @@GLOBAL.server_id]" <> $primary_server_id
218 --let $assert_text= Assert that PRIMARY server HAS changed.
219 --source include/assert.inc
220
221 }
222
223 --inc $i
224 }
225
226 --echo #
227 --echo # Stage 3. Clean up.
228 --echo #
229
230 # restore this
231 --let $rpl_connection_silent=0
232
233 --source include/group_replication_end.inc