function apdqc_kill_metadata_lock in Asynchronous Prefetch Database Query Cache 7
Checks db processlist for metadata lock & kills query if waiting over 1s.
Parameters
string $thread_id: Name thread to check for the metadata lock.
Return value
bool TRUE if it did kill the query. FALSE if no killing was done.
3 calls to apdqc_kill_metadata_lock()
- apdqc_admin_change_table_collation_queries in ./
apdqc.admin.inc - Convert the table to the specified collation.
- apdqc_convert_cache_index in ./
apdqc.admin.inc - Converts a database index from one form to another.
- apdqc_truncate_table in ./
apdqc.mysql.inc - Empties out a database table in a non metadata locking fashion.
File
- ./
apdqc.mysql.inc, line 979 - APDQC Database interface code for MySQL database servers.
Code
function apdqc_kill_metadata_lock($thread_id) {
$lock_found = TRUE;
while ($lock_found) {
// Check for a Metadata lock.
// @ignore sql_curly
$result = db_query("SELECT * FROM information_schema.processlist WHERE ID = :pid AND STATE LIKE 'Waiting for table metadata lock' LIMIT 1", array(
":pid" => $thread_id,
));
foreach ($result as $record) {
// Rename should not take over 1 second.
if ($record->TIME >= 1) {
// Kill query that is in a metadata lock state.
db_query("KILL QUERY :pid", array(
":pid" => $thread_id,
));
return TRUE;
}
// Wait 250ms.
usleep(250000);
// Goto top of while loop.
continue 2;
}
// Metadata lock cleared.
$lock_found = FALSE;
}
return FALSE;
}