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 $rpl_debug= 1]
12 # [--let $slave_timeout= NUMBER]
13 # --source include/rpl_sync.inc
16 # $rpl_only_running_threads
17 # By default, this script assumes that both the IO thread and the
18 # SQL thread are running and fails if one of them is stopped. If
19 # $rpl_only_running_threads is set, this script first checks
20 # which slave threads are running:
21 # - If both threads are running, sync both threads with master.
22 # - If only IO thread is running, sync IO thread with master.
23 # - If only SQL thread is running, sync SQL thread with IO thread.
24 # - If no thread is running, don't sync.
27 # Set the timeout when waiting for threads to sync. See
28 # include/wait_for_slave_param.inc
31 # See include/rpl_init.inc
34 # ==== Side effects ====
36 # Does not change the current connection (note that this is different
37 # from mysqltest's built-in sync_slave_with_master command).
40 --let $include_filename= rpl_sync.inc
41 --source include/begin_include_file.inc
44 # Compute $rpl_sync_chain if needed. We could have done this in
45 # rpl_change_topology.inc, but instead we do it here because that
46 # means we only compute $rpl_sync_chain when it is needed.
47 if ($rpl_sync_chain_dirty)
49 --source include/rpl_generate_sync_chain.inc
50 --let $rpl_sync_chain_dirty= 0
56 --echo \$rpl_sync_chain = '$rpl_sync_chain' \$rpl_only_running_threads= $rpl_only_running_threads
59 if (!$rpl_server_count_length)
61 --die \$rpl_server_count_length is not set. Did you call rpl_init.inc?
66 --let $_rpl_connect= 0
68 # $rpl_sync_chain consists of a sequence of sync chains. Each sync
71 # <space><server1_1><server1_2>...<server1_N>
73 # So the space character indicates that a new sync chain starts.
74 --let $_rpl_server= `SELECT TRIM(SUBSTR('$rpl_sync_chain', 1 + ($_rpl_i - 1) * $rpl_server_count_length, $rpl_server_count_length))`
80 --echo [sync server_$_rpl_prev_server -> server_$_rpl_server]
82 if ($rpl_only_running_threads)
84 --connection server_$_rpl_server
85 --let $_rpl_slave_io_running= query_get_value(SHOW SLAVE STATUS, Slave_IO_Running, 1)
86 --let $_rpl_slave_sql_running= query_get_value(SHOW SLAVE STATUS, Slave_SQL_Running, 1)
89 --echo Sync IO: $_rpl_slave_io_running; Sync SQL: $_rpl_slave_sql_running
91 --let $_rpl_slave_io_running= `SELECT IF('$_rpl_slave_io_running' != 'No', 1, '')`
92 --let $_rpl_slave_sql_running= `SELECT IF('$_rpl_slave_sql_running' = 'Yes', 1, '')`
93 if ($_rpl_slave_io_running)
95 --connection server_$_rpl_prev_server
96 if ($_rpl_slave_sql_running)
100 --let $_rpl_master_file= query_get_value("SHOW MASTER STATUS", File, 1)
101 --let $_rpl_master_pos= query_get_value("SHOW MASTER STATUS", Position, 1)
102 --echo syncing master_file='$_rpl_master_file' master_pos='$_rpl_master_pos'
104 --sync_slave_with_master server_$_rpl_server
106 if (!$_rpl_slave_sql_running)
108 --let $sync_slave_connection= server_$_rpl_server
109 --source include/sync_slave_io_with_master.inc
112 if (!$_rpl_slave_io_running)
114 if ($_rpl_slave_sql_running)
116 --source include/sync_slave_sql_with_io.inc
120 if (!$rpl_only_running_threads)
122 --connection server_$_rpl_prev_server
125 --let $_rpl_master_file= query_get_value("SHOW MASTER STATUS", File, 1)
126 --let $_rpl_master_pos= query_get_value("SHOW MASTER STATUS", Position, 1)
127 --echo syncing master_file='$_rpl_master_file' master_pos='$_rpl_master_pos'
129 --sync_slave_with_master server_$_rpl_server
133 # This happens at the beginning of a new sync subchain and at the
134 # end of the full sync chain.
138 --let $_rpl_server= `SELECT TRIM(SUBSTR('$rpl_sync_chain', 1 + ($_rpl_i - 1) * $rpl_server_count_length, $rpl_server_count_length))`
147 --let $_rpl_prev_server= $_rpl_server
152 --let $include_filename= rpl_sync.inc
153 --source include/end_include_file.inc