mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
Fix for bug #50913 "Deadlock between open_and_lock_tables_derived
and MDL". Concurrent execution of a multi-DELETE statement and ALTER TABLE statement which affected one of the tables used in the multi-DELETE sometimes led to deadlock. Similar deadlocks might have occured when one performed INSERT/UPDATE/DELETE on a view and concurrently executed ALTER TABLE for the view's underlying table, or when one concurrently executed TRUNCATE TABLE for InnoDB table and ALTER TABLE for the same table. These deadlocks were caused by a discrepancy between types of metadata and thr_lock.cc locks acquired by those statements. What happened was that multi-DELETE/TRUNCATE/DML-through-the- view statement in the first connection acquired SR lock on a table, then ALTER TABLE would come in in the second connection and acquire SNW metadata lock and TL_WRITE_ALLOW_READ thr_lock.c lock and then would start waiting for the first connection during lock upgrade. After that the statement in the first connection would try to acquire TL_WRITE lock on table and would start waiting for the second connection, creating a deadlock. This patch solves this problem by ensuring that we acquire SW metadata lock in all cases in which we acquiring write thr_lock.c lock. This guarantees that deadlocks like the one described above won't occur since all lock conflicts in such situation are resolved within MDL subsystem. This patch also adds assert which should guarantee that such situations won't arise in future.
This commit is contained in:
@@ -2292,3 +2292,33 @@ SET DEBUG_SYNC= 'RESET';
|
||||
SET @@global.general_log= @old_general_log;
|
||||
SET @@global.log_output= @old_log_output;
|
||||
SET @@session.sql_log_off= @old_sql_log_off;
|
||||
#
|
||||
# Additional coverage for bug #50913 "Deadlock between
|
||||
# open_and_lock_tables_derived and MDL". The main test
|
||||
# case is in lock_multi.test
|
||||
#
|
||||
drop table if exists t1;
|
||||
set debug_sync= 'RESET';
|
||||
create table t1 (i int) engine=InnoDB;
|
||||
# Switching to connection 'con50913_1'.
|
||||
set debug_sync= 'thr_multi_lock_after_thr_lock SIGNAL parked WAIT_FOR go';
|
||||
# Sending:
|
||||
alter table t1 add column j int;
|
||||
# Switching to connection 'default'.
|
||||
# Wait until ALTER TABLE gets blocked on a sync point after
|
||||
# acquiring thr_lock.c lock.
|
||||
set debug_sync= 'now WAIT_FOR parked';
|
||||
# The below statement should wait on MDL lock and not deadlock on
|
||||
# thr_lock.c lock.
|
||||
# Sending:
|
||||
truncate table t1;
|
||||
# Switching to connection 'con50913_2'.
|
||||
# Wait until TRUNCATE TABLE is blocked on MDL lock.
|
||||
# Unblock ALTER TABLE.
|
||||
set debug_sync= 'now SIGNAL go';
|
||||
# Switching to connection 'con50913_1'.
|
||||
# Reaping ALTER TABLE.
|
||||
# Switching to connection 'default'.
|
||||
# Reaping TRUNCATE TABLE.
|
||||
set debug_sync= 'RESET';
|
||||
drop table t1;
|
||||
|
||||
Reference in New Issue
Block a user