MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
wait_until_count_sessions.inc
1 # include/wait_until_count_sessions.inc
2 #
3 # SUMMARY
4 #
5 # Waits until the passed number ($count_sessions) of concurrent sessions or
6 # a smaller number was observed via
7 # SHOW STATUS LIKE 'Threads_connected'
8 # or the operation times out.
9 # Note:
10 # 1. We wait for $current_sessions <= $count_sessions because in the use case
11 # with count_sessions.inc before and wait_until_count_sessions.inc after
12 # the core of the test it could happen that the disconnects of sessions
13 # belonging to the preceeding test are not finished.
14 # sessions at test begin($count_sessions) = m + n
15 # sessions of the previous test which will be soon disconnected = n (n >= 0)
16 # sessions at test end ($current sessions, assuming the test disconnects
17 # all additional sessions) = m
18 # 2. Starting with 5.1 we could also use
19 # SELECT COUNT(*) FROM information_schema.processlist
20 # I stay with "SHOW STATUS LIKE 'Threads_connected'" because this
21 # runs in all versions 5.0+
22 #
23 #
24 # USAGE
25 #
26 # let $count_sessions= 3;
27 # --source include/wait_until_count_sessions.inc
28 #
29 # OR typical example of a test which uses more than one session
30 # Such a test could harm successing tests if there is no server shutdown
31 # and start between.
32 #
33 # If the testing box is slow than the disconnect of sessions belonging to
34 # the current test might happen when the successing test gets executed.
35 # This means the successing test might see activities like unexpected
36 # rows within the general log or the PROCESSLIST.
37 # Example from bug http://bugs.mysql.com/bug.php?id=40377
38 # --- bzr_mysql-6.0-rpl/.../r/log_state.result
39 # +++ bzr_mysql-6.0-rpl/.../r/log_state.reject
40 # @@ -25,6 +25,7 @@
41 # event_time user_host ... command_type argument
42 # TIMESTAMP USER_HOST ... Query create table t1(f1 int)
43 # TIMESTAMP USER_HOST ... Query select * from mysql.general_log
44 # +TIMESTAMP USER_HOST ... Quit
45 # ....
46 #
47 # What to do?
48 # -----------
49 # <start of test>
50 # # Determine initial number of connections (set $count_sessions)
51 # --source include/count_sessions.inc
52 # ...
53 # connect (con1,.....)
54 # ...
55 # connection default;
56 # ...
57 # disconnect con1;
58 # ...
59 # # Wait until we have reached the initial number of connections
60 # # or more than the sleep time above (10 seconds) has passed.
61 # # $count_sessions
62 # --source include/wait_until_count_sessions.inc
63 # <end of test>
64 #
65 # Important note about tests with unfortunate (= not cooperative
66 # to successing tests) architecture:
67 # connection con1;
68 # send SELECT ..., sleep(10)
69 # connection default;
70 # ...
71 # disconnect con1;
72 # <end of test>
73 # should be fixed by
74 # connection con1;
75 # send SELECT ..., sleep(10)
76 # connection default;
77 # ...
78 # connect con1;
79 # reap;
80 # connection default;
81 # disconnect con1;
82 # <end of test>
83 # and not only by appending include/wait_until_count_sessions.inc etc.
84 #
85 #
86 # EXAMPLE
87 #
88 # backup.test, grant3.test
89 #
90 #
91 # Created:
92 # 2009-01-14 mleich
93 # Modified:
94 # 2009-02-24 mleich Fix Bug#43114 wait_until_count_sessions too restrictive,
95 # random PB failures
96 #
97 
98 let $wait_counter= 100;
99 if ($wait_timeout)
100 {
101  let $wait_counter= `SELECT $wait_timeout * 10`;
102 }
103 # Reset $wait_timeout so that its value won't be used on subsequent
104 # calls, and default will be used instead.
105 let $wait_timeout= 0;
106 while ($wait_counter)
107 {
108  let $current_sessions= query_get_value(SHOW STATUS LIKE 'Threads_connected', Value, 1);
109  let $success= `SELECT $current_sessions <= $count_sessions`;
110  if ($success)
111  {
112  let $wait_counter= 0;
113  }
114  if (!$success)
115  {
116  real_sleep 0.1;
117  dec $wait_counter;
118  }
119 }
120 if (!$success)
121 {
122  --echo # Timeout in wait_until_count_sessions.inc
123  --echo # Number of sessions expected: <= $count_sessions found: $current_sessions
124  SHOW PROCESSLIST;
125  --die Timeout in wait_until_count_sessions.inc
126 }
127