1#
2# SUMMARY
3#   Check that a statement is incompatible with FLUSH TABLES WITH READ LOCK.
4#
5# PARAMETERS
6#   $con_aux1      Name of the 1st aux connection to be used by this script.
7#   $con_aux2      Name of the 2nd aux connection to be used by this script.
8#   $statement     The statement to be checked.
9#   $cleanup_stmt1 The 1st statement to be run in order to revert effects
10#                  of statement to be checked.
11#   $cleanup_stmt2 The 2nd statement to be run in order to revert effects
12#                  of statement to be checked.
13#   $skip_3rd_chk  Skip the 3rd stage of checking. The purpose of the third
14#                  stage is to check that metadata locks taken by this
15#                  statement are incompatible with metadata locks taken
16#                  by FTWRL.
17#
18# EXAMPLE
19#   flush_read_lock.test
20#
21--disable_result_log
22--disable_query_log
23
24# Reset DEBUG_SYNC facility for safety.
25set debug_sync= "RESET";
26
27#
28# First, check that the statement cannot be run under FTWRL.
29#
30flush tables with read lock;
31--disable_abort_on_error
32--eval $statement
33--enable_abort_on_error
34let $err= $mysql_errno;
35if ($err)
36{
37--echo Success: Was not able to run '$statement' under FTWRL.
38unlock tables;
39}
40if (!$err)
41{
42--echo Error: Was able to run '$statement' under FTWRL!
43unlock tables;
44if ($cleanup_stmt1)
45{
46--eval $cleanup_stmt1;
47}
48if ($cleanup_stmt2)
49{
50--eval $cleanup_stmt2;
51}
52}
53
54
55#
56# Then check that this statement is blocked by FTWRL
57# that is active in another connection.
58#
59connection $con_aux1;
60flush tables with read lock;
61
62connection default;
63--send_eval $statement;
64
65connection $con_aux1;
66
67--enable_result_log
68--enable_query_log
69let $wait_condition=
70  select count(*) = 1 from information_schema.processlist
71  where state = "Waiting for backup lock" and
72        info = "$statement";
73--source include/wait_condition.inc
74--disable_result_log
75--disable_query_log
76
77if ($success)
78{
79--echo Success: '$statement' is blocked by FTWRL active in another connection.
80}
81if (!$success)
82{
83--echo Error: '$statement' wasn't blocked by FTWRL active in another connection!
84}
85unlock tables;
86
87connection default;
88--reap
89
90if ($cleanup_stmt1)
91{
92--eval $cleanup_stmt1;
93}
94if ($cleanup_stmt2)
95{
96--eval $cleanup_stmt2;
97}
98
99if (!$skip_3rd_check)
100{
101#
102# Finally, let us check that FTWRL will not succeed if this
103# statement is active but has already closed its tables.
104#
105connection default;
106--eval set debug_sync='execute_command_after_close_tables SIGNAL parked WAIT_FOR go';
107--send_eval $statement;
108
109connection $con_aux1;
110set debug_sync="now WAIT_FOR parked";
111--send flush tables with read lock
112
113connection $con_aux2;
114--enable_result_log
115--enable_query_log
116let $wait_condition=
117  select count(*) = 1 from information_schema.processlist
118  where state = "Waiting for backup lock" and
119        info = "flush tables with read lock";
120--source include/wait_condition.inc
121--disable_result_log
122--disable_query_log
123
124if ($success)
125{
126--echo Success: FTWRL is blocked when '$statement' is active in another connection.
127}
128if (!$success)
129{
130--echo Error: FTWRL isn't blocked when '$statement' is active in another connection!
131}
132set debug_sync="now SIGNAL go";
133connection default;
134--reap
135connection $con_aux1;
136--reap
137unlock tables;
138connection default;
139
140set debug_sync= "RESET";
141
142if ($cleanup_stmt1)
143{
144--eval $cleanup_stmt1;
145}
146if ($cleanup_stmt2)
147{
148--eval $cleanup_stmt2;
149}
150}
151
152--enable_result_log
153--enable_query_log
154