@@ -124,6 +124,7 @@ class Deadlock_detection_visitor: public MDL_wait_for_graph_visitor
124124 Deadlock_detection_visitor (MDL_context *start_node_arg)
125125 : m_start_node(start_node_arg),
126126 m_victim (NULL ),
127+ m_current_search_depth(0 ),
127128 m_found_deadlock(FALSE )
128129 {}
129130 virtual bool enter_node (MDL_context *node);
@@ -132,8 +133,6 @@ class Deadlock_detection_visitor: public MDL_wait_for_graph_visitor
132133 virtual bool inspect_edge (MDL_context *dest);
133134
134135 MDL_context *get_victim () const { return m_victim; }
135-
136- void abort_traversal (MDL_context *node);
137136private:
138137 /* *
139138 Change the deadlock victim to a new one if it has lower deadlock
@@ -148,6 +147,13 @@ class Deadlock_detection_visitor: public MDL_wait_for_graph_visitor
148147 MDL_context *m_start_node;
149148 /* * If a deadlock is found, the context that identifies the victim. */
150149 MDL_context *m_victim;
150+ /* * Set to the 0 at start. Increased whenever
151+ we descend into another MDL context (aka traverse to the next
152+ wait-for graph node). When MAX_SEARCH_DEPTH is reached, we
153+ assume that a deadlock is found, even if we have not found a
154+ loop.
155+ */
156+ uint m_current_search_depth;
151157 /* * TRUE if we found a deadlock. */
152158 bool m_found_deadlock;
153159 /* *
@@ -181,7 +187,7 @@ class Deadlock_detection_visitor: public MDL_wait_for_graph_visitor
181187
182188bool Deadlock_detection_visitor::enter_node (MDL_context *node)
183189{
184- m_found_deadlock= m_current_search_depth >= MAX_SEARCH_DEPTH;
190+ m_found_deadlock= ++ m_current_search_depth >= MAX_SEARCH_DEPTH;
185191 if (m_found_deadlock)
186192 {
187193 DBUG_ASSERT (! m_victim);
@@ -201,6 +207,7 @@ bool Deadlock_detection_visitor::enter_node(MDL_context *node)
201207
202208void Deadlock_detection_visitor::leave_node (MDL_context *node)
203209{
210+ --m_current_search_depth;
204211 if (m_found_deadlock)
205212 opt_change_victim_to (node);
206213}
@@ -244,21 +251,6 @@ Deadlock_detection_visitor::opt_change_victim_to(MDL_context *new_victim)
244251}
245252
246253
247- /* *
248- Abort traversal of a wait-for graph and report a deadlock.
249-
250- @param node Node which we were about to visit when abort
251- was initiated.
252- */
253-
254- void Deadlock_detection_visitor::abort_traversal (MDL_context *node)
255- {
256- DBUG_ASSERT (! m_victim);
257- m_found_deadlock= TRUE ;
258- opt_change_victim_to (node);
259- }
260-
261-
262254/* *
263255 Get a bit corresponding to enum_mdl_type value in a granted/waiting bitmaps
264256 and compatibility matrices.
@@ -2064,13 +2056,8 @@ bool MDL_lock::visit_subgraph(MDL_ticket *waiting_ticket,
20642056 are visiting it but this is OK: in the worst case we might do some
20652057 extra work and one more context might be chosen as a victim.
20662058 */
2067- ++gvisitor->m_current_search_depth ;
2068-
20692059 if (gvisitor->enter_node (src_ctx))
2070- {
2071- --gvisitor->m_current_search_depth ;
20722060 goto end;
2073- }
20742061
20752062 /*
20762063 We do a breadth-first search first -- that is, inspect all
@@ -2127,7 +2114,6 @@ bool MDL_lock::visit_subgraph(MDL_ticket *waiting_ticket,
21272114
21282115end_leave_node:
21292116 gvisitor->leave_node (src_ctx);
2130- --gvisitor->m_current_search_depth ;
21312117
21322118end:
21332119 mysql_prlock_unlock (&m_rwlock);
0 commit comments