MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stop_slave.inc
1 # ==== Purpose ====
2 #
3 # Issues STOP SLAVE on the current connection. Then waits until both
4 # the IO and SQL threads have stopped, or until a timeout is reached.
5 #
6 # Please use this instead of 'STOP SLAVE', to reduce the risk of races
7 # in test cases.
8 #
9 # This will fail if the slave IO or SQL thread has an error. If you
10 # expect an error in the IO thread, use
11 # include/wait_for_slave_io_error.inc and include/stop_slave_sql.inc.
12 #
13 #
14 # ==== Usage ====
15 #
16 # [--let $rpl_only_running_threads= 1]
17 # [--let $slave_timeout= NUMBER]
18 # [--let $rpl_debug= 1]
19 # --source include/stop_slave.inc
20 #
21 # Parameters:
22 # $rpl_only_running_threads
23 # By default, this script executes STOP SLAVE unconditionally.
24 # This generates a warnings if one or both slave threads are
25 # already stopped. If $rpl_only_running_threads is set, this
26 # script checks which slave threads are running, and issues either
27 # STOP SLAVE, STOP SLAVE SQL_THREAD, STOP SLAVE IO_THREAD, or
28 # nothing.
29 #
30 # $slave_timeout
31 # See include/wait_for_slave_param.inc
32 #
33 # $rpl_debug
34 # See include/rpl_init.inc
35 
36 
37 --let $include_filename= stop_slave.inc
38 --source include/begin_include_file.inc
39 
40 
41 if (!$rpl_debug)
42 {
43  --disable_query_log
44 }
45 
46 
47 if ($rpl_only_running_threads)
48 {
49  --let $_slave_sql_running= query_get_value(SHOW SLAVE STATUS, Slave_SQL_Running, 1)
50  --let $_slave_io_running= query_get_value(SHOW SLAVE STATUS, Slave_IO_Running, 1)
51  if ($rpl_debug)
52  {
53  --echo Stop SQL: $_slave_sql_running; Stop IO: $_slave_io_running
54  }
55 
56  --let $_slave_running_bits= `SELECT IF('$_slave_io_running' = 'Yes', 1, 0) + IF('$_slave_sql_running' = 'Yes', 2, 0)`
57  if ($_slave_running_bits)
58  {
59  --dec $_slave_running_bits
60  # $_slave_running_bits=1: io thread running
61  if (!$_slave_running_bits)
62  {
63  --source include/stop_slave_io.inc
64  }
65  --dec $_slave_running_bits
66  # $_slave_running_bits=2: sql thread running
67  if (!$_slave_running_bits)
68  {
69  --source include/stop_slave_sql.inc
70  }
71  --dec $_slave_running_bits
72  # $_slave_running_bits=2: both threads running
73  if (!$_slave_running_bits)
74  {
75  STOP SLAVE;
76  --source include/wait_for_slave_to_stop.inc
77  }
78  }
79 }
80 if (!$rpl_only_running_threads)
81 {
82  STOP SLAVE;
83  --source include/wait_for_slave_to_stop.inc
84 }
85 
86 
87 --let $include_filename= stop_slave.inc
88 --source include/end_include_file.inc