summaryrefslogtreecommitdiff
path: root/sql/mdl.cc
diff options
context:
space:
mode:
authorDmitry Lenev <dlenev@mysql.com>2010-02-10 18:46:03 +0300
committerDmitry Lenev <dlenev@mysql.com>2010-02-10 18:46:03 +0300
commit96344befd355da789f206f81e228eb03828ce462 (patch)
tree6c8f7502b8b58b23eb754e7a3508781afa2d9436 /sql/mdl.cc
parent7dc5666c6be292e8b88f0112c2fd16e0e78b03f0 (diff)
downloadmariadb-git-96344befd355da789f206f81e228eb03828ce462.tar.gz
Fix for bug #50998 "Deadlock in MDL code during test
rqg_mdl_stability". When start of statement's waiting on a metadata lock created more than one loop in waiters graph server might have entered deadlock condition. The problem was that in the case described above MDL deadlock detector had to perform several searches for deadlock but forgot to reset Deadlock_detection_context before performing new search. Failure to do so has broken assumption in code resposible for choosing victim that if Deadlock_detection_context::victim is set we also have read lock on m_waiting_for_lock for this context. As result this lock could have been unlocked more times than it was acquired which corrupted rwlock's state which led to server deadlock. This fix ensures that such reset is done before each attempt to find a deadlock. mysql-test/r/mdl_sync.result: Added test for bug #50998 "Deadlock in MDL code during test rqg_mdl_stability" as well as coverage for the case when addition of statement waiting for metadata lock adds several loops in the waiters graph and therefore several searches for deadlock should be performed by MDL deadlock detector. mysql-test/t/mdl_sync.test: Added test for bug #50998 "Deadlock in MDL code during test rqg_mdl_stability" as well as coverage for the case when addition of statement waiting for metadata lock adds several loops in the waiters graph and therefore several searches for deadlock should be performed by MDL deadlock detector. sql/mdl.cc: Ensure that in cases when MDL deadlock detector had to perform several searches for deadlock because several loops in waiters graph are possible we reset Deadlock_detection_context before performing each search. Failure to do so has broken assumption in code resposible for choosing victim that if Deadlock_detection_context::victim is set we also have read lock on m_waiting_for_lock for this context. As result this lock could have been unlocked more times than it was acquired which corrupted rwlock's state (no one was able to acquire write lock on it anymore).
Diffstat (limited to 'sql/mdl.cc')
-rw-r--r--sql/mdl.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/sql/mdl.cc b/sql/mdl.cc
index 54931f89e40..e48ae8a3f59 100644
--- a/sql/mdl.cc
+++ b/sql/mdl.cc
@@ -1755,10 +1755,15 @@ bool MDL_context::find_deadlock(Deadlock_detection_context *deadlock_ctx)
bool MDL_context::find_deadlock()
{
- Deadlock_detection_context deadlock_ctx(this);
-
while (1)
{
+ /*
+ The fact that we use fresh instance of deadlock_ctx for each
+ search performed by find_deadlock() below is important, code
+ responsible for victim selection relies on this.
+ */
+ Deadlock_detection_context deadlock_ctx(this);
+
if (! find_deadlock(&deadlock_ctx))
{
/* No deadlocks are found! */