#At file:///home/dlenev/src/bzr/mysql-5.5-rt-grl/ based on revid:dmitry.lenev@stripped
3168 Dmitry Lenev 2010-10-19
More changes to draft patch refactoring global read
lock implementation. Makes GRL yet another type of
metadata lock and thus exposes it to deadlock detector
in MDL subsystem.
Solves bugs #54673 "It takes too long to get readlock for
'FLUSH TABLES WITH READ LOCK'" and #57006 "Deadlock between
HANDLER and FLUSH TABLES WITH READ LOCK".
Work-in-progress.
modified:
sql/lock.cc
sql/sql_class.cc
sql/sql_class.h
sql/sql_insert.cc
=== modified file 'sql/lock.cc'
--- a/sql/lock.cc 2010-10-18 12:33:49 +0000
+++ b/sql/lock.cc 2010-10-19 13:31:53 +0000
@@ -1137,10 +1137,6 @@ bool Global_read_lock::make_global_read_
thd->variables.lock_wait_timeout))
DBUG_RETURN(TRUE);
- /*
- TODO/FIXME Ensure that this ticket is correctly placed after sentinel
- when we are leaving LOCK TABLES mode.
- */
thd->mdl_context.move_ticket_after_trans_sentinel(mdl_request.ticket);
m_mdl_blocks_commits_lock= mdl_request.ticket;
m_state= GRL_ACQUIRED_AND_BLOCKS_COMMIT;
@@ -1148,6 +1144,22 @@ bool Global_read_lock::make_global_read_
DBUG_RETURN(FALSE);
}
+
+/**
+ Move tickets for metadata locks which are used to implement GRL after
+ transactional sentinel.
+
+ @param thd Reference to thread.
+*/
+
+void Global_read_lock::move_tickets_after_trans_sentinel(THD *thd)
+{
+ if (m_mdl_global_shared_lock)
+ thd->mdl_context.move_ticket_after_trans_sentinel(m_mdl_global_shared_lock);
+ if (m_mdl_blocks_commits_lock)
+ thd->mdl_context.move_ticket_after_trans_sentinel(m_mdl_blocks_commits_lock);
+}
+
/**
@} (end of group Locking)
*/
=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc 2010-10-18 12:33:49 +0000
+++ b/sql/sql_class.cc 2010-10-19 13:31:53 +0000
@@ -3458,11 +3458,12 @@ void THD::set_mysys_var(struct st_my_thr
void THD::leave_locked_tables_mode()
{
locked_tables_mode= LTM_NONE;
+ mdl_context.reset_trans_sentinel(NULL);
/*
- Make sure we don't release the global read lock when leaving LTM.
- TODO/FIXME: Add handling of commit blocker!
+ Make sure we don't release the global read lock and commit blocker
+ when leaving LTM.
*/
- mdl_context.reset_trans_sentinel(global_read_lock.global_shared_lock());
+ global_read_lock.move_tickets_after_trans_sentinel(this);
/* Also ensure that we don't release metadata locks for open HANDLERs. */
if (handler_tables_hash.records)
mysql_ha_move_tickets_after_trans_sentinel(this);
=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h 2010-10-18 12:33:49 +0000
+++ b/sql/sql_class.h 2010-10-19 13:31:53 +0000
@@ -1350,7 +1350,7 @@ public:
void release_protection_if_set(THD *thd);
bool make_global_read_lock_block_commit(THD *thd);
bool is_acquired() const { return m_state != GRL_NONE; }
- MDL_ticket *global_shared_lock() const { return m_mdl_global_shared_lock; }
+ void move_tickets_after_trans_sentinel(THD *thd);
private:
enum_grl_state m_state;
/**
=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc 2010-10-18 12:33:49 +0000
+++ b/sql/sql_insert.cc 2010-10-19 13:31:53 +0000
@@ -540,8 +540,6 @@ bool open_and_lock_for_insert_delayed(TH
table to being inserted into inside the connection thread.
If this goes ok, the tickets are cloned and added to the list of granted
locks held by the handler thread.
-
- TODO/FIXME: Handle release of protection against GRL.
*/
if (thd->global_read_lock.can_acquire_protection())
DBUG_RETURN(TRUE);
@@ -592,7 +590,12 @@ bool open_and_lock_for_insert_delayed(TH
this or another tables (updating the same table is of course illegal,
but such an attempt can be discovered only later during statement
execution).
+
+ Move ticket protecting from a GRL to the front of ticket list.
+ This allows to find it quickly when this lock has to be released
+ at the end of statement.
*/
+ thd->mdl_context.move_ticket_to_front(protection_request.ticket);
/*
Reset the ticket in case we end up having to use normal insert and
Attachment: [text/bzr-bundle] bzr/dmitry.lenev@oracle.com-20101019133153-pgg9yjsmcy187na4.bundle
| Thread |
|---|
| • bzr commit into mysql-5.5-runtime branch (Dmitry.Lenev:3168) | Dmitry Lenev | 19 Oct |