MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
wait_for_slave_param.inc
1 # ==== Purpose ====
2 #
3 # Waits until SHOW SLAVE STATUS has returned a specified value, or
4 # until a timeout is reached.
5 #
6 #
7 # ==== Usage ====
8 #
9 # --let $slave_param= Slave_SQL_Running
10 # --let $slave_param_value= No
11 # [--let $slave_param_comparison= [ < | <= | >= | > | = | != ]]
12 # [--let $slave_timeout= NUMBER]
13 # [--let $slave_error_param= [Slave_SQL_Errno | Slave_IO_Errno]]
14 # [--let $rpl_debug= 1]
15 # --source include/slave_wait_param.inc
16 #
17 # Parameters:
18 #
19 # $slave_param, $slave_param_value
20 # This macro will wait until the column of the output of SHOW SLAVE
21 # STATUS named $slave_param gets the value $slave_param_value. See
22 # the example above.
23 #
24 # $slave_param_comparison
25 # By default, this file waits until $slave_param becomes equal to
26 # $slave_param_value. If you want to wait until $slave_param
27 # becomes *unequal* to $slave_param_value, set this parameter to the
28 # string '!=', like this:
29 # --let $slave_param_comparison= !=
30 #
31 # $slave_timeout
32 # The default timeout is 60 seconds. You can change the timeout by
33 # setting $slave_timeout. The unit is one second.
34 #
35 # $slave_error_param
36 # If set, this script will check if the column of the output from
37 # SHOW SLAVE STATUS named $slave_error_param is nonzero. If it is,
38 # this script will faile immediately. Typically, this should be set
39 # to Last_IO_Errno or Last_SQL_Errno.
40 #
41 # $rpl_debug
42 # See include/rpl_init.inc
43 
44 
45 --let $include_filename= wait_for_slave_param.inc [$slave_param]
46 --source include/begin_include_file.inc
47 
48 --let $default_timeout= 30
49 --let $sleep_freq= 10
50 --let $sleep_time= `select 1.0 / $sleep_freq`
51 
52 --let $start_to_wait=`select current_timestamp()`
53 
54 let $_slave_timeout= $slave_timeout;
55 if (!$_slave_timeout)
56 {
57  let $_slave_timeout= `select $default_timeout * $sleep_freq`;
58 }
59 
60 if ($slave_error_param == '')
61 {
62  --let $slave_error_param= 1
63 }
64 
65 let $_slave_param_comparison= $slave_param_comparison;
66 if (!$_slave_param_comparison)
67 {
68  let $_slave_param_comparison= =;
69 }
70 
71 if ($rpl_debug)
72 {
73  --echo Waiting until '$slave_param' $_slave_param_comparison '$slave_param_value' [timeout='$_slave_timeout', \$slave_error_param='$slave_error_param']
74 }
75 
76 --let $_slave_check_configured= query_get_value("SHOW SLAVE STATUS", Slave_IO_Running, 1)
77 
78 if ($_slave_check_configured == 'No such row')
79 {
80  --echo **** ERROR: SHOW SLAVE STATUS returned empty result set. Slave not configured. ****
81  --source include/show_rpl_debug_info.inc
82  --die SHOW SLAVE STATUS returned empty result set. Slave not configured.
83 }
84 
85 --let $_slave_timeout_counter= `select $_slave_timeout * $sleep_freq`
86 --let $_slave_continue= 1
87 while ($_slave_continue)
88 {
89  --let $_show_slave_status_value= query_get_value("SHOW SLAVE STATUS", $slave_param, 1)
90 
91  # Check if an error condition is reached.
92  if (!$slave_error_param)
93  {
94  --let $_show_slave_status_error_value= query_get_value("SHOW SLAVE STATUS", $slave_error_param, 1)
95  if ($_show_slave_status_error_value)
96  {
97  --echo **** ERROR: $slave_error_param = '$_show_slave_status_error_value' while waiting for slave parameter $slave_param $_slave_param_comparison $slave_param_value ****
98  --source include/show_rpl_debug_info.inc
99  --die Error condition reached in include/wait_for_slave_param.inc
100  }
101  }
102 
103  # Check if the termination condition is reached.
104  --let $_slave_continue= `SELECT NOT('$_show_slave_status_value' $_slave_param_comparison '$slave_param_value')`
105 
106  # Decrease timer, and check if the timeout is reached.
107  if ($_slave_continue)
108  {
109  --dec $_slave_timeout_counter
110  if (!$_slave_timeout_counter)
111  {
112  --let $end_to_wait=`select current_timestamp()`
113 
114  --echo **** ERROR: timeout after $_slave_timeout ($end_to_wait - $start_to_wait) seconds while waiting for slave parameter $slave_param $_slave_param_comparison $slave_param_value ****
115  --source include/show_rpl_debug_info.inc
116  --die Timeout in include/wait_for_slave_param.inc
117  }
118  --sleep $sleep_time
119  }
120 }
121 
122 
123 --let $include_filename= wait_for_slave_param.inc [$slave_param]
124 --source include/end_include_file.inc