diff options
author | Konstantin Osipov <kostja@sun.com> | 2010-06-03 18:08:22 +0400 |
---|---|---|
committer | Konstantin Osipov <kostja@sun.com> | 2010-06-03 18:08:22 +0400 |
commit | e7854c86a7e98a8680f262d39d7497cf76932bee (patch) | |
tree | a22fd6fba79873ea7156749a2e5ac99738c15739 /sql/mdl.h | |
parent | 8867c0a52c69745f90bc24e11f5945d6eca6d88e (diff) | |
download | mariadb-git-e7854c86a7e98a8680f262d39d7497cf76932bee.tar.gz |
A code review comment for Bug#52289.
Encapsulate the deadlock detection functionality into
a visitor class, and separate it from the wait-for graph
traversal code.
Use "Internal iterator" and "Visitor" patterns to
achieve the desired separation of responsibilities.
Add comments.
sql/mdl.cc:
Encapsulate deadlock detection into a class.
sql/mdl.h:
Adjust for a rename of a class.
Diffstat (limited to 'sql/mdl.h')
-rw-r--r-- | sql/mdl.h | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/sql/mdl.h b/sql/mdl.h index 1a123d5baa9..0710155d10c 100644 --- a/sql/mdl.h +++ b/sql/mdl.h @@ -34,7 +34,7 @@ class THD; class MDL_context; class MDL_lock; class MDL_ticket; -class Deadlock_detection_context; +class Deadlock_detection_visitor; /** Type of metadata lock request. @@ -322,9 +322,6 @@ public: DBUG_ASSERT(ticket == NULL); type= type_arg; } - /* A helper used to determine which lock request should be aborted. */ - uint get_deadlock_weight() const; - static MDL_request *create(MDL_key::enum_mdl_namespace mdl_namespace, const char *db, const char *name, enum_mdl_type mdl_type, MEM_ROOT *root); @@ -418,6 +415,8 @@ public: bool is_incompatible_when_granted(enum_mdl_type type) const; bool is_incompatible_when_waiting(enum_mdl_type type) const; + /* A helper used to determine which lock request should be aborted. */ + uint get_deadlock_weight() const; private: friend class MDL_context; @@ -529,6 +528,9 @@ public: inline THD *get_thd() const { return m_thd; } + /** @pre Only valid if we started waiting for lock. */ + inline uint get_deadlock_weight() const + { return m_waiting_for->get_deadlock_weight(); } /** Wake up context which is waiting for a change of MDL_lock state. */ @@ -559,7 +561,7 @@ public: return m_needs_thr_lock_abort; } - bool find_deadlock(Deadlock_detection_context *deadlock_ctx); + bool find_deadlock(Deadlock_detection_visitor *dvisitor); private: /** All MDL tickets acquired by this connection. @@ -670,17 +672,6 @@ private: mysql_prlock_unlock(&m_waiting_for_lock); } - void set_deadlock_weight(uint weight) - { - /* - m_deadlock_weight should not be modified while m_waiting_for is - non-NULL as in this case this context might participate in deadlock - and so m_deadlock_weight can be accessed from other threads. - */ - DBUG_ASSERT(m_waiting_for == NULL); - m_deadlock_weight= weight; - } - void stop_waiting() { mysql_prlock_wrlock(&m_waiting_for_lock); |