mariadb/storage/myisammrg
Jon Olav Hauglid 51a3375c98 Bug #56292 Deadlock with ALTER TABLE and MERGE tables
ALTER TABLE on a MERGE table could cause a deadlock with two
other connections if we reached a situation where:

1) A connection doing ALTER TABLE can't upgrade to MDL_EXCLUSIVE on the
parent table, but holds TL_READ_NO_INSERT on the child tables.
2) A connection doing DELETE on a child table can't get TL_WRITE on it
since ALTER TABLE holds TL_READ_NO_INSERT.
3) A connection doing SELECT on the parent table can't get TL_READ on 
the child tables since TL_WRITE is ahead in the lock queue, but holds
MDL_SHARED_READ on the parent table preventing ALTER TABLE from upgrading.

For regular tables, this deadlock is avoided by having ALTER TABLE
take a MDL_SHARED_NO_WRITE metadata lock on the table. This prevents
DELETE from acquiring MDL_SHARED_WRITE on the table before ALTER TABLE
tries to upgrade to MDL_EXCLUSIVE. In the example above, SELECT would
therefore not be blocked by the pending DELETE as DELETE would not be
able to enter TL_WRITE in the table lock queue.

This patch fixes the problem for merge tables by using the same metadata
lock type for child tables as for the parent table. The child tables will
in this case therefore be locked with MDL_SHARED_NO_WRITE, preventing
DELETE from acquiring a metadata lock and enter into the table lock queue.

Change in behavior: By taking the same metadata lock for child tables
as for the parent table, LOCK TABLE on the parent table will now also
implicitly lock the child tables. Since LOCK TABLE on the parent table
now takes more than one metadata lock, it is possible for LOCK TABLE
... WRITE on the parent table or child tables to give ER_LOCK_DEADLOCK
error.

Test case added to mdl_sync.test.
Merge.test/.result has been updated to reflect the change to LOCK TABLE.
2010-09-08 10:25:37 +02:00
..
CMakeLists.txt Patch for Bug#55854 (MySQL AB should not be AUTHOR, copyright incorrect). 2010-08-12 19:19:57 +04:00
ha_myisammrg.cc Bug #56292 Deadlock with ALTER TABLE and MERGE tables 2010-09-08 10:25:37 +02:00
ha_myisammrg.h Backport of revid 2617.69.21, 2617.69.22, 2617.29.23: 2009-12-08 16:57:25 +03:00
Makefile.am Another incarnation of the patch for Bug#30708 2010-05-19 17:00:23 +04:00
myrg_close.c Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled 2010-07-08 18:20:08 -03:00
myrg_create.c WL#2360 Performance schema 2009-12-04 18:26:15 -07:00
myrg_def.h WL#2360 Performance schema 2009-12-04 18:26:15 -07:00
myrg_delete.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
myrg_extra.c Backport of: 2009-12-03 02:09:22 +03:00
myrg_info.c Bug#45800 crash when replacing into a merge table and there is a duplicate 2009-07-30 16:04:41 +05:30
myrg_locking.c BUG#29806 - binlog_innodb.test creates a server log 2007-07-25 19:56:17 +05:00
myrg_open.c Merge of mysql-5.1-bugteam into mysql-trunk-merge. 2010-07-20 16:30:10 -03:00
myrg_panic.c Merge mysql.com:/home/kent/bk/main/mysql-5.0 2006-12-31 01:32:21 +01:00
myrg_queue.c Backport of 2010-05-31 17:38:02 +04:00
myrg_range.c Merge mysql.com:/home/kent/bk/main/mysql-5.0 2006-12-31 01:32:21 +01:00
myrg_records.c Fixed bug#36006: Optimizer does table scan for SELECT COUNT(*) 2008-04-26 02:45:58 +05:00
myrg_rfirst.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
myrg_rkey.c Merge from 5.0 for 43414 2009-08-28 18:21:54 +02:00
myrg_rlast.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
myrg_rnext.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
myrg_rnext_same.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
myrg_rprev.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
myrg_rrnd.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
myrg_rsame.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
myrg_static.c WL#2360 Performance schema 2009-12-04 18:26:15 -07:00
myrg_update.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
myrg_write.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
plug.in bug #23369 (Embedded library can't be linked) 2006-10-18 17:03:37 +05:00