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/wait_for_slave_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 5 minutes. You can change the timeout by 33# setting $slave_timeout. The unit is seconds. 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 49let $_slave_timeout= $slave_timeout; 50if (!$_slave_timeout) 51{ 52 let $_slave_timeout= 300; 53 if ($VALGRIND_TEST) 54 { 55 let $_slave_timeout= 1500; 56 } 57} 58 59if ($slave_error_param == '') 60{ 61 --let $slave_error_param= 1 62} 63 64let $_slave_param_comparison= $slave_param_comparison; 65if (!$_slave_param_comparison) 66{ 67 let $_slave_param_comparison= =; 68} 69 70if ($rpl_debug) 71{ 72 --echo Waiting until '$slave_param' $_slave_param_comparison '$slave_param_value' [\$slave_error_param='$slave_error_param'] 73} 74 75--let $_slave_check_configured= query_get_value("SHOW SLAVE STATUS", Slave_IO_Running, 1) 76 77if ($_slave_check_configured == 'No such row') 78{ 79 --echo **** ERROR: SHOW SLAVE STATUS returned empty result set. Slave not configured. **** 80 --source include/show_rpl_debug_info.inc 81 --die SHOW SLAVE STATUS returned empty result set. Slave not configured. 82} 83 84# mysqltest doesn't provide any better way to multiply by 10 85--let $_wait_for_slave_param_zero= 0 86--let $_slave_timeout_counter= $_slave_timeout$_wait_for_slave_param_zero 87--let $_slave_continue= 1 88while ($_slave_continue) 89{ 90 --let $_show_slave_status_value= query_get_value("SHOW SLAVE STATUS", $slave_param, 1) 91 92 # Check if an error condition is reached. 93 if (!$slave_error_param) 94 { 95 --let $_show_slave_status_error_value= query_get_value("SHOW SLAVE STATUS", $slave_error_param, 1) 96 if ($_show_slave_status_error_value) 97 { 98 --echo **** ERROR: $slave_error_param = '$_show_slave_status_error_value' while waiting for slave parameter $slave_param $_slave_param_comparison $slave_param_value **** 99 --source include/show_rpl_debug_info.inc 100 --die Error condition reached in include/wait_for_slave_param.inc 101 } 102 } 103 104 # Check if the termination condition is reached. 105 --let $_slave_continue= `SELECT NOT('$_show_slave_status_value' $_slave_param_comparison '$slave_param_value')` 106 107 # Decrease timer, and check if the timeout is reached. 108 if ($_slave_continue) 109 { 110 --dec $_slave_timeout_counter 111 if (!$_slave_timeout_counter) 112 { 113 --echo **** ERROR: timeout after $_slave_timeout seconds while waiting for slave parameter $slave_param $_slave_param_comparison $slave_param_value **** 114 --source include/show_rpl_debug_info.inc 115 --die Timeout in include/wait_for_slave_param.inc 116 } 117 --sleep 0.1 118 } 119} 120 121 122--let $include_filename= wait_for_slave_param.inc [$slave_param] 123--source include/end_include_file.inc 124