1# 2# SUMMARY 3# Check that a statement is compatible 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_stmt The statement to be run in order to revert effects of 10# the statement to be checked. 11# $skip_3rd_chk Skip the 3rd stage of checking. The purpose of the third 12# stage is to check that metadata locks taken by this 13# statement are compatible with metadata locks taken 14# by FTWRL. 15# 16# EXAMPLE 17# flush_read_lock.test 18# 19--disable_result_log 20--disable_query_log 21 22# Reset DEBUG_SYNC facility for safety. 23set debug_sync= "RESET"; 24 25# 26# First, check that the statement can be run under FTWRL. 27# 28flush tables with read lock; 29--disable_abort_on_error 30--eval $statement 31--enable_abort_on_error 32let $err= $mysql_errno; 33if (!$err) 34{ 35--echo Success: Was able to run '$statement' under FTWRL. 36unlock tables; 37if ($cleanup_stmt) 38{ 39--eval $cleanup_stmt; 40} 41} 42if ($err) 43{ 44--echo Error: Wasn't able to run '$statement' under FTWRL! 45unlock tables; 46} 47 48# 49# Then check that this statement won't be blocked by FTWRL 50# that is active in another connection. 51# 52connection $con_aux1; 53flush tables with read lock; 54 55connection default; 56--send_eval $statement; 57 58connection $con_aux1; 59 60--enable_result_log 61--enable_query_log 62let $wait_condition= 63 select count(*) = 0 from information_schema.processlist 64 where info = "$statement"; 65--source include/wait_condition.inc 66--disable_result_log 67--disable_query_log 68 69if ($success) 70{ 71--echo Success: Was able to run '$statement' with FTWRL active in another connection. 72 73connection default; 74# Apparently statement was successfully executed and so 75# was not blocked by FTWRL. 76# To be safe against wait_condition.inc succeeding due to 77# races let us first reap the statement being checked to 78# ensure that it has been successfully executed. 79--reap 80 81connection $con_aux1; 82unlock tables; 83 84connection default; 85} 86if (!$success) 87{ 88--echo Error: Wasn't able to run '$statement' with FTWRL active in another connection! 89unlock tables; 90connection default; 91--reap 92} 93 94if ($cleanup_stmt) 95{ 96--eval $cleanup_stmt; 97} 98 99if (!$skip_3rd_check) 100{ 101# 102# Finally, let us check that FTWRL will succeed if this statement 103# is active but has already closed its tables. 104# 105connection default; 106set 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(*) = 0 from information_schema.processlist 118 where info = "flush tables with read lock"; 119--source include/wait_condition.inc 120--disable_result_log 121--disable_query_log 122 123if ($success) 124{ 125--echo Success: Was able to run FTWRL while '$statement' was active in another connection. 126connection $con_aux1; 127# Apparently FTWRL was successfully executed and so was not blocked by 128# the statement being checked. To be safe against wait_condition.inc 129# succeeding due to races let us first reap the FTWRL to ensure that it 130# has been successfully executed. 131--reap 132unlock tables; 133set debug_sync="now SIGNAL go"; 134connection default; 135--reap 136} 137if (!$success) 138{ 139--echo Error: Wasn't able to run FTWRL while '$statement' was active in another connection! 140set debug_sync="now SIGNAL go"; 141connection default; 142--reap 143connection $con_aux1; 144--reap 145unlock tables; 146connection default; 147} 148 149set debug_sync= "RESET"; 150if ($cleanup_stmt) 151{ 152--eval $cleanup_stmt; 153} 154 155} 156 157--enable_result_log 158--enable_query_log 159