Storage Engine API
mongo::LockerImpl< IsForMMAPV1 > Class Template Reference

Interface for acquiring locks. More...

#include <lock_state.h>

Inheritance diagram for mongo::LockerImpl< IsForMMAPV1 >:
mongo::Locker

Detailed Description

template<bool IsForMMAPV1>
class mongo::LockerImpl< IsForMMAPV1 >

Interface for acquiring locks.

One of those objects will have to be instantiated for each request (transaction).

Lock/unlock methods must always be called from a single thread.

All instances reference a single global lock manager.

Parameters
IsForMMAPV1Whether to compile-in the flush lock functionality, which is specific to the way the MMAP V1 (legacy) storag engine does commit concurrency control.

Public Member Functions

 LockerImpl ()
 Instantiates new locker. More...
 
virtual ~LockerImpl ()
 
virtual ClientState getClientState () const
 Return whether client is holding any locks (active), or is queued on any locks or waiting for a ticket (throttled). More...
 
virtual LockerId getId () const
 
stdx::thread::id getThreadId () const override
 Get a platform-specific thread identifier of the thread which owns the this locker for tracing purposes. More...
 
void updateThreadIdToCurrentThread () override
 Updates any cached thread id values to represent the current thread. More...
 
void unsetThreadId () override
 Clears any cached thread id values. More...
 
void setSharedLocksShouldTwoPhaseLock (bool sharedLocksShouldTwoPhaseLock) override
 Indicate that shared locks should participate in two-phase locking for this Locker instance. More...
 
void setMaxLockTimeout (Milliseconds maxTimeout) override
 This is useful to ensure that potential deadlocks do not occur. More...
 
bool hasMaxLockTimeout () override
 Returns whether this Locker has a maximum lock timeout set. More...
 
void unsetMaxLockTimeout () override
 Clears the max lock timeout override set by setMaxLockTimeout() above. More...
 
virtual LockResult lockGlobal (OperationContext *opCtx, LockMode mode)
 This should be the first method invoked for a particular Locker object. More...
 
virtual LockResult lockGlobal (LockMode mode)
 
virtual LockResult lockGlobalBegin (OperationContext *opCtx, LockMode mode, Date_t deadline)
 Requests the global lock to be acquired in the specified mode. More...
 
virtual LockResult lockGlobalBegin (LockMode mode, Date_t deadline)
 
virtual LockResult lockGlobalComplete (OperationContext *opCtx, Date_t deadline)
 Calling lockGlobalComplete without an OperationContext does not allow the lock acquisition to be interrupted. More...
 
virtual LockResult lockGlobalComplete (Date_t deadline)
 
virtual void lockMMAPV1Flush ()
 This method is used only in the MMAP V1 storage engine, otherwise it is a no-op. More...
 
virtual void downgradeGlobalXtoSForMMAPV1 ()
 This is only necessary for the MMAP V1 engine and in particular, the fsyncLock command which needs to first acquire the global lock in X-mode for truncating the journal and then downgrade to S before it blocks. More...
 
virtual bool unlockGlobal ()
 Decrements the reference count on the global lock. More...
 
virtual void beginWriteUnitOfWork ()
 beginWriteUnitOfWork/endWriteUnitOfWork are called at the start and end of WriteUnitOfWorks. More...
 
virtual void endWriteUnitOfWork ()
 
virtual bool inAWriteUnitOfWork () const
 
virtual LockResult lock (OperationContext *opCtx, ResourceId resId, LockMode mode, Date_t deadline=Date_t::max(), bool checkDeadlock=false)
 Requests a lock for resource 'resId' with mode 'mode'. More...
 
virtual LockResult lock (ResourceId resId, LockMode mode, Date_t deadline=Date_t::max(), bool checkDeadlock=false)
 Calling lock without an OperationContext does not allow LOCK_WAITING states to be interrupted. More...
 
virtual void downgrade (ResourceId resId, LockMode newMode)
 Downgrades the specified resource's lock mode without changing the reference count. More...
 
virtual bool unlock (ResourceId resId)
 Releases a lock previously acquired through a lock call. More...
 
virtual LockMode getLockMode (ResourceId resId) const
 Retrieves the mode in which a lock is held or checks whether the lock held for a particular resource covers the specified mode. More...
 
virtual bool isLockHeldForMode (ResourceId resId, LockMode mode) const
 
virtual bool isDbLockedForMode (StringData dbName, LockMode mode) const
 
virtual bool isCollectionLockedForMode (StringData ns, LockMode mode) const
 
virtual ResourceId getWaitingResource () const
 Returns the resource that this locker is waiting/blocked on (if any). More...
 
virtual void getLockerInfo (LockerInfo *lockerInfo) const
 
virtual boost::optional< LockerInfogetLockerInfo () const final
 Returns boost::none if this is an instance of LockerNoop, or a populated LockerInfo otherwise. More...
 
virtual bool saveLockStateAndUnlock (LockSnapshot *stateOut)
 Retrieves all locks held by this transaction, other than RESOURCE_MUTEX locks, and what mode they're held in. More...
 
virtual void restoreLockState (OperationContext *opCtx, const LockSnapshot &stateToRestore)
 Re-locks all locks whose state was stored in 'stateToRestore'. More...
 
virtual void restoreLockState (const LockSnapshot &stateToRestore)
 
virtual void releaseTicket ()
 Releases the ticket associated with the Locker. More...
 
virtual void reacquireTicket (OperationContext *opCtx)
 Reacquires a ticket for the Locker. More...
 
LockResult lockBegin (OperationContext *opCtx, ResourceId resId, LockMode mode)
 Allows for lock requests to be requested in a non-blocking way. More...
 
LockResult lockComplete (OperationContext *opCtx, ResourceId resId, LockMode mode, Date_t deadline, bool checkDeadlock)
 Waits for the completion of a lock, previously requested through lockBegin or lockGlobalBegin. More...
 
LockResult lockComplete (ResourceId resId, LockMode mode, Date_t deadline, bool checkDeadlock)
 
FastMapNoAlloc< ResourceId, LockRequestgetRequestsForTest () const
 This function is for unit testing only. More...
 
virtual void dump () const
 
virtual bool isW () const
 
virtual bool isR () const
 
virtual bool isLocked () const
 
virtual bool isWriteLocked () const
 
virtual bool isReadLocked () const
 
bool isGlobalLockedRecursively () override
 
virtual bool hasLockPending () const
 Pending means we are currently trying to get a lock (could be the parallel batch writer lock). More...
 
- Public Member Functions inherited from mongo::Locker
virtual ~Locker ()
 
virtual bool isNoop () const
 Returns true if this is an instance of LockerNoop. More...
 
void setShouldConflictWithSecondaryBatchApplication (bool newValue)
 If set to false, this opts out of conflicting with replication's use of the ParallelBatchWriterMode lock. More...
 
bool shouldConflictWithSecondaryBatchApplication () const
 
void setShouldAcquireTicket (bool newValue)
 If set to false, this opts out of the ticket mechanism. More...
 
bool shouldAcquireTicket () const
 
unsigned numResourcesToUnlockAtEndUnitOfWorkForTest () const
 This function is for unit testing only. More...
 

Private Types

typedef FastMapNoAlloc< ResourceId, LockRequestLockRequestsMap
 

Private Member Functions

LockResult _lockGlobalBegin (OperationContext *opCtx, LockMode, Date_t deadline)
 Like lockGlobalBegin, but accepts a deadline for acquiring a ticket. More...
 
bool _unlockImpl (LockRequestsMap::Iterator *it)
 The main functionality of the unlock method, except accepts iterator in order to avoid additional lookups during unlockGlobal. More...
 
LockMode _getModeForMMAPV1FlushLock () const
 MMAP V1 locking code yields and re-acquires the flush lock occasionally in order to allow the flush thread proceed. More...
 
bool _shouldDelayUnlock (ResourceId resId, LockMode mode) const
 Whether we should use two phase locking. More...
 
void _releaseTicket ()
 Releases the ticket for the Locker. More...
 
LockResult _acquireTicket (OperationContext *opCtx, LockMode mode, Date_t deadline)
 Acquires a ticket for the Locker under 'mode'. More...
 

Private Attributes

const LockerId _id
 
SpinLock _lock
 
LockRequestsMap _requests
 
CondVarLockGrantNotification _notify
 
SingleThreadedLockStats _stats
 
int _wuowNestingLevel
 
LockMode _modeForTicket = MODE_NONE
 
AtomicWord< ClientState_clientState {kInactive}
 
stdx::thread::id _threadId
 
bool _sharedLocksShouldTwoPhaseLock = false
 
boost::optional< Milliseconds > _maxLockTimeout
 

Friends

class AutoYieldFlushLockForMMAPV1Commit
 

Additional Inherited Members

- Public Types inherited from mongo::Locker
enum  ClientState {
  kInactive, kActiveReader, kActiveWriter, kQueuedReader,
  kQueuedWriter
}
 State for reporting the number of active and queued reader and writer clients. More...
 
- Static Public Member Functions inherited from mongo::Locker
static void setGlobalThrottling (class TicketHolder *reading, class TicketHolder *writing)
 Require global lock attempts to obtain tickets from 'reading' (for MODE_S and MODE_IS), and from 'writing' (for MODE_IX), which must have static lifetimes. More...
 
- Protected Member Functions inherited from mongo::Locker
 Locker ()
 
- Protected Attributes inherited from mongo::Locker
int _uninterruptibleLocksRequested = 0
 The number of callers that are guarding from lock interruptions. More...
 
unsigned _numResourcesToUnlockAtEndUnitOfWork = 0
 The number of LockRequests to unlock at the end of this WUOW. More...
 

Member Typedef Documentation

◆ LockRequestsMap

template<bool IsForMMAPV1>
typedef FastMapNoAlloc<ResourceId, LockRequest> mongo::LockerImpl< IsForMMAPV1 >::LockRequestsMap
private

Constructor & Destructor Documentation

◆ LockerImpl()

template<bool IsForMMAPV1>
mongo::LockerImpl< IsForMMAPV1 >::LockerImpl ( )

Instantiates new locker.

Must be given a unique identifier for disambiguation. Lockers having the same identifier will not conflict on lock acquisition.

◆ ~LockerImpl()

template<bool IsForMMAPV1>
mongo::LockerImpl< IsForMMAPV1 >::~LockerImpl ( )
virtual

Member Function Documentation

◆ _acquireTicket()

template<bool IsForMMAPV1>
LockResult mongo::LockerImpl< IsForMMAPV1 >::_acquireTicket ( OperationContext *  opCtx,
LockMode  mode,
Date_t  deadline 
)
private

Acquires a ticket for the Locker under 'mode'.

Returns LOCK_TIMEOUT if it cannot acquire a ticket within 'deadline'.

◆ _getModeForMMAPV1FlushLock()

template<bool IsForMMAPV1>
LockMode mongo::LockerImpl< IsForMMAPV1 >::_getModeForMMAPV1FlushLock ( ) const
private

MMAP V1 locking code yields and re-acquires the flush lock occasionally in order to allow the flush thread proceed.

This call returns in what mode the flush lock should be acquired. It is based on the type of the operation (IS for readers, IX for writers).

◆ _lockGlobalBegin()

template<bool IsForMMAPV1>
LockResult mongo::LockerImpl< IsForMMAPV1 >::_lockGlobalBegin ( OperationContext *  opCtx,
LockMode  mode,
Date_t  deadline 
)
private

Like lockGlobalBegin, but accepts a deadline for acquiring a ticket.

◆ _releaseTicket()

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::_releaseTicket ( )
private

Releases the ticket for the Locker.

◆ _shouldDelayUnlock()

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::_shouldDelayUnlock ( ResourceId  resId,
LockMode  mode 
) const
private

Whether we should use two phase locking.

Returns true if the particular lock's release should be delayed until the end of the operation.

We delay release of write operation locks (X, IX) in order to ensure that the data changes they protect are committed successfully. endWriteUnitOfWork will release them afterwards. This protects other threads from seeing inconsistent in-memory state.

Shared locks (S, IS) will also participate in two-phase locking if '_sharedLocksShouldTwoPhaseLock' is true. This will protect open storage engine transactions across network calls.

◆ _unlockImpl()

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::_unlockImpl ( LockRequestsMap::Iterator it)
private

The main functionality of the unlock method, except accepts iterator in order to avoid additional lookups during unlockGlobal.

Frees locks immediately, so must not be called from inside a WUOW.

◆ beginWriteUnitOfWork()

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::beginWriteUnitOfWork ( )
virtual

beginWriteUnitOfWork/endWriteUnitOfWork are called at the start and end of WriteUnitOfWorks.

They can be used to implement two-phase locking. Each call to begin should be matched with an eventual call to end.

endWriteUnitOfWork, if not called in a nested WUOW, will release all two-phase locking held lock resources.

Implements mongo::Locker.

◆ downgrade()

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::downgrade ( ResourceId  resId,
LockMode  newMode 
)
virtual

Downgrades the specified resource's lock mode without changing the reference count.

Implements mongo::Locker.

◆ downgradeGlobalXtoSForMMAPV1()

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::downgradeGlobalXtoSForMMAPV1 ( )
virtual

This is only necessary for the MMAP V1 engine and in particular, the fsyncLock command which needs to first acquire the global lock in X-mode for truncating the journal and then downgrade to S before it blocks.

The downgrade is necessary in order to be nice and not block readers while under fsyncLock.

Implements mongo::Locker.

◆ dump()

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::dump ( ) const
virtual

Implements mongo::Locker.

◆ endWriteUnitOfWork()

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::endWriteUnitOfWork ( )
virtual

Implements mongo::Locker.

◆ getClientState()

template<bool IsForMMAPV1>
Locker::ClientState mongo::LockerImpl< IsForMMAPV1 >::getClientState ( ) const
virtual

Return whether client is holding any locks (active), or is queued on any locks or waiting for a ticket (throttled).

Implements mongo::Locker.

◆ getId()

template<bool IsForMMAPV1>
virtual LockerId mongo::LockerImpl< IsForMMAPV1 >::getId ( ) const
inlinevirtual

Implements mongo::Locker.

◆ getLockerInfo() [1/2]

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::getLockerInfo ( LockerInfo lockerInfo) const
virtual

Implements mongo::Locker.

◆ getLockerInfo() [2/2]

template<bool IsForMMAPV1>
boost::optional< Locker::LockerInfo > mongo::LockerImpl< IsForMMAPV1 >::getLockerInfo ( ) const
finalvirtual

Returns boost::none if this is an instance of LockerNoop, or a populated LockerInfo otherwise.

Implements mongo::Locker.

◆ getLockMode()

template<bool IsForMMAPV1>
LockMode mongo::LockerImpl< IsForMMAPV1 >::getLockMode ( ResourceId  resId) const
virtual

Retrieves the mode in which a lock is held or checks whether the lock held for a particular resource covers the specified mode.

For example isLockHeldForMode will return true for MODE_S, if MODE_X is already held, because MODE_X covers MODE_S.

Implements mongo::Locker.

◆ getRequestsForTest()

template<bool IsForMMAPV1>
FastMapNoAlloc<ResourceId, LockRequest> mongo::LockerImpl< IsForMMAPV1 >::getRequestsForTest ( ) const
inline

This function is for unit testing only.

◆ getThreadId()

template<bool IsForMMAPV1>
stdx::thread::id mongo::LockerImpl< IsForMMAPV1 >::getThreadId ( ) const
overridevirtual

Get a platform-specific thread identifier of the thread which owns the this locker for tracing purposes.

Implements mongo::Locker.

◆ getWaitingResource()

template<bool IsForMMAPV1>
ResourceId mongo::LockerImpl< IsForMMAPV1 >::getWaitingResource ( ) const
virtual

Returns the resource that this locker is waiting/blocked on (if any).

If the locker is not waiting for a resource the returned value will be invalid (isValid() == false).

Implements mongo::Locker.

◆ hasLockPending()

template<bool IsForMMAPV1>
virtual bool mongo::LockerImpl< IsForMMAPV1 >::hasLockPending ( ) const
inlinevirtual

Pending means we are currently trying to get a lock (could be the parallel batch writer lock).

Implements mongo::Locker.

◆ hasMaxLockTimeout()

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::hasMaxLockTimeout ( )
inlineoverridevirtual

Returns whether this Locker has a maximum lock timeout set.

Implements mongo::Locker.

◆ inAWriteUnitOfWork()

template<bool IsForMMAPV1>
virtual bool mongo::LockerImpl< IsForMMAPV1 >::inAWriteUnitOfWork ( ) const
inlinevirtual

Implements mongo::Locker.

◆ isCollectionLockedForMode()

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::isCollectionLockedForMode ( StringData  ns,
LockMode  mode 
) const
virtual

Implements mongo::Locker.

◆ isDbLockedForMode()

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::isDbLockedForMode ( StringData  dbName,
LockMode  mode 
) const
virtual

Implements mongo::Locker.

◆ isGlobalLockedRecursively()

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::isGlobalLockedRecursively ( )
overridevirtual

Implements mongo::Locker.

◆ isLocked()

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::isLocked ( ) const
virtual

Implements mongo::Locker.

◆ isLockHeldForMode()

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::isLockHeldForMode ( ResourceId  resId,
LockMode  mode 
) const
virtual

Implements mongo::Locker.

◆ isR()

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::isR ( ) const
virtual

Implements mongo::Locker.

◆ isReadLocked()

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::isReadLocked ( ) const
virtual

Implements mongo::Locker.

◆ isW()

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::isW ( ) const
virtual

Implements mongo::Locker.

◆ isWriteLocked()

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::isWriteLocked ( ) const
virtual

Implements mongo::Locker.

◆ lock() [1/2]

template<bool IsForMMAPV1>
LockResult mongo::LockerImpl< IsForMMAPV1 >::lock ( OperationContext *  opCtx,
ResourceId  resId,
LockMode  mode,
Date_t  deadline = Date_t::max(),
bool  checkDeadlock = false 
)
virtual

Requests a lock for resource 'resId' with mode 'mode'.

An OperationContext 'opCtx' must be provided to interrupt waiting on the locker condition variable that indicates status of the lock acquisition. A lock operation would otherwise wait until a timeout or the lock is granted.

Implements mongo::Locker.

◆ lock() [2/2]

template<bool IsForMMAPV1>
virtual LockResult mongo::LockerImpl< IsForMMAPV1 >::lock ( ResourceId  resId,
LockMode  mode,
Date_t  deadline = Date_t::max(),
bool  checkDeadlock = false 
)
inlinevirtual

Calling lock without an OperationContext does not allow LOCK_WAITING states to be interrupted.

Implements mongo::Locker.

◆ lockBegin()

template<bool IsForMMAPV1>
LockResult mongo::LockerImpl< IsForMMAPV1 >::lockBegin ( OperationContext *  opCtx,
ResourceId  resId,
LockMode  mode 
)

Allows for lock requests to be requested in a non-blocking way.

There can be only one outstanding pending lock request per locker object.

lockBegin posts a request to the lock manager for the specified lock to be acquired, which either immediately grants the lock, or puts the requestor on the conflict queue and returns immediately with the result of the acquisition. The result can be one of:

LOCK_OK - Nothing more needs to be done. The lock is granted. LOCK_WAITING - The request has been queued up and will be granted as soon as the lock is free. If this result is returned, typically lockComplete needs to be called in order to wait for the actual grant to occur. If the caller no longer needs to wait for the grant to happen, unlock needs to be called with the same resource passed to lockBegin.

In other words for each call to lockBegin, which does not return LOCK_OK, there needs to be a corresponding call to either lockComplete or unlock.

If an operation context is provided that represents an interrupted operation, lockBegin will throw an exception whenever it would have been possible to grant the lock with LOCK_OK. This behavior can be disabled with an UninterruptibleLockGuard.

NOTE: These methods are not public and should only be used inside the class implementation and for unit-tests and not called directly.

◆ lockComplete() [1/2]

template<bool IsForMMAPV1>
LockResult mongo::LockerImpl< IsForMMAPV1 >::lockComplete ( OperationContext *  opCtx,
ResourceId  resId,
LockMode  mode,
Date_t  deadline,
bool  checkDeadlock 
)

Waits for the completion of a lock, previously requested through lockBegin or lockGlobalBegin.

Must only be called, if lockBegin returned LOCK_WAITING.

Parameters
opCtxOperation context that, if not null, will be used to allow interruptible lock acquisition.
resIdResource id which was passed to an earlier lockBegin call. Must match.
modeMode which was passed to an earlier lockBegin call. Must match.
deadlineThe absolute time point when this lock acquisition will time out, if not yet granted.
checkDeadlockwhether to perform deadlock detection while waiting.

◆ lockComplete() [2/2]

template<bool IsForMMAPV1>
LockResult mongo::LockerImpl< IsForMMAPV1 >::lockComplete ( ResourceId  resId,
LockMode  mode,
Date_t  deadline,
bool  checkDeadlock 
)
inline

◆ lockGlobal() [1/2]

template<bool IsForMMAPV1>
LockResult mongo::LockerImpl< IsForMMAPV1 >::lockGlobal ( OperationContext *  opCtx,
LockMode  mode 
)
virtual

This should be the first method invoked for a particular Locker object.

It acquires the Global lock in the specified mode and effectively indicates the mode of the operation. This is what the lock modes on the global lock mean:

IX - Regular write operation IS - Regular read operation S - Stops all write activity. Used for administrative operations (repl, etc). X - Stops all activity. Used for administrative operations (repl state changes, shutdown, etc).

This method can be called recursively, but each call to lockGlobal must be accompanied by a call to unlockGlobal.

Parameters
opCtxOperationContext used to interrupt the lock waiting, if provided.
modeMode in which the global lock should be acquired. Also indicates the intent of the operation.
Returns
LOCK_OK, if the global lock (and the flush lock, for the MMAP V1 engine) were acquired within the specified time bound. Otherwise, the respective failure code and neither lock will be acquired.

Implements mongo::Locker.

◆ lockGlobal() [2/2]

template<bool IsForMMAPV1>
virtual LockResult mongo::LockerImpl< IsForMMAPV1 >::lockGlobal ( LockMode  mode)
inlinevirtual

Implements mongo::Locker.

◆ lockGlobalBegin() [1/2]

template<bool IsForMMAPV1>
virtual LockResult mongo::LockerImpl< IsForMMAPV1 >::lockGlobalBegin ( OperationContext *  opCtx,
LockMode  mode,
Date_t  deadline 
)
inlinevirtual

Requests the global lock to be acquired in the specified mode.

See the comments for lockBegin/Complete for more information on the semantics. The deadline indicates the absolute time point when this lock acquisition will time out, if not yet granted. The lockGlobalBegin method has a deadline for use with the TicketHolder, if there is one.

Implements mongo::Locker.

◆ lockGlobalBegin() [2/2]

template<bool IsForMMAPV1>
virtual LockResult mongo::LockerImpl< IsForMMAPV1 >::lockGlobalBegin ( LockMode  mode,
Date_t  deadline 
)
inlinevirtual

Implements mongo::Locker.

◆ lockGlobalComplete() [1/2]

template<bool IsForMMAPV1>
LockResult mongo::LockerImpl< IsForMMAPV1 >::lockGlobalComplete ( OperationContext *  opCtx,
Date_t  deadline 
)
virtual

Calling lockGlobalComplete without an OperationContext does not allow the lock acquisition to be interrupted.

Implements mongo::Locker.

◆ lockGlobalComplete() [2/2]

template<bool IsForMMAPV1>
virtual LockResult mongo::LockerImpl< IsForMMAPV1 >::lockGlobalComplete ( Date_t  deadline)
inlinevirtual

Implements mongo::Locker.

◆ lockMMAPV1Flush()

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::lockMMAPV1Flush ( )
virtual

This method is used only in the MMAP V1 storage engine, otherwise it is a no-op.

See the comments in the implementation for more details on how MMAP V1 journaling works.

Implements mongo::Locker.

◆ reacquireTicket()

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::reacquireTicket ( OperationContext *  opCtx)
virtual

Reacquires a ticket for the Locker.

This must only be called after releaseTicket(). It restores the ticket under its previous LockMode. An OperationContext is required to interrupt the ticket acquisition to prevent deadlocks. A dead lock is possible when a ticket is reacquired while holding a lock.

Implements mongo::Locker.

◆ releaseTicket()

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::releaseTicket ( )
virtual

Releases the ticket associated with the Locker.

This allows locks to be held without contributing to reader/writer throttling.

Implements mongo::Locker.

◆ restoreLockState() [1/2]

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::restoreLockState ( OperationContext *  opCtx,
const LockSnapshot stateToRestore 
)
virtual

Re-locks all locks whose state was stored in 'stateToRestore'.

Parameters
opCtxAn operation context that enables the restoration to be interrupted.

Implements mongo::Locker.

◆ restoreLockState() [2/2]

template<bool IsForMMAPV1>
virtual void mongo::LockerImpl< IsForMMAPV1 >::restoreLockState ( const LockSnapshot stateToRestore)
inlinevirtual

Implements mongo::Locker.

◆ saveLockStateAndUnlock()

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::saveLockStateAndUnlock ( LockSnapshot stateOut)
virtual

Retrieves all locks held by this transaction, other than RESOURCE_MUTEX locks, and what mode they're held in.

Stores these locks in 'stateOut', destroying any previous state. Unlocks all locks held by this transaction. This functionality is used for yielding, which is voluntary/cooperative lock release and reacquisition in order to allow for interleaving of otherwise conflicting long-running operations.

This functionality is also used for releasing locks on databases and collections when cursors are dormant and waiting for a getMore request.

Returns true if locks are released. It is expected that restoreLockerImpl will be called in the future.

Returns false if locks are not released. restoreLockState(...) does not need to be called in this case.

Implements mongo::Locker.

◆ setMaxLockTimeout()

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::setMaxLockTimeout ( Milliseconds  maxTimeout)
inlineoverridevirtual

This is useful to ensure that potential deadlocks do not occur.

Overrides provided timeouts in lock requests with 'maxTimeout' if the provided timeout is greater. Basically, no lock acquisition will take longer than 'maxTimeout'.

If an UninterruptibleLockGuard is set during a lock request, the max timeout override will be ignored.

Future lock requests may throw LockTimeout errors if a lock request provides a Date_t::max() deadline and 'maxTimeout' is reached. Presumably these callers do not expect to handle lock acquisition failure, so this is done to ensure the caller does not proceed as if the lock were successfully acquired.

Implements mongo::Locker.

◆ setSharedLocksShouldTwoPhaseLock()

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::setSharedLocksShouldTwoPhaseLock ( bool  sharedLocksShouldTwoPhaseLock)
inlineoverridevirtual

Indicate that shared locks should participate in two-phase locking for this Locker instance.

Implements mongo::Locker.

◆ unlock()

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::unlock ( ResourceId  resId)
virtual

Releases a lock previously acquired through a lock call.

It is an error to try to release lock which has not been previously acquired (invariant violation).

Returns
true if the lock was actually released; false if only the reference count was decremented, but the lock is still held.

Implements mongo::Locker.

◆ unlockGlobal()

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::unlockGlobal ( )
virtual

Decrements the reference count on the global lock.

If the reference count on the global lock hits zero, the transaction is over, and unlockGlobal unlocks all other locks except for RESOURCE_MUTEX locks.

Returns
true if this is the last endTransaction call (i.e., the global lock was released); false if there are still references on the global lock. This value should not be relied on and is only used for assertion purposes.
false if the global lock is still held.

Implements mongo::Locker.

◆ unsetMaxLockTimeout()

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::unsetMaxLockTimeout ( )
inlineoverridevirtual

Clears the max lock timeout override set by setMaxLockTimeout() above.

Implements mongo::Locker.

◆ unsetThreadId()

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::unsetThreadId ( )
overridevirtual

Clears any cached thread id values.

Implements mongo::Locker.

◆ updateThreadIdToCurrentThread()

template<bool IsForMMAPV1>
void mongo::LockerImpl< IsForMMAPV1 >::updateThreadIdToCurrentThread ( )
overridevirtual

Updates any cached thread id values to represent the current thread.

Implements mongo::Locker.

Friends And Related Function Documentation

◆ AutoYieldFlushLockForMMAPV1Commit

template<bool IsForMMAPV1>
friend class AutoYieldFlushLockForMMAPV1Commit
friend

Member Data Documentation

◆ _clientState

template<bool IsForMMAPV1>
AtomicWord<ClientState> mongo::LockerImpl< IsForMMAPV1 >::_clientState {kInactive}
private

◆ _id

template<bool IsForMMAPV1>
const LockerId mongo::LockerImpl< IsForMMAPV1 >::_id
private

◆ _lock

template<bool IsForMMAPV1>
SpinLock mongo::LockerImpl< IsForMMAPV1 >::_lock
mutableprivate

◆ _maxLockTimeout

template<bool IsForMMAPV1>
boost::optional<Milliseconds> mongo::LockerImpl< IsForMMAPV1 >::_maxLockTimeout
private

◆ _modeForTicket

template<bool IsForMMAPV1>
LockMode mongo::LockerImpl< IsForMMAPV1 >::_modeForTicket = MODE_NONE
private

◆ _notify

template<bool IsForMMAPV1>
CondVarLockGrantNotification mongo::LockerImpl< IsForMMAPV1 >::_notify
private

◆ _requests

template<bool IsForMMAPV1>
LockRequestsMap mongo::LockerImpl< IsForMMAPV1 >::_requests
private

◆ _sharedLocksShouldTwoPhaseLock

template<bool IsForMMAPV1>
bool mongo::LockerImpl< IsForMMAPV1 >::_sharedLocksShouldTwoPhaseLock = false
private

◆ _stats

template<bool IsForMMAPV1>
SingleThreadedLockStats mongo::LockerImpl< IsForMMAPV1 >::_stats
private

◆ _threadId

template<bool IsForMMAPV1>
stdx::thread::id mongo::LockerImpl< IsForMMAPV1 >::_threadId
private

◆ _wuowNestingLevel

template<bool IsForMMAPV1>
int mongo::LockerImpl< IsForMMAPV1 >::_wuowNestingLevel
private

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