Entry point for the lock manager scheduling functionality.
More...
#include <lock_manager.h>
Entry point for the lock manager scheduling functionality.
Don't use it directly, but instead go through the Locker interface.
|
| LockManager () |
|
| ~LockManager () |
|
LockResult | lock (ResourceId resId, LockRequest *request, LockMode mode) |
| Acquires lock on the specified resource in the specified mode and returns the outcome of the operation. More...
|
|
LockResult | convert (ResourceId resId, LockRequest *request, LockMode newMode) |
|
bool | unlock (LockRequest *request) |
| Decrements the reference count of a previously locked request and if the reference count becomes zero, removes the request and proceeds to granting any conflicts. More...
|
|
void | downgrade (LockRequest *request, LockMode newMode) |
| Downgrades the mode in which an already granted request is held, without changing the reference count of the lock request. More...
|
|
void | cleanupUnusedLocks () |
| Iterates through all buckets and deletes all locks, which have no requests on them. More...
|
|
void | dump () const |
| Dumps the contents of all locks to the log. More...
|
|
void | getLockInfoBSON (const std::map< LockerId, BSONObj > &lockToClientMap, BSONObjBuilder *result) |
| Dumps the contents of all locks into a BSON object to be used in lockInfo command in the shell. More...
|
|
◆ LockManager()
mongo::LockManager::LockManager |
( |
| ) |
|
◆ ~LockManager()
mongo::LockManager::~LockManager |
( |
| ) |
|
◆ _buildBucketBSON()
void mongo::LockManager::_buildBucketBSON |
( |
const LockRequest * |
iter, |
|
|
const std::map< LockerId, BSONObj > & |
lockToClientMap, |
|
|
const LockBucket * |
bucket, |
|
|
BSONArrayBuilder * |
locks |
|
) |
| |
|
private |
Build the BSON object containing the lock info for a particular bucket.
The lockToClientMap is used to map the lockerId to more useful client information.
◆ _cleanupUnusedLocksInBucket()
void mongo::LockManager::_cleanupUnusedLocksInBucket |
( |
LockBucket * |
bucket | ) |
|
|
private |
Helper function to delete all locks that have no request on them on a single bucket.
Called by cleanupUnusedLocks()
◆ _dumpBucket()
void mongo::LockManager::_dumpBucket |
( |
const LockBucket * |
bucket | ) |
const |
|
private |
Prints the contents of a bucket to the log.
◆ _dumpBucketToBSON()
void mongo::LockManager::_dumpBucketToBSON |
( |
const std::map< LockerId, BSONObj > & |
lockToClientMap, |
|
|
const LockBucket * |
bucket, |
|
|
BSONObjBuilder * |
result |
|
) |
| |
|
private |
Dump the contents of a bucket to the BSON.
◆ _getBucket()
Retrieves the bucket in which the particular resource must reside.
There is no need to hold a lock when calling this function.
◆ _getPartition()
◆ _onLockModeChanged()
void mongo::LockManager::_onLockModeChanged |
( |
LockHead * |
lock, |
|
|
bool |
checkConflictQueue |
|
) |
| |
|
private |
Should be invoked when the state of a lock changes in a way, which could potentially allow other blocked requests to proceed.
MUST be called under the lock bucket's mutex.
- Parameters
-
lock | Lock whose grant state should be recalculated. |
checkConflictQueue | Whether to go through the conflict queue. This is an optimisation in that we only need to check the conflict queue if one of the granted modes, which was conflicting before became zero. |
◆ cleanupUnusedLocks()
void mongo::LockManager::cleanupUnusedLocks |
( |
| ) |
|
Iterates through all buckets and deletes all locks, which have no requests on them.
This call is kind of expensive and should only be used for reducing the memory footprint of the lock manager.
◆ convert()
◆ downgrade()
Downgrades the mode in which an already granted request is held, without changing the reference count of the lock request.
This call never blocks, will always succeed and may potentially allow other blocked lock requests to proceed.
- Parameters
-
request | Request, already in granted mode through a previous call to lock. |
newMode | Mode, which is less-restrictive than the mode in which the request is already held. I.e., the conflict set of newMode must be a sub-set of the conflict set of the request's current mode. |
◆ dump()
void mongo::LockManager::dump |
( |
| ) |
const |
Dumps the contents of all locks to the log.
◆ getLockInfoBSON()
void mongo::LockManager::getLockInfoBSON |
( |
const std::map< LockerId, BSONObj > & |
lockToClientMap, |
|
|
BSONObjBuilder * |
result |
|
) |
| |
Dumps the contents of all locks into a BSON object to be used in lockInfo command in the shell.
◆ lock()
Acquires lock on the specified resource in the specified mode and returns the outcome of the operation.
See the details for LockResult for more information on what the different results mean.
Locking the same resource twice increments the reference count of the lock so each call to lock must be matched with a call to unlock with the same resource.
- Parameters
-
resId | Id of the resource to be locked. |
request | LockRequest structure on which the state of the request will be tracked. This value cannot be NULL and the notify value must be set. If the return value is not LOCK_WAITING, this pointer can be freed and will not be used any more. |
If the return value is LOCK_WAITING, the notification method will be called at some point into the future, when the lock either becomes granted or a deadlock is discovered. If unlock is called before the lock becomes granted, the notification will not be invoked.
If the return value is LOCK_WAITING, the notification object must live at least until the notify method has been invoked or unlock has been called for the resource it was assigned to. Failure to do so will cause the lock manager to call into an invalid memory location.
- Parameters
-
mode | Mode in which the resource should be locked. Lock upgrades are allowed. |
- Returns
- See comments for LockResult.
◆ MONGO_DISALLOW_COPYING()
mongo::LockManager::MONGO_DISALLOW_COPYING |
( |
LockManager |
| ) |
|
|
private |
◆ unlock()
bool mongo::LockManager::unlock |
( |
LockRequest * |
request | ) |
|
Decrements the reference count of a previously locked request and if the reference count becomes zero, removes the request and proceeds to granting any conflicts.
This method always succeeds and never blocks.
- Parameters
-
request | A previously locked request. Calling unlock more times than lock was called for the same LockRequest is an error. |
- Returns
- true if this is the last reference for the request; false otherwise
◆ DeadlockDetector
◆ LockHead
◆ _lockBuckets
◆ _numLockBuckets
const unsigned mongo::LockManager::_numLockBuckets |
|
staticprivate |
◆ _numPartitions
const unsigned mongo::LockManager::_numPartitions = 32 |
|
staticprivate |
◆ _partitions
The documentation for this class was generated from the following files:
- /home/louis/git/mongodbsource.github.io/src/src/mongo/db/concurrency/lock_manager.h
- /home/louis/git/mongodbsource.github.io/src/src/mongo/db/concurrency/lock_manager.cpp