1# ==== Purpose ====
2#
3# Reset all replication servers to a clean state:
4#
5#  - sync all slaves,
6#  - stop all slaves (STOP SLAVE),
7#  - remove all binlogs and relay logs (RESET MASTER and RESET SLAVE),
8#  - start all slaves again (START SLAVE).
9#
10# It does not execute CHANGE MASTER, so the replication topology is
11# kept intact.
12#
13#
14# ==== Usage ====
15#
16# [--let $rpl_only_running_threads= 1]
17# [--let $rpl_debug= 1]
18# [--let $slave_timeout= NUMBER]
19# --source include/rpl_end.inc
20#
21# Parameters:
22#   $rpl_only_running_threads
23#     If one or both of the IO and SQL threads is stopped, sync and
24#     stop only the threads that are running.  See
25#     include/rpl_sync.inc and include/stop_slave.inc for details.
26#
27#   $rpl_debug
28#     See include/rpl_init.inc
29#
30#   $slave_timeout
31#     Set the timeout when waiting for slave threads to stop and
32#     start, respectively.  See include/wait_for_slave_param.inc
33#
34# Note:
35#   This script will fail if Last_SQL_Error or Last_IO_Error is
36#   nonempty.  If you expect an error in the SQL thread, you should
37#   normally do this before you source include/rpl_reset.inc:
38#
39#     --source include/wait_for_slave_sql_error.inc
40#     --source include/stop_slave_io.inc
41#     RESET SLAVE;
42
43--let $include_filename= rpl_reset.inc
44--source include/begin_include_file.inc
45
46
47if (!$rpl_debug)
48{
49  --disable_query_log
50}
51
52
53--source include/rpl_sync.inc
54
55
56if ($rpl_debug)
57{
58  --echo ---- Stop and reset all servers ----
59}
60--let $_rpl_server= $rpl_server_count
61while ($_rpl_server)
62{
63  --let $rpl_connection_name= server_$_rpl_server
64  --source include/rpl_connection.inc
65
66  # Check if this server is configured to have a master
67  if (`SELECT SUBSTRING('$rpl_master_list', 1 + ($_rpl_server - 1) * $rpl_server_count_length, $rpl_server_count_length) != ''`)
68  {
69    --source include/stop_slave.inc
70    RESET SLAVE;
71  }
72  RESET MASTER;
73  --dec $_rpl_server
74}
75
76
77--source include/rpl_start_slaves.inc
78
79
80--let $include_filename= rpl_reset.inc
81--source include/end_include_file.inc
82