From: Dmitry Lenev Date: October 19 2010 1:32pm Subject: bzr commit into mysql-5.5-runtime branch (Dmitry.Lenev:3168) List-Archive: http://lists.mysql.com/commits/121148 Message-Id: <20101019133221.082F3E5924@mockturtle> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0455964545==" --===============0455964545== MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline #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 --===============0455964545== MIME-Version: 1.0 Content-Type: text/bzr-bundle; charset="us-ascii"; name="bzr/dmitry.lenev@stripped" Content-Transfer-Encoding: 7bit Content-Disposition: inline # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: dmitry.lenev@stripped # target_branch: file:///home/dlenev/src/bzr/mysql-5.5-rt-grl/ # testament_sha1: 4797eb155db28b1da489a01ed247013c69def1ea # timestamp: 2010-10-19 17:32:20 +0400 # base_revision_id: dmitry.lenev@stripped\ # c66oylcf3mcls2e4 # # Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWThcQzIAA9TfgGAQWPP//3/v noC////6YAhN9at07YNAc7UoMgAAUGEpqCVPZqNT0Cn6NEyjeVPUaPUaDam1DIyPTU0NBKSnkm0Z R6Ke1CaaZMTQAAA9TTIBoAZIyCTFHplDQaDTQAAAAA0AOMmTTTCZGQMCMTRgjCDRpgAEOMmTTTCZ GQMCMTRgjCDRpgAEEkQIIyMTQEaNCeiaNQQ02psp6mgBtHgeOLBkRlrhk0ysPIknt2zXncPrCfNm dKW+s4Qz6KvFxFJKD52ONOFb1ftIm5CGQAwAlJFirXM0KcyMbPBX1WbgFBKbIJUzjorPQ5B8wuBm YZmZMwsfqljonki5KkCoiB0CjoWuAemPYgywQo2dObFk+rr9Xjc+01/7Hyz/IPscd8rOvvKuHqe+ bhijF7lBA571VhjFzuSKIOiI2TfaqQjjasCh0lUBxyBK0gpC4rFZgBfofeat1+eBTMiqMownpe5Y YR0bNS6FTNfuMi5g1awzXYF2bmaWI6QMQ67+SiMzb27DrxN2U5Hw+NthsNguaQaUPTfRHQU9ZjFE 0QSysw4pglEYTuyaLRLO7A99uLbA453ghwikEFFjZlkFs6g4BZo9HoCZjFiDJOxybvQe+pkg1gSS SK2A5kojrskA8RMVHwJB8UmTSgFKCWlgiSD0oSDojPGKFEzuoZwjBEe51umCqYyjHxBFJXbYUFho jEGVFUNVMji4SrXeC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