Storage Engine API
mongo::DeadlockDetector Class Reference

Iteratively builds the wait-for graph, starting from a given blocked Locker and stops either when all reachable nodes have been checked or if a cycle is detected. More...

#include <lock_manager.h>

Detailed Description

Iteratively builds the wait-for graph, starting from a given blocked Locker and stops either when all reachable nodes have been checked or if a cycle is detected.

This class is thread-safe. Because locks may come and go in parallel with deadlock detection, it may report false positives, but if there is a stable cycle it will be discovered.

Implemented as a separate class in order to facilitate diagnostics and also unit-testing for cases where locks come and go in parallel with deadlock detection.

Classes

struct  Edges
 
struct  UnprocessedNode
 

Public Member Functions

 DeadlockDetector (const LockManager &lockMgr, const Locker *initialLocker)
 Initializes the wait-for graph builder with the LM to operate on and a locker object from which to start the search. More...
 
DeadlockDetectorcheck ()
 
bool next ()
 Processes the next wait for node and queues up its set of owners to the unprocessed queue. More...
 
bool hasCycle () const
 Checks whether a cycle exists in the wait-for graph, which has been built so far. More...
 
std::string toString () const
 Produces a string containing the wait-for graph that has been built so far. More...
 

Private Types

typedef std::vector< LockerIdConflictingOwnersList
 
typedef std::map< LockerId, EdgesWaitForGraph
 
typedef WaitForGraph::value_type WaitForGraphPair
 
typedef std::deque< UnprocessedNodeUnprocessedNodesQueue
 

Private Member Functions

void _processNextNode (const UnprocessedNode &node)
 

Private Attributes

const LockManager_lockMgr
 
const LockerId _initialLockerId
 
UnprocessedNodesQueue _queue
 
WaitForGraph _graph
 
bool _foundCycle
 

Member Typedef Documentation

◆ ConflictingOwnersList

◆ UnprocessedNodesQueue

◆ WaitForGraph

◆ WaitForGraphPair

typedef WaitForGraph::value_type mongo::DeadlockDetector::WaitForGraphPair
private

Constructor & Destructor Documentation

◆ DeadlockDetector()

mongo::DeadlockDetector::DeadlockDetector ( const LockManager lockMgr,
const Locker initialLocker 
)

Initializes the wait-for graph builder with the LM to operate on and a locker object from which to start the search.

Deadlock will only be reported if there is a wait cycle in which the initial locker participates.

Member Function Documentation

◆ _processNextNode()

void mongo::DeadlockDetector::_processNextNode ( const UnprocessedNode node)
private

◆ check()

DeadlockDetector& mongo::DeadlockDetector::check ( )
inline

◆ hasCycle()

bool mongo::DeadlockDetector::hasCycle ( ) const

Checks whether a cycle exists in the wait-for graph, which has been built so far.

It's only useful to call this after next() has returned false.

◆ next()

bool mongo::DeadlockDetector::next ( )

Processes the next wait for node and queues up its set of owners to the unprocessed queue.

Returns
true if there are more unprocessed nodes and no cycle has been discovered yet; false if either all reachable nodes have been processed or

◆ toString()

std::string mongo::DeadlockDetector::toString ( ) const

Produces a string containing the wait-for graph that has been built so far.

Member Data Documentation

◆ _foundCycle

bool mongo::DeadlockDetector::_foundCycle
private

◆ _graph

WaitForGraph mongo::DeadlockDetector::_graph
private

◆ _initialLockerId

const LockerId mongo::DeadlockDetector::_initialLockerId
private

◆ _lockMgr

const LockManager& mongo::DeadlockDetector::_lockMgr
private

◆ _queue

UnprocessedNodesQueue mongo::DeadlockDetector::_queue
private

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