Storage Engine API
mongo::Lock::DBLock Class Reference

Database lock with support for collection- and document-level locking. More...

#include <d_concurrency.h>

Detailed Description

Database lock with support for collection- and document-level locking.

This lock supports four modes (see Lock_Mode): MODE_IS: concurrent database access, requiring further collection read locks MODE_IX: concurrent database access, requiring further collection read or write locks MODE_S: shared read access to the database, blocking any writers MODE_X: exclusive access to the database, blocking all other readers and writers

For MODE_IS or MODE_S also acquires global lock in intent-shared (IS) mode, and for MODE_IX or MODE_X also acquires global lock in intent-exclusive (IX) mode. For storage engines that do not support collection-level locking, MODE_IS will be upgraded to MODE_S and MODE_IX will be upgraded to MODE_X.

Public Member Functions

 DBLock (OperationContext *opCtx, StringData db, LockMode mode, Date_t deadline=Date_t::max())
 
 DBLock (DBLock &&)
 
 ~DBLock ()
 
void relockWithMode (LockMode newMode)
 Releases the DBLock and reacquires it with the new mode. More...
 
bool isLocked () const
 

Private Attributes

const ResourceId _id
 
OperationContext *const _opCtx
 
LockResult _result
 
LockMode _mode
 
GlobalLock _globalLock
 

Constructor & Destructor Documentation

◆ DBLock() [1/2]

mongo::Lock::DBLock::DBLock ( OperationContext *  opCtx,
StringData  db,
LockMode  mode,
Date_t  deadline = Date_t::max() 
)

◆ DBLock() [2/2]

mongo::Lock::DBLock::DBLock ( DBLock &&  otherLock)

◆ ~DBLock()

mongo::Lock::DBLock::~DBLock ( )

Member Function Documentation

◆ isLocked()

bool mongo::Lock::DBLock::isLocked ( ) const
inline

◆ relockWithMode()

void mongo::Lock::DBLock::relockWithMode ( LockMode  newMode)

Releases the DBLock and reacquires it with the new mode.

The global intent lock is retained (so the database can't disappear). Relocking from MODE_IS or MODE_S to MODE_IX or MODE_X is not allowed to avoid violating the global intent. Use relockWithMode() instead of upgrading to avoid deadlock.

Member Data Documentation

◆ _globalLock

GlobalLock mongo::Lock::DBLock::_globalLock
private

◆ _id

const ResourceId mongo::Lock::DBLock::_id
private

◆ _mode

LockMode mongo::Lock::DBLock::_mode
private

◆ _opCtx

OperationContext* const mongo::Lock::DBLock::_opCtx
private

◆ _result

LockResult mongo::Lock::DBLock::_result
private

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