MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
check_concurrent_insert.inc
1 #
2 # SUMMARY
3 # Check if statement reading table '$table' allows concurrent
4 # inserts in it.
5 #
6 # PARAMETERS
7 # $table Table in which concurrent inserts should be allowed.
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 executed while
43 # statement being checked has its tables locked.
44 # We use wait_condition.inc instead of simply reaping
45 # concurrent insert here in order to avoid deadlocks if test
46 # fails and to time out gracefully instead.
47 let $wait_condition=
48  select count(*) = 0 from information_schema.processlist
49  where info = "insert into $table (i) values (0)";
50 --source include/wait_condition.inc
51 
52 --disable_result_log
53 --disable_query_log
54 
55 if ($success)
56 {
57 # Apparently concurrent insert was successfully executed.
58 # To be safe against wait_condition.inc succeeding due to
59 # races let us first reap concurrent insert to ensure that
60 # it has really been successfully executed.
61 connection $con_aux2;
62 --reap
63 connection default;
64 set debug_sync= 'now SIGNAL go';
65 connection $con_aux1;
66 --reap
67 connection default;
68 --echo Success: '$statement' allows concurrent inserts into '$table'.
69 }
70 if (!$success)
71 {
72 # Waiting has timed out. Apparently concurrent insert was blocked.
73 # So to be able to continue we need to end our statement first.
74 set debug_sync= 'now SIGNAL go';
75 connection $con_aux1;
76 --reap
77 connection $con_aux2;
78 --reap
79 connection default;
80 --echo Error: '$statement' doesn't allow concurrent inserts into '$table'!
81 }
82 
83 --eval delete from $table where i = 0;
84 
85 if ($restore_table)
86 {
87 --eval truncate table $restore_table;
88 --eval insert into $restore_table select * from t_backup;
89 drop temporary table t_backup;
90 }
91 
92 # Clean-up. Reset DEBUG_SYNC facility after use.
93 set debug_sync= "RESET";
94 
95 --enable_result_log
96 --enable_query_log