MySQL 8.0.32
Source Code Documentation
Deadlock_detection_visitor Class Reference

A context of the recursive traversal through all contexts in all sessions in search for deadlock. More...

Inheritance diagram for Deadlock_detection_visitor:
[legend]

Public Member Functions

 Deadlock_detection_visitor (MDL_context *start_node_arg)
 
bool enter_node (MDL_context *node) override
 Enter a node of a wait-for graph. More...
 
void leave_node (MDL_context *node) override
 Done inspecting this node. More...
 
bool inspect_edge (MDL_context *dest) override
 Inspect a wait-for graph edge from one MDL context to another. More...
 
MDL_contextget_victim () const
 
- Public Member Functions inherited from MDL_wait_for_graph_visitor
virtual ~MDL_wait_for_graph_visitor ()
 
 MDL_wait_for_graph_visitor ()
 

Private Member Functions

void opt_change_victim_to (MDL_context *new_victim)
 Change the deadlock victim to a new one if it has lower deadlock weight. More...
 

Private Attributes

MDL_contextm_start_node
 The context which has initiated the search. More...
 
MDL_contextm_victim
 If a deadlock is found, the context that identifies the victim. More...
 
uint m_current_search_depth
 Set to the 0 at start. More...
 
bool m_found_deadlock
 true if we found a deadlock. More...
 

Static Private Attributes

static const uint MAX_SEARCH_DEPTH = 32
 Maximum depth for deadlock searches. More...
 

Additional Inherited Members

- Public Attributes inherited from MDL_wait_for_graph_visitor
uint m_lock_open_count
 XXX, hack: During deadlock search, we may need to inspect TABLE_SHAREs and acquire LOCK_open. More...
 

Detailed Description

A context of the recursive traversal through all contexts in all sessions in search for deadlock.

Constructor & Destructor Documentation

◆ Deadlock_detection_visitor()

Deadlock_detection_visitor::Deadlock_detection_visitor ( MDL_context start_node_arg)
inline

Member Function Documentation

◆ enter_node()

bool Deadlock_detection_visitor::enter_node ( MDL_context node)
overridevirtual

Enter a node of a wait-for graph.

After a node is entered, inspect_edge() will be called for all wait-for destinations of this node. Then leave_node() will be called. We call "enter_node()" for all nodes we inspect, including the starting node.

Return values
trueMaximum search depth exceeded.
falseOK.

Implements MDL_wait_for_graph_visitor.

◆ get_victim()

MDL_context * Deadlock_detection_visitor::get_victim ( ) const
inline

◆ inspect_edge()

bool Deadlock_detection_visitor::inspect_edge ( MDL_context node)
overridevirtual

Inspect a wait-for graph edge from one MDL context to another.

Return values
trueA loop is found.
falseNo loop is found.

Implements MDL_wait_for_graph_visitor.

◆ leave_node()

void Deadlock_detection_visitor::leave_node ( MDL_context node)
overridevirtual

Done inspecting this node.

Decrease the search depth. If a deadlock is found, and we are backtracking to the start node, optionally change the deadlock victim to one with lower deadlock weight.

Implements MDL_wait_for_graph_visitor.

◆ opt_change_victim_to()

void Deadlock_detection_visitor::opt_change_victim_to ( MDL_context new_victim)
private

Change the deadlock victim to a new one if it has lower deadlock weight.

Parameters
new_victimNew candidate for deadlock victim.

Member Data Documentation

◆ m_current_search_depth

uint Deadlock_detection_visitor::m_current_search_depth
private

Set to the 0 at start.

Increased whenever we descend into another MDL context (aka traverse to the next wait-for graph node). When MAX_SEARCH_DEPTH is reached, we assume that a deadlock is found, even if we have not found a loop.

◆ m_found_deadlock

bool Deadlock_detection_visitor::m_found_deadlock
private

true if we found a deadlock.

◆ m_start_node

MDL_context* Deadlock_detection_visitor::m_start_node
private

The context which has initiated the search.

There can be multiple searches happening in parallel at the same time.

◆ m_victim

MDL_context* Deadlock_detection_visitor::m_victim
private

If a deadlock is found, the context that identifies the victim.

◆ MAX_SEARCH_DEPTH

const uint Deadlock_detection_visitor::MAX_SEARCH_DEPTH = 32
staticprivate

Maximum depth for deadlock searches.

After this depth is achieved we will unconditionally declare that there is a deadlock.

Note
This depth should be small enough to avoid stack being exhausted by recursive search algorithm.

TODO: Find out what is the optimal value for this parameter. Current value is safe, but probably sub-optimal, as there is an anecdotal evidence that real-life deadlocks are even shorter typically.


The documentation for this class was generated from the following file: