3 # Sync all servers in an arbitrary replication topology. This works
4 # only if the servers have been configured with rpl_init.inc (and
5 # possibly rpl_change_topology.inc).
10 # [--let $rpl_only_running_threads= 1]
11 # [--let $use_gtids= 1]
12 # [--let $rpl_debug= 1]
13 # [--let $slave_timeout= NUMBER]
14 # --source include/rpl_sync.inc
17 # $rpl_only_running_threads
18 # By default, this script assumes that both the IO thread and the
19 # SQL thread are running and fails if one of them is stopped. If
20 # $rpl_only_running_threads is set, this script first checks
21 # which slave threads are running:
22 # - If both threads are running, sync both threads with master.
23 # - If only IO thread is running, sync IO thread with master.
24 # - If only SQL thread is running, sync SQL thread with IO thread.
25 # - If no thread is running, don't sync.
28 # If set, uses GTIDs instead of filename and offset for positions.
31 # Set the timeout when waiting for threads to sync. See
32 # include/wait_for_slave_param.inc
35 # See include/rpl_init.inc
38 # ==== Side effects ====
40 # Does not change the current connection (note that this is different
41 # from mysqltest's built-in sync_slave_with_master command).
44 --let $include_filename= rpl_sync.inc
45 --source include/begin_include_file.inc
48 # Compute $rpl_sync_chain if needed. We could have done this in
49 # rpl_change_topology.inc, but instead we do it here because that
50 # means we only compute $rpl_sync_chain when it is needed.
51 if ($rpl_sync_chain_dirty)
53 --source include/rpl_generate_sync_chain.inc
54 --let $rpl_sync_chain_dirty= 0
60 --echo \$rpl_sync_chain =
'$rpl_sync_chain' \$rpl_only_running_threads= $rpl_only_running_threads
63 if (!$rpl_server_count_length)
65 --die \$rpl_server_count_length is not
set. Did you call rpl_init.inc?
70 --let $_rpl_connect= 0
72 # $rpl_sync_chain consists of a sequence of sync chains. Each sync
75 # <space><server1_1><server1_2>...<server1_N>
77 # So the space character indicates that a new sync chain starts.
78 --let $_rpl_server= `SELECT TRIM(SUBSTR(
'$rpl_sync_chain', 1 + ($_rpl_i - 1) * $rpl_server_count_length, $rpl_server_count_length))`
84 --echo [sync server_$_rpl_prev_server -> server_$_rpl_server]
86 if ($rpl_only_running_threads)
88 --connection server_$_rpl_server
89 --let $_rpl_slave_io_running= query_get_value(SHOW SLAVE
STATUS, Slave_IO_Running, 1)
90 --let $_rpl_slave_sql_running= query_get_value(SHOW SLAVE
STATUS, Slave_SQL_Running, 1)
93 --echo Sync IO: $_rpl_slave_io_running; Sync SQL: $_rpl_slave_sql_running
95 if ($_rpl_slave_io_running != No)
97 --connection server_$_rpl_prev_server
98 --let $sync_slave_connection= server_$_rpl_server
99 if ($_rpl_slave_sql_running != No)
101 --source include/sync_slave_sql_with_master.inc
103 if ($_rpl_slave_sql_running == No)
105 --source include/sync_slave_io_with_master.inc
108 if ($_rpl_slave_io_running == No)
110 if ($_rpl_slave_sql_running != No)
112 --source include/sync_slave_sql_with_io.inc
116 if (!$rpl_only_running_threads)
118 --connection server_$_rpl_prev_server
119 --let $saved_value= $sync_slave_connection
120 --let $sync_slave_connection= server_$_rpl_server
121 --source include/sync_slave_sql_with_master.inc
122 --let $sync_slave_connection= $saved_value
126 # This happens at the beginning of a new sync subchain and at the
127 # end of the full sync chain.
131 --let $_rpl_server= `SELECT TRIM(SUBSTR(
'$rpl_sync_chain', 1 + ($_rpl_i - 1) * $rpl_server_count_length, $rpl_server_count_length))`
140 --let $_rpl_prev_server= $_rpl_server
145 --let $include_filename= rpl_sync.inc
146 --source include/end_include_file.inc