35 #include "mongo/db/operation_context.h" 36 #include "mongo/platform/atomic_word.h" 37 #include "mongo/util/concurrency/spin_lock.h" 95 template <
bool IsForMMAPV1>
168 Date_t deadline = Date_t::max(),
169 bool checkDeadlock =
false);
173 Date_t deadline = Date_t::max(),
174 bool checkDeadlock =
false) {
175 return lock(
nullptr, resId, mode, deadline, checkDeadlock);
190 virtual boost::optional<LockerInfo>
getLockerInfo() const final;
248 return lockComplete(
nullptr, resId, mode, deadline, checkDeadlock);
255 scoped_spinlock scopedLock(
_lock);
359 virtual void dump()
const;
361 virtual bool isW()
const;
362 virtual bool isR()
const;
LockMode _modeForTicket
Definition: lock_state.h:335
virtual void notify(ResourceId resId, LockResult result)
This method is invoked at most once for each lock request and indicates the outcome of the lock acqui...
Definition: lock_state.cpp:236
virtual void downgrade(ResourceId resId, LockMode newMode)
Downgrades the specified resource's lock mode without changing the reference count.
Definition: lock_state.cpp:504
LockManager * getGlobalLockManager()
Retrieves the global lock manager instance.
Definition: lock_state.cpp:1096
Interface for acquiring locks.
Definition: locker.h:47
Entry point for the lock manager scheduling functionality.
Definition: lock_manager.h:53
virtual void downgradeGlobalXtoSForMMAPV1()
This is only necessary for the MMAP V1 engine and in particular, the fsyncLock command which needs to...
Definition: lock_state.cpp:401
Collection *const const NamespaceString & ns
Definition: collection_info_cache_impl.cpp:53
virtual bool unlock(ResourceId resId)
Releases a lock previously acquired through a lock call.
Definition: lock_state.cpp:510
Interface on which granted lock requests will be notified.
Definition: lock_manager_defs.h:289
void _releaseTicket()
Releases the ticket for the Locker.
Definition: lock_state.cpp:942
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
virtual ResourceId getWaitingResource() const
Returns the resource that this locker is waiting/blocked on (if any).
Definition: lock_state.cpp:596
SingleThreadedLockStats _stats
Definition: lock_state.h:328
FastMapNoAlloc< ResourceId, LockRequest > getRequestsForTest() const
This function is for unit testing only.
Definition: lock_state.h:254
uint64_t LockerId
Definition: lock_manager_defs.h:259
LockerImpl< true > MMAPV1LockerImpl
Definition: lock_state.h:375
void unsetMaxLockTimeout() override
Clears the max lock timeout override set by setMaxLockTimeout() above.
Definition: lock_state.h:129
virtual bool saveLockStateAndUnlock(LockSnapshot *stateOut)
Retrieves all locks held by this transaction, other than RESOURCE_MUTEX locks, and what mode they're ...
Definition: lock_state.cpp:647
virtual bool unlockGlobal()
Decrements the reference count on the global lock.
Definition: lock_state.cpp:424
void updateThreadIdToCurrentThread() override
Updates any cached thread id values to represent the current thread.
Definition: lock_state.cpp:270
SpinLock _lock
Definition: lock_state.h:316
const LockerId _id
Definition: lock_state.h:309
void unsetThreadId() override
Clears any cached thread id values.
Definition: lock_state.cpp:275
void setMaxLockTimeout(Milliseconds maxTimeout) override
This is useful to ensure that potential deadlocks do not occur.
Definition: lock_state.h:121
virtual bool isReadLocked() const
Definition: lock_state.cpp:185
virtual bool isLocked() const
Definition: lock_state.cpp:175
virtual void lockMMAPV1Flush()
This method is used only in the MMAP V1 storage engine, otherwise it is a no-op.
Definition: lock_state.cpp:385
LockMode _getModeForMMAPV1FlushLock() const
MMAP V1 locking code yields and re-acquires the flush lock occasionally in order to allow the flush t...
Definition: lock_state.cpp:974
bool isGlobalLockedRecursively() override
Definition: lock_state.cpp:992
LockResult lockComplete(ResourceId resId, LockMode mode, Date_t deadline, bool checkDeadlock)
Definition: lock_state.h:247
virtual void reacquireTicket(OperationContext *opCtx)
Reacquires a ticket for the Locker.
Definition: lock_state.cpp:320
virtual bool hasLockPending() const
Pending means we are currently trying to get a lock (could be the parallel batch writer lock).
Definition: lock_state.h:369
bool _unlockImpl(LockRequestsMap::Iterator *it)
The main functionality of the unlock method, except accepts iterator in order to avoid additional loo...
Definition: lock_state.cpp:951
FastMapNoAlloc< ResourceId, LockRequest > LockRequestsMap
Definition: lock_state.h:262
stdx::thread::id getThreadId() const override
Get a platform-specific thread identifier of the thread which owns the this locker for tracing purpos...
Definition: lock_state.cpp:265
Uniquely identifies a lockable resource.
Definition: lock_manager_defs.h:189
virtual void dump() const
Definition: lock_state.cpp:190
stdx::mutex _mutex
Definition: lock_state.h:76
virtual void beginWriteUnitOfWork()
beginWriteUnitOfWork/endWriteUnitOfWork are called at the start and end of WriteUnitOfWorks.
Definition: lock_state.cpp:447
Notfication callback, which stores the last notification result and signals a condition variable,...
Definition: lock_state.h:45
void setSharedLocksShouldTwoPhaseLock(bool sharedLocksShouldTwoPhaseLock) override
Indicate that shared locks should participate in two-phase locking for this Locker instance.
Definition: lock_state.h:117
virtual bool isDbLockedForMode(StringData dbName, LockMode mode) const
Definition: lock_state.cpp:547
virtual ~LockerImpl()
Definition: lock_state.cpp:280
void clear()
Clears the object so it can be reused.
Definition: lock_state.cpp:215
virtual bool isCollectionLockedForMode(StringData ns, LockMode mode) const
Definition: lock_state.cpp:560
LockResult _result
Definition: lock_state.h:80
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 ...
Definition: lock_state.cpp:531
IndexSet::const_iterator it
Definition: ephemeral_for_test_btree_impl.cpp:458
CondVarLockGrantNotification _notify
Definition: lock_state.h:324
virtual void restoreLockState(OperationContext *opCtx, const LockSnapshot &stateToRestore)
Re-locks all locks whose state was stored in 'stateToRestore'.
Definition: lock_state.cpp:707
bool hasMaxLockTimeout() override
Returns whether this Locker has a maximum lock timeout set.
Definition: lock_state.h:125
LockResult
Return values for the locking functions of the lock manager.
Definition: lock_manager_defs.h:108
Interface for acquiring locks.
Definition: lock_state.h:96
LockMode
LockMode compatibility matrix.
Definition: lock_manager_defs.h:61
virtual LockResult lockGlobal(LockMode mode)
Definition: lock_state.h:134
LockRequestsMap _requests
Definition: lock_state.h:320
ClientState
State for reporting the number of active and queued reader and writer clients.
Definition: locker.h:79
LockResult wait(Milliseconds timeout)
Uninterruptible blocking method, which waits for the notification to fire.
Definition: lock_state.cpp:219
stdx::thread::id _threadId
Definition: lock_state.h:341
std::array< DefaultLockerImpl, kMaxPerfThreads > locker
Definition: d_concurrency_bm.cpp:66
virtual void endWriteUnitOfWork()
Definition: lock_state.cpp:456
bool _sharedLocksShouldTwoPhaseLock
Definition: lock_state.h:344
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'.
Definition: lock_state.cpp:487
virtual bool isWriteLocked() const
Definition: lock_state.cpp:180
LockResult lockBegin(OperationContext *opCtx, ResourceId resId, LockMode mode)
Allows for lock requests to be requested in a non-blocking way.
Definition: lock_state.cpp:734
stdx::condition_variable _cond
Definition: lock_state.h:77
CondVarLockGrantNotification()
Definition: lock_state.cpp:211
virtual boost::optional< LockerInfo > getLockerInfo() const final
Returns boost::none if this is an instance of LockerNoop, or a populated LockerInfo otherwise.
Definition: lock_state.cpp:640
bool _shouldDelayUnlock(ResourceId resId, LockMode mode) const
Whether we should use two phase locking.
Definition: lock_state.cpp:132
boost::optional< Milliseconds > _maxLockTimeout
Definition: lock_state.h:350
None.
Definition: lock_manager_defs.h:63
IteratorImpl< FastMapNoAlloc< ResourceId, LockRequest >, LockRequest, map_iterator > Iterator
Definition: fast_map_noalloc.h:196
virtual LockResult lockGlobalBegin(OperationContext *opCtx, LockMode mode, Date_t deadline)
Requests the global lock to be acquired in the specified mode.
Definition: lock_state.h:137
MONGO_DISALLOW_COPYING(CondVarLockGrantNotification)
virtual bool isR() const
Definition: lock_state.cpp:170
virtual ClientState getClientState() const
Return whether client is holding any locks (active), or is queued on any locks or waiting for a ticke...
Definition: lock_state.cpp:294
virtual LockResult lockGlobal(OperationContext *opCtx, LockMode mode)
This should be the first method invoked for a particular Locker object.
Definition: lock_state.cpp:305
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.
Definition: lock_state.cpp:817
virtual bool inAWriteUnitOfWork() const
Definition: lock_state.h:155
LockResult _acquireTicket(OperationContext *opCtx, LockMode mode, Date_t deadline)
Acquires a ticket for the Locker under 'mode'.
Definition: lock_state.cpp:327
virtual LockResult lockGlobalComplete(OperationContext *opCtx, Date_t deadline)
Calling lockGlobalComplete without an OperationContext does not allow the lock acquisition to be inte...
Definition: lock_state.cpp:380
LockSnapshot captures the state of all resources that are locked, what modes they're locked in,...
Definition: locker.h:342
LockResult _lockGlobalBegin(OperationContext *opCtx, LockMode, Date_t deadline)
Like lockGlobalBegin, but accepts a deadline for acquiring a ticket.
Definition: lock_state.cpp:349
AtomicWord< ClientState > _clientState
Definition: lock_state.h:338
virtual LockResult lockGlobalComplete(Date_t deadline)
Definition: lock_state.h:144
virtual bool isLockHeldForMode(ResourceId resId, LockMode mode) const
Definition: lock_state.cpp:542
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
virtual LockResult lockGlobalBegin(LockMode mode, Date_t deadline)
Definition: lock_state.h:140
LockerImpl()
Instantiates new locker.
Definition: lock_state.cpp:261
int _wuowNestingLevel
Definition: lock_state.h:332
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.
Definition: lock_state.h:171
LockerImpl< false > DefaultLockerImpl
Definition: lock_state.h:374
virtual LockerId getId() const
Definition: lock_state.h:108
bool isValid() const
Definition: lock_manager_defs.h:211
virtual void releaseTicket()
Releases the ticket associated with the Locker.
Definition: lock_state.cpp:936
virtual bool isW() const
Definition: lock_state.cpp:165