Bug #50821 | Deadlock between LOCK TABLES and ALTER TABLE | ||
---|---|---|---|
Submitted: | 2 Feb 2010 9:59 | Modified: | 7 Mar 2010 1:03 |
Reporter: | Jon Olav Hauglid | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Locking | Severity: | S1 (Critical) |
Version: | mysql-next-4284 | OS: | Any |
Assigned to: | Jon Olav Hauglid | CPU Architecture: | Any |
[2 Feb 2010 9:59]
Jon Olav Hauglid
[2 Feb 2010 12:09]
Jon Olav Hauglid
Repeatable MTR-test case. Execute this with --mysqld=--log-bin=OFF. create table t1(id int); create table t2(id int); connect (con2, localhost, root); start transaction; select * from t1; connection default; --send alter table t1 add column j int; connection con2; --sleep 1 insert into t2 select * from t1; commit; connection default; --reap drop table t1, t2; disconnect con2;
[3 Feb 2010 15:47]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/99110 3070 Jon Olav Hauglid 2010-02-03 Bug #50821 Deadlock between LOCK TABLES and ALTER TABLE This was a deadlock between ALTER TABLE and another DML statement. ALTER TABLE would wait trying to upgrade its lock to MDL_EXCLUSIVE and the DML statement would wait trying to acquire a TL_READ_NO_INSERT table level lock. This could happen if one connection first acquired a MDL_SHARED_READ lock on a table. In another connection ALTER TABLE is then started. ALTER TABLE eventually blocks trying to upgrade to MDL_EXCLUSIVE, but while holding a TL_WRITE_ALLOW_READ table level lock. If the first connection then tries to acquire TL_READ_NO_INSERT, it will block and we have a deadlock since neither connection can proceed. This patch fixes the problem by allowing TL_READ_NO_INSERT locks to be granted if another connection holds TL_WRITE_ALLOW_READ on the same table. This will allow the DML statement to proceed such that it eventually can release its MDL lock which in turn makes ALTER TABLE able to proceed. Test case added to lock_sync.test.
[4 Feb 2010 9:00]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/99216 3073 Jon Olav Hauglid 2010-02-04 Bug #50821 Deadlock between LOCK TABLES and ALTER TABLE This was a deadlock between ALTER TABLE and another DML statement (or LOCK TABLES ... READ). ALTER TABLE would wait trying to upgrade its lock to MDL_EXCLUSIVE and the DML statement would wait trying to acquire a TL_READ_NO_INSERT table level lock. This could happen if one connection first acquired a MDL_SHARED_READ lock on a table. In another connection ALTER TABLE is then started. ALTER TABLE eventually blocks trying to upgrade to MDL_EXCLUSIVE, but while holding a TL_WRITE_ALLOW_READ table level lock. If the first connection then tries to acquire TL_READ_NO_INSERT, it will block and we have a deadlock since neither connection can proceed. This patch fixes the problem by allowing TL_READ_NO_INSERT locks to be granted if another connection holds TL_WRITE_ALLOW_READ on the same table. This will allow the DML statement to proceed such that it eventually can release its MDL lock which in turn makes ALTER TABLE able to proceed. Note that TL_READ_NO_INSERT was already partially compatible with TL_WRITE_ALLOW_READ as the latter would be granted if the former lock was held. This patch just makes the opposite true as well. Also note that since ALTER TABLE takes an upgradable MDL lock, there will be no starvation of ALTER TABLE statements by statements acquiring TL_READ or TL_READ_NO_INSERT. Test case added to lock_sync.test.
[4 Feb 2010 10:35]
Jon Olav Hauglid
Pushed to mysql-next-4284.
[4 Feb 2010 10:38]
Jon Olav Hauglid
Setting the bug to Closed since it was not reproducable outside next-4284 which is an internal tree.
[16 Feb 2010 16:47]
Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20100216101445-2ofzkh48aq2e0e8o) (version source revid:kostja@sun.com-20100210211106-nq8ztcq2z9o4csit) (merge vers: 6.0.14-alpha) (pib:16)
[16 Feb 2010 16:56]
Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100216101208-33qkfwdr0tep3pf2) (version source revid:jon.hauglid@sun.com-20100204090036-bu3x1qwj4wjg3xd6) (pib:16)
[6 Mar 2010 11:01]
Bugs System
Pushed into 5.5.3-m3 (revid:alik@sun.com-20100306103849-hha31z2enhh7jwt3) (version source revid:vvaintroub@mysql.com-20100216221947-luyhph0txl2c5tc8) (merge vers: 5.5.99-m3) (pib:16)
[7 Mar 2010 1:03]
Paul DuBois
No changelog entry needed.