1# ==== Purpose ====
2#
3# Shut down replication initialized by include/rpl_init.inc.
4#
5# This syncs all servers, executes STOP SLAVE on all servers, executes
6# CHANGE MASTER on all servers, and disconnects all connections
7# configured by rpl_init.inc.
8#
9# It does not execute RESET MASTER or RESET SLAVE, because that would
10# remove binlogs which are possibly useful debug information in case
11# the test case later fails with a result mismatch.  If you need that,
12# source include/rpl_reset.inc before you source this file.
13#
14#
15# ==== Usage ====
16#
17# [--let $rpl_only_running_threads= 1]
18# [--let $rpl_debug= 1]
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# Note:
31#   This script will fail if Last_SQL_Error or Last_IO_Error is
32#   nonempty.  If you expect an error in the SQL thread, you should
33#   normally call this script as follows:
34#
35#     --source include/wait_for_slave_sql_error.inc
36#     --source include/stop_slave_io.inc
37#     RESET SLAVE;
38#     --let $rpl_only_running_threads= 1
39#     --source include/rpl_end.inc
40#
41#
42# ==== Side effects ====
43#
44# Changes the current connection to 'default'.
45
46
47--let $include_filename= rpl_end.inc
48--source include/begin_include_file.inc
49
50
51if (!$rpl_inited)
52{
53  --die ERROR IN TEST: rpl_end.inc was sourced when replication was not configured. Most likely, rpl_end.inc was sourced twice or rpl_init.inc has not been sourced.
54}
55
56
57if ($rpl_debug)
58{
59  --echo ---- Check that no slave thread has an error ----
60}
61
62--let $_rpl_server= $rpl_server_count
63while ($_rpl_server)
64{
65  --let $rpl_connection_name= server_$_rpl_server
66  --source include/rpl_connection.inc
67
68  # Only check slave threads for error on hosts that were at some
69  # point configured as slave.
70  --let $_tmp= query_get_value(SHOW SLAVE STATUS, Master_Host, 1)
71  if ($_tmp != 'No such row')
72  {
73    --source include/check_slave_no_error.inc
74  }
75
76  --dec $_rpl_server
77}
78
79--source include/rpl_sync.inc
80--source include/rpl_stop_slaves.inc
81
82if (!$rpl_debug)
83{
84  --disable_query_log
85}
86--let $_rpl_server= $rpl_server_count
87while ($_rpl_server)
88{
89  --let $rpl_connection_name= server_$_rpl_server
90  --source include/rpl_connection.inc
91
92  # Clear Using_Gtid in SHOW SLAVE STATUS to keep check_testcase happy.
93  CHANGE MASTER TO master_log_file='';
94
95  --dec $_rpl_server
96}
97
98# mtr configures server 2 to be a slave before it runs the test. We
99# have to restore that state now, so we change topology to 1->2.
100--let $rpl_topology= none
101--source include/rpl_change_topology.inc
102
103
104--connection default
105--let $_rpl_server= $rpl_server_count
106--let $_rpl_one= _1
107while ($_rpl_server)
108{
109  --disconnect server_$_rpl_server
110  --disconnect server_$_rpl_server$_rpl_one
111  --dec $_rpl_server
112}
113
114--let $rpl_inited= 0
115
116# Do not restore connection, because we have disconnected it.
117--let $skip_restore_connection= 1
118--let $include_filename= rpl_end.inc
119--source include/end_include_file.inc
120