MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
wait_for_status_var.inc
1 # ==== Purpose ====
2 #
3 # Waits until a variable from SHOW STATUS has returned a specified
4 # value, or until a timeout is reached.
5 #
6 # ==== Usage ====
7 #
8 # let $status_var= Threads_connected;
9 # let $status_var_value= 1;
10 # --source include/wait_for_status_var.inc
11 #
12 # Parameters:
13 #
14 # $status_var, $status_var_value
15 # This macro will wait until the variable of SHOW STATUS
16 # named $status_var gets the value $status_var_value. See
17 # the example above.
18 #
19 # $status_type= GLOBAL|SESSION
20 # To specify the type (attribute) of status variable and
21 # run either SHOW GLOBAL STATUS or SHOW SESSION STATUS.
22 #
23 # $status_var_comparsion
24 # By default, this file waits until $status_var becomes equal to
25 # $status_var_value. If you want to wait until $status_var
26 # becomes *unequal* to $status_var_value, set this parameter to the
27 # string '!=', like this:
28 # let $status_var_comparsion= !=;
29 #
30 # $status_timeout
31 # The default timeout is 1 minute. You can change the timeout by
32 # setting $status_timeout. The unit is tenths of seconds.
33 #
34 
35 if (`SELECT STRCMP('$status_type', '') * STRCMP(UPPER('$status_type'), 'SESSION') * STRCMP(UPPER('$status_type'), 'GLOBAL')`)
36 {
37  --echo **** ERROR: Unknown type of variable status_type: allowed values are: SESSION or GLOBAL ****
38  die;
39 }
40 
41 let $_status_timeout_counter= $status_timeout;
42 if (!$_status_timeout_counter)
43 {
44  let $_status_timeout_counter= 600;
45 }
46 
47 let $_status_var_comparsion= $status_var_comparsion;
48 if (!$_status_var_comparsion)
49 {
50  let $_status_var_comparsion= =;
51 }
52 
53 # Get type of variable
54 let $_is_number= 0;
55 if (`SELECT '$status_var_value' REGEXP '^[\+\-]*[0-9]+(\.[0-9]+)*\$'`)
56 {
57  let $_is_number= 1;
58 }
59 
60 let $_show_status_value= query_get_value("SHOW $status_type STATUS LIKE '$status_var'", Value, 1);
61 
62 # Set way of comparing
63 let $_query= SELECT NOT('$_show_status_value' $_status_var_comparsion '$status_var_value');
64 if ($_is_number)
65 {
66  let $_query= SELECT NOT($_show_status_value $_status_var_comparsion $status_var_value);
67 }
68 
69 while (`$_query`)
70 {
71  if (!$_status_timeout_counter)
72  {
73  --echo **** ERROR: failed while waiting for $status_type $status_var $_status_var_comparsion $status_var_value ****
74  --echo Note: the following output may have changed since the failure was detected
75  --echo **** Showing STATUS, PROCESSLIST ****
76  eval SHOW $status_type STATUS LIKE '$status_var';
77  SHOW PROCESSLIST;
78  die;
79  }
80  dec $_status_timeout_counter;
81  sleep 0.1;
82  let $_show_status_value= query_get_value("SHOW $status_type STATUS LIKE '$status_var'", Value, 1);
83  let $_query= SELECT NOT('$_show_status_value' $_status_var_comparsion '$status_var_value');
84  if ($_is_number)
85  {
86  let $_query= SELECT NOT($_show_status_value $_status_var_comparsion $status_var_value);
87  }
88 }