mariadb/mysys
Jon Olav Hauglid a19377e0d7 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.
2010-02-04 10:00:36 +01:00
..
array.c Fix for a few assorted compiler warnings. 2009-08-28 12:06:59 -03:00
base64.c fixed compilation warnings. addendum to the fix for bug 29125 2009-03-20 16:27:53 +02:00
ChangeLog
charset-def.c Bsckporting WL#3764 Sinhala Collation 2009-10-06 15:34:49 +05:00
charset.c Manual merge from mysql-next-mr. 2009-12-17 23:02:52 +03:00
checksum.c Bug#29125 Windows Server X64: so many compiler warnings 2009-02-13 11:41:47 -05:00
CMakeLists.txt WL#2373 Use cycle counter for timing 2009-11-24 16:36:31 -07:00
default.c Merge mysql-next-mr (revno 2936) --> mysql-next-mr-marc 2009-12-11 01:58:13 -07:00
default_modify.c This is the downport of 2009-09-11 22:26:35 +02:00
errors.c Backport of: 2009-11-24 16:54:59 +03:00
hash.c Merge next-mr -> next-4284. 2010-02-02 16:58:15 +03:00
lf_alloc-pin.c WL#3230 concurrent hash 2009-11-17 19:31:40 -07:00
lf_dynarray.c WL#3230 concurrent hash 2009-11-17 19:31:40 -07:00
lf_hash.c WL#3230 concurrent hash 2009-11-17 19:31:40 -07:00
list.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
make-ccc Remove unused (and incorrect) my_lread() and my_lwrite() 2006-09-14 23:29:44 -06:00
make-conf.c Many files: 2006-12-23 20:17:15 +01:00
Makefile.am WL#2373 Use cycle counter for timing 2009-11-24 16:36:31 -07:00
md5.c Bug #42434: license of mysys MD5 implementation is not GPL-compatible 2009-03-09 20:57:03 +02:00
mf_arr_appstr.c Bug #20748: Configuration files should not be read more than once 2007-11-07 15:23:50 -07:00
mf_brkhant.c Many files: 2006-12-23 20:17:15 +01:00
mf_cache.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
mf_dirname.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
mf_fn_ext.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
mf_format.c BUG#43949 Initialization of slave produces a warning message in Valgrind 2009-04-19 02:21:33 +01:00
mf_getdate.c Merge from 5.0-bugteam 2009-05-13 08:48:00 -07:00
mf_iocache.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
mf_iocache2.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
mf_keycache.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
mf_keycaches.c Backport of: 2009-10-14 20:37:38 +04:00
mf_loadpath.c Backport of: 2009-11-24 16:54:59 +03:00
mf_pack.c Merge from 5.0 for 43414 2009-08-28 18:21:54 +02:00
mf_path.c Backport of: 2009-11-24 16:54:59 +03:00
mf_qsort.c Fix for bug #31207: Test "join_nested" shows different strategy on IA64 2007-10-17 20:08:58 +04:00
mf_qsort2.c Many files: 2006-12-23 20:17:15 +01:00
mf_radix.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
mf_same.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
mf_sort.c Merge polly.(none):/home/kaa/src/maint/mysql-5.0-maint 2007-10-18 14:32:43 +04:00
mf_soundex.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
mf_tempdir.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
mf_tempfile.c Moved a lot of old bug fixes and safe cleanups from Maria 5.1 tree to 5.1 2007-10-11 18:07:40 +03:00
mf_unixpath.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
mf_util.c Many files: 2006-12-23 20:17:15 +01:00
mf_wcomp.c Many files: 2006-12-23 20:17:15 +01:00
mf_wfile.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
mulalloc.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
my_access.c Merge mysql.com:/home/kent/bk/main/mysql-5.0 2006-12-23 20:20:40 +01:00
my_aes.c my_strtoll10-x86.s: 2006-12-31 01:02:27 +01:00
my_alarm.c Many files: 2006-12-23 20:17:15 +01:00
my_alloc.c Backport of Bug#15192 to mysql-next-mr 2009-11-10 18:31:28 -02:00
my_append.c Backport of: 2009-11-24 16:54:59 +03:00
my_atomic.c WL#2595 kernel-independent atomic operations 2009-11-17 17:11:32 -07:00
my_bit.c Moved a lot of old bug fixes and safe cleanups from Maria 5.1 tree to 5.1 2007-10-11 18:07:40 +03:00
my_bitmap.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
my_chsize.c This is the downport of 2009-09-11 22:26:35 +02:00
my_clock.c Backport of: 2009-11-24 16:54:59 +03:00
my_compress.c Bug#29125 Windows Server X64: so many compiler warnings 2009-02-13 11:41:47 -05:00
my_conio.c Bug#29125 Windows Server X64: so many compiler warnings 2009-02-13 11:41:47 -05:00
my_copy.c Backport of: 2009-11-24 16:54:59 +03:00
my_crc32.c Many files: 2006-12-23 20:17:15 +01:00
my_create.c This is the downport of 2009-09-11 22:26:35 +02:00
my_delete.c Manual resolving for the following files 2009-12-01 21:07:18 +02:00
my_div.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
my_dup.c This is the downport of 2009-09-11 22:26:35 +02:00
my_error.c WL#4903 Plugin Service API part I 2009-11-02 21:05:42 +01:00
my_file.c This is the downport of 2009-09-11 22:26:35 +02:00
my_fopen.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
my_fstream.c Backport of: 2009-11-24 16:54:59 +03:00
my_gethostbyname.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
my_gethwaddr.c fix compile error. definition of VOID in trunk still conflicts with windows headers. that was fixed in 6.0 2009-09-13 19:38:06 +02:00
my_getncpus.c WL#2595 kernel-independent atomic operations 2009-11-17 17:11:32 -07:00
my_getopt.c WL#4738 streamline/simplify @@variable creation process 2009-12-22 10:35:56 +01:00
my_getpagesize.c Many files: 2006-12-23 20:17:15 +01:00
my_getsystime.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
my_getwd.c Backport of: 2009-11-24 16:54:59 +03:00
my_handler.c Fixed problem with non-synchronous error lists 2008-03-28 18:45:03 +02:00
my_handler_errors.h WL#5016: Fix header file include guards 2009-09-23 23:32:31 +02:00
my_init.c WL#2360 Performance schema 2010-01-06 22:42:07 -07:00
my_largepage.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
my_lib.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
my_libwrap.c Many files: 2006-12-23 20:17:15 +01:00
my_lock.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
my_lockmem.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
my_malloc.c Backport of my_malloc() changes from 5.1 to make it 64-bit safe on Unix platforms. 2007-08-29 19:20:18 +04:00
my_memmem.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
my_messnc.c WL#2110 (SIGNAL) 2009-09-10 03:18:29 -06:00
my_mkdir.c Merge mysql.com:/home/kent/bk/main/mysql-5.0 2006-12-23 20:20:40 +01:00
my_mmap.c This is the downport of 2009-09-11 22:26:35 +02:00
my_net.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
my_netware.c Many files: 2006-12-23 20:17:15 +01:00
my_new.cc Bug#43461: invalid comparison with string literal in default.c 2009-03-19 17:20:15 -03:00
my_once.c my_once.c: clarify the comment 2009-12-26 21:55:32 +01:00
my_open.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
my_port.c my_strtoll10-x86.s: 2006-12-31 01:02:27 +01:00
my_pread.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
my_pthread.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
my_quick.c This is the downport of 2009-09-11 22:26:35 +02:00
my_rdtsc.c WL#2373 Use cycle counter for timing 2009-11-24 16:36:31 -07:00
my_read.c This is the downport of 2009-09-11 22:26:35 +02:00
my_realloc.c Moved a lot of old bug fixes and safe cleanups from Maria 5.1 tree to 5.1 2007-10-11 18:07:40 +03:00
my_redel.c Backport of: 2009-11-24 16:54:59 +03:00
my_rename.c Moved a lot of old bug fixes and safe cleanups from Maria 5.1 tree to 5.1 2007-10-11 18:07:40 +03:00
my_seek.c This is the downport of 2009-09-11 22:26:35 +02:00
my_sleep.c Merge mysql.com:/home/kent/bk/main/mysql-5.0 2006-12-23 20:20:40 +01:00
my_static.c Merge next-mr -> next-4284. 2009-12-15 21:45:22 +03:00
my_static.h WL#5016: Fix header file include guards 2009-09-23 23:32:31 +02:00
my_symlink.c Bug#39102 valgrind build does not compile in realpath, which make DATA/INDEX DIR fail 2008-10-27 19:25:11 +04:00
my_symlink2.c Merge mysql.com:/home/svoj/devel/mysql/BUG32111/mysql-5.0-engines 2007-11-12 15:26:37 +04:00
my_sync.c Manual merge from mysql-trunk. 2009-12-11 12:39:38 +03:00
my_thr_init.c WL#2360 Performance schema 2010-01-06 22:42:07 -07:00
my_timer_cycles.il WL#2373 Use cycle counter for timing 2009-11-24 16:36:31 -07:00
my_vle.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
my_wincond.c A follow up for the fix for Bug#35164 (remove priorities on Windows). 2009-11-23 20:08:37 +03:00
my_windac.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
my_winerr.c This is the downport of 2009-09-11 22:26:35 +02:00
my_winfile.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
my_winthread.c Manual merge from mysql-trunk-merge. 2009-12-16 21:02:21 +03:00
my_write.c This is the downport of 2009-09-11 22:26:35 +02:00
mysys_priv.h WL#2360 Performance schema 2010-01-06 22:42:07 -07:00
ptr_cmp.c WL#5105, review fix 2009-11-20 20:01:43 +01:00
queues.c Fix for server bug experienced in Maria (wrong "Truncated incorrect <var_name> 2008-02-18 23:29:39 +01:00
rijndael.c my_strtoll10-x86.s: 2006-12-31 01:02:27 +01:00
safemalloc.c WL#4738 streamline/simplify @@variable creation process 2009-12-22 10:35:56 +01:00
sha1.c Merge bk-internal.mysql.com:/home/bk/mysql-5.0 2007-01-22 14:04:40 +02:00
stacktrace.c Manual merge from mysql-trunk-merge. 2009-12-16 21:02:21 +03:00
string.c Bug#29125 Windows Server X64: so many compiler warnings 2009-02-13 11:41:47 -05:00
test_charset.c Fix doxygen warnings. 2007-08-15 17:43:08 +04:00
test_dir.c Merge mysql.com:/home/kent/bk/main/mysql-5.0 2006-12-23 20:20:40 +01:00
test_fn.c Many files: 2006-12-23 20:17:15 +01:00
test_xml.c Many files: 2006-12-23 20:17:15 +01:00
testhash.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
thr_alarm.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
thr_lock.c Bug #50821 Deadlock between LOCK TABLES and ALTER TABLE 2010-02-04 10:00:36 +01:00
thr_mutex.c WL#2360 Performance schema 2009-12-09 20:19:51 -07:00
thr_rwlock.c Many files: 2006-12-23 20:17:15 +01:00
tree.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
trie.c WL#3817: Simplify string / memory area types and make things more consistent (first part) 2007-05-10 12:59:39 +03:00
typelib.c WL#4738 streamline/simplify @@variable creation process 2009-12-22 10:35:56 +01:00