3 # Set up replication on several servers in a specified topology.
5 # By default, this script does the following:
6 # - Creates the connections server_1, server_2, ..., server_N, as
7 # well as extra connections server_1_1, server_2_1, ...,
8 # server_N_1. server_I and server_I_1 are connections to the same
10 # - Verifies that @@server_id of all servers are different.
11 # - Calls RESET MASTER, RESET SLAVE, USE test, CHANGE MASTER, START SLAVE.
12 # - Sets the connection to server_1 before exiting.
16 # 1. If you are going to use more than two servers, create
17 # rpl_test.cfg with the following contents:
29 # SERVER_MYPORT_3= @mysqld.3.port
30 # SERVER_MYPORT_4= @mysqld.4.port
31 # SERVER_MYPORT_5= @mysqld.5.port
33 # SERVER_MYPORT_N= @mysqld.N.port
35 # (It is allowed, but not required, to configure SERVER_MYPORT_1
36 # and SERVER_MYPORT_2 too. If these variables are not set, the
37 # variables MASTER_MYPORT and SLAVE_MYPORT, configured in the
38 # default my.cnf used by the rpl and rpl_ndb suites, are used
39 # instead. In addition, in the rpl_ndb suite, SERVER_MYPORT_3 is
40 # not needed since MASTER_MYPORT1 can be used instead.)
42 # 2. Execute the following near the top of the test:
44 # [--let $rpl_server_count= 7]
45 # --let $rpl_topology= 1->2->3->1->4, 2->5, 6->7
46 # [--let $rpl_extra_connections_per_server= 1]
47 # [--let $rpl_check_server_ids= 1]
48 # [--let $rpl_skip_change_master= 1]
49 # [--let $rpl_skip_start_slave= 1]
50 # [--let $rpl_skip_reset_master_and_slave= 1]
51 # [--let $rpl_debug= 1]
52 # [--let $slave_timeout= NUMBER]
53 # [--let $use_gtids= 1]
54 # --source include/rpl_init.inc
59 # The number of servers to configure. If this is not set, the largest
60 # number in $rpl_topology will be used.
63 # A comma-separated list of replication chain
64 # specifications. Each replication chain specification has the
65 # form S1->S2->...->Sn, where 1 <= S1,...Sn <= $rpl_server_count.
66 # This file will configure S(i+1) to be a slave of S(i). If you
67 # want to specify the empty topology (no server replicates at
68 # all), you have to set $rpl_topology=none.
70 # $rpl_extra_connections_per_server
71 # By default, this script creates connections server_N and
72 # server_N_1. If you can set this variable to a number, the
74 # server_N, server_N_1, ..., server_N_$rpl_extra_connections_per_server
76 # $rpl_check_server_ids
77 # If $rpl_check_server_ids is set, this script checks that the
78 # @@server_id of all servers are different. This is normally
79 # guaranteed by mtr, so it is only useful for debugging.
81 # $rpl_skip_reset_master_and_slave
82 # By default, this script issues RESET MASTER and RESET SLAVE
83 # before CHANGE MASTER and START SLAVE. RESET MASTER and RESET
84 # SLAVE are suppressed if $rpl_skip_reset_master_and_slave is
87 # $rpl_skip_change_master
88 # By default, this script issues CHANGE MASTER so that all slaves
89 # are ready to run as specified by $rpl_topology. CHANGE MASTER
90 # is suppressed if $rpl_skip_change_master is set.
92 # $rpl_skip_start_slave
93 # By default, this script issues START SLAVE on all slaves
94 # specified by $rpl_topology. START SLAVE is suppressed if
95 # $rpl_skip_change_master is set.
98 # By default, this script only outputs a static text that says
99 # that rpl_init.inc was invoked. If $rpl_debug is set, additional
100 # debug info is printed. The debug info may be nondeterministic,
101 # so no test case should be checked in with $rpl_debug set.
104 # Timeout used when waiting for the slave threads to start.
105 # See include/wait_for_slave_param.inc
108 # Use option MASTER_AUTO_POSITION = 1 to CHANGE MASTER.
111 # ==== Side effects ====
113 # Changes current connection to server_1.
115 --source include/have_log_bin.inc
118 --let $include_filename= rpl_init.inc [topology=$rpl_topology]
119 --source include/begin_include_file.inc
124 --echo ----
Check input ----
125 --echo MASTER_MYPORT=
'$MASTER_MYPORT' SLAVE_MYPORT=
'$SLAVE_MYPORT' MASTER_MYPORT1=
'$MASTER_MYPORT1' SLAVE_MYPORT1=
'$SLAVE_MYPORT1'
128 # Allow $MASTER_MYPORT as alias for $SERVER_MYPORT_1
129 if (!$SERVER_MYPORT_1)
131 --let SERVER_MYPORT_1= $MASTER_MYPORT
133 # Allow $SLAVE_MYPORT as alias for $SERVER_MYPORT_2
134 if (!$SERVER_MYPORT_2)
136 --let SERVER_MYPORT_2= $SLAVE_MYPORT
138 # Allow $MASTER_MYPORT1 as alias for $SERVER_MYPORT_3
139 # (this alias is used by rpl_ndb tests)
140 if (!$SERVER_MYPORT_3)
142 --let SERVER_MYPORT_3= $MASTER_MYPORT1
144 # Allow $SLAVE_MYPORT1 as alias for $SERVER_MYPORT_4
145 # (this alias is used by rpl_ndb tests)
146 if (!$SERVER_MYPORT_4)
148 --let SERVER_MYPORT_4= $SLAVE_MYPORT1
150 # Check that $rpl_server_count is set
151 if (!$rpl_server_count)
153 --let $rpl_server_count= `SELECT
REPLACE(
'$rpl_topology',
'->',
',')`
154 if (`SELECT LOCATE(
',',
'$rpl_server_count')`)
156 --let $rpl_server_count= `SELECT GREATEST($rpl_server_count)`
160 --let $_rpl_extra_connections_per_server= $rpl_extra_connections_per_server
161 if ($_rpl_extra_connections_per_server ==
'')
163 --let $_rpl_extra_connections_per_server= 1
169 --echo ---- Setup connections and reset each server ----
179 # Create two connections to each server; reset master/slave, select
180 # database, set autoinc variables.
181 --let $_rpl_server= $rpl_server_count
186 --let $rpl_server_number= $_rpl_server
187 --let $rpl_connection_name= server_$_rpl_server
188 --source include/rpl_connect.inc
189 --let $_rpl_connection_number= 1
190 while ($_rpl_connection_number <= $_rpl_extra_connections_per_server)
192 --let $rpl_connection_name= server_$_rpl_server$underscore$_rpl_connection_number
193 --source include/rpl_connect.inc
194 --inc $_rpl_connection_number
198 --let $rpl_connection_name= server_$_rpl_server
199 --source include/rpl_connection.inc
201 if (!$rpl_skip_reset_master_and_slave)
211 # Signal that initialization is done and all connections created.
214 # Signal that the server is in a dirty state and needs to be restarted
215 # if the test is skipped. If the test is not skipped, it will continue
216 # to the end and execute its cleanup section (and check-testcase will
217 # report if you forget to clean up).
218 --source include/force_restart_if_skipped.inc
221 # Assert that all hosts have different server_ids
222 if ($rpl_check_server_ids)
226 --echo ----
Check that @@server_id is distinct
for all servers ----
229 --let $_rpl_server= $rpl_server_count
232 --let $_rpl_server2= $_rpl_server
234 while ($_rpl_server2)
236 --let $assert_text= Servers $_rpl_server and $_rpl_server2 should have different @@server_id
237 --let $assert_condition= [$_rpl_server:SELECT @@server_id AS
i,
i, 1] != [$_rpl_server2:SELECT @@server_id AS
i,
i, 1]
239 --source include/assert.inc
246 # $rpl_master_list must be set so that include/rpl_change_topology.inc
247 # knows which servers are initialized and not.
248 --let $rpl_master_list= `SELECT REPEAT(
'x', $rpl_server_count * LENGTH($rpl_server_count))`
249 --source include/rpl_change_topology.inc
252 if (!$rpl_skip_start_slave)
254 --source include/rpl_start_slaves.inc
258 --let $rpl_connection_name= server_1
259 --source include/rpl_connection.inc
262 --let $skip_restore_connection= 1
263 --let $include_filename= rpl_init.inc
264 --source include/end_include_file.inc