mariadb/include/mysql
Dmitry Lenev 49406b97df A better fix for bug #56405 "Deadlock in the MDL deadlock
detector" that doesn't introduce bug #56715 "Concurrent
transactions + FLUSH result in sporadical unwarranted
deadlock errors".

Deadlock could have occurred when workload containing a mix
of DML, DDL and FLUSH TABLES statements affecting the same
set of tables was executed in a heavily concurrent environment.

This deadlock occurred when several connections tried to
perform deadlock detection in the metadata locking subsystem.
The first connection started traversing wait-for graph,
encountered a sub-graph representing a wait for flush, acquired
LOCK_open and dived into sub-graph inspection. Then it
encountered sub-graph corresponding to wait for metadata lock
and blocked while trying to acquire a rd-lock on
MDL_lock::m_rwlock, since some,other thread had a wr-lock on it.
When this wr-lock was released it could have happened (if there
was another pending wr-lock against this rwlock) that the rd-lock
from the first connection was left unsatisfied but at the same
time the new rd-lock request from the second connection sneaked
in and was satisfied (for this to be possible the second
rd-request should come exactly after the wr-lock is released but
before pending the wr-lock manages to grab rwlock, which is
possible both on Linux and in our own rwlock implementation).
If this second connection continued traversing the wait-for graph
and encountered a sub-graph representing a wait for flush it tried
to acquire LOCK_open and thus the deadlock was created.

The previous patch tried to workaround this problem by not
allowing the deadlock detector to lock LOCK_open mutex if
some other thread doing deadlock detection already owns it
and current search depth is greater than 0. Instead deadlock
was reported. As a result it has introduced bug #56715.

This patch solves this problem in a different way.
It introduces a new rw_pr_lock_t implementation to be used
by MDL subsystem instead of one based on Linux rwlocks or
our own rwlock implementation. This new implementation
never allows situation in which an rwlock is rd-locked and
there is a blocked pending rd-lock. Thus the situation which
has caused this bug becomes impossible with this implementation.

Due to fact that this implementation is optimized for
wr-lock/unlock scenario which is most common in the MDL
subsystem it doesn't introduce noticeable performance
regressions in sysbench tests. Moreover it significantly
improves situation for POINT_SELECT test when many
connections are used.

No test case is provided as this bug is very hard to repeat
in MTR environment but is repeatable with the help of RQG
tests.
This patch also doesn't include a test for bug #56715
"Concurrent transactions + FLUSH result in sporadical
unwarranted deadlock errors" as it takes too much time to
be run as part of normal test-suite runs.
2010-09-29 16:09:07 +04:00
..
psi A better fix for bug #56405 "Deadlock in the MDL deadlock 2010-09-29 16:09:07 +04:00
innodb_priv.h WL#5030: Splitting mysql_priv.h 2010-04-21 00:29:30 +02:00
plugin.h Auto-merge from mysql-5.5-merge. 2010-08-30 18:07:40 +04:00
plugin_audit.h BUG#47059 - In audit plugin I cannot see the event subclasses, 2010-04-15 13:05:17 +04:00
plugin_audit.h.pp Auto-merge from mysql-5.5-merge. 2010-08-30 18:07:40 +04:00
plugin_ftparser.h Backport from 6.0-codebase. 2009-12-15 23:52:47 +04:00
plugin_ftparser.h.pp Auto-merge from mysql-5.5-merge. 2010-08-30 18:07:40 +04:00
service_my_snprintf.h Fix for Bug#54478 "mysqld crashes during boot when running mtr with --debug option" 2010-09-15 13:33:22 +02:00
service_thd_alloc.h Bug#52514: mysql 5.1 do_abi_check does not compile w/ gcc4.5 2010-07-20 16:34:20 -03:00
service_thd_wait.h WL#5363: Thread Pool Service Interface 2010-06-07 16:01:39 +02:00
service_thread_scheduler.h WL#5363: Thread Pool Service Interface 2010-06-07 16:01:39 +02:00
services.h WL#5363: Thread Pool Service Interface 2010-06-07 16:01:39 +02:00