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