MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
check_no_concurrent_insert.inc
1 #
2 # SUMMARY
3 # Check that statement reading table '$table' doesn't allow concurrent
4 # inserts in it.
5 #
6 # PARAMETERS
7 # $table Table in which concurrent inserts should be disallowed.
8 # $con_aux1 Name of the first auxiliary connection to be used by this
9 # script.
10 # $con_aux2 Name of the second auxiliary connection to be used by this
11 # script.
12 # $statement Statement to be checked.
13 # $restore_table Table which might be modified by statement to be checked
14 # and thus needs backing up before its execution and
15 # restoring after it (can be empty).
16 #
17 # EXAMPLE
18 # lock_sync.test
19 #
20 --disable_result_log
21 --disable_query_log
22 
23 # Reset DEBUG_SYNC facility for safety.
24 set debug_sync= "RESET";
25 
26 if ($restore_table)
27 {
28 --eval create temporary table t_backup select * from $restore_table;
29 }
30 
31 connection $con_aux1;
32 set debug_sync='after_lock_tables_takes_lock SIGNAL parked WAIT_FOR go';
33 --send_eval $statement;
34 
35 connection $con_aux2;
36 set debug_sync='now WAIT_FOR parked';
37 --send_eval insert into $table (i) values (0);
38 
39 --enable_result_log
40 --enable_query_log
41 connection default;
42 # Wait until concurrent insert is successfully blocked because
43 # of our statement.
44 let $wait_condition=
45  select count(*) = 1 from information_schema.processlist
46  where state = "Waiting for table level lock" and
47  info = "insert into $table (i) values (0)";
48 --source include/wait_condition.inc
49 
50 --disable_result_log
51 --disable_query_log
52 
53 set debug_sync= 'now SIGNAL go';
54 connection $con_aux1;
55 --reap
56 connection $con_aux2;
57 --reap
58 connection default;
59 
60 if ($success)
61 {
62 --echo Success: '$statement' doesn't allow concurrent inserts into '$table'.
63 }
64 if (!$success)
65 {
66 --echo Error: '$statement' allows concurrent inserts into '$table'!
67 }
68 
69 --eval delete from $table where i = 0;
70 
71 if ($restore_table)
72 {
73 --eval truncate table $restore_table;
74 --eval insert into $restore_table select * from t_backup;
75 drop temporary table t_backup;
76 }
77 
78 # Clean-up. Reset DEBUG_SYNC facility after use.
79 set debug_sync= "RESET";
80 
81 --enable_result_log
82 --enable_query_log