diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2022-09-16 12:36:06 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-09-16 20:30:14 +0000 |
commit | ec54f761d043e56cf484de864a89c3645223f878 (patch) | |
tree | 5aad7f6538a91d276d0b5314b82c7bcca0e20c30 /src/mongo/db/concurrency | |
parent | eb5d4ed00d889306f061428f5652431301feba8e (diff) | |
download | mongo-ec54f761d043e56cf484de864a89c3645223f878.tar.gz |
SERVER-67383 Use `CollectionNamespaceOrUUIDLock` to lock collections via UUID
Diffstat (limited to 'src/mongo/db/concurrency')
-rw-r--r-- | src/mongo/db/concurrency/d_concurrency.cpp | 45 | ||||
-rw-r--r-- | src/mongo/db/concurrency/d_concurrency.h | 4 |
2 files changed, 6 insertions, 43 deletions
diff --git a/src/mongo/db/concurrency/d_concurrency.cpp b/src/mongo/db/concurrency/d_concurrency.cpp index a678e49bbb0..f46c09d636e 100644 --- a/src/mongo/db/concurrency/d_concurrency.cpp +++ b/src/mongo/db/concurrency/d_concurrency.cpp @@ -33,7 +33,6 @@ #include <string> #include <vector> -#include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/concurrency/flow_control_ticketholder.h" #include "mongo/db/namespace_string.h" #include "mongo/db/service_context.h" @@ -246,49 +245,15 @@ Lock::DBLock::~DBLock() { } Lock::CollectionLock::CollectionLock(OperationContext* opCtx, - const NamespaceStringOrUUID& nssOrUUID, + const NamespaceString& ns, LockMode mode, Date_t deadline) - : _opCtx(opCtx) { - if (nssOrUUID.nss()) { - auto& nss = *nssOrUUID.nss(); - _id = {RESOURCE_COLLECTION, nss}; - - invariant(nss.coll().size(), str::stream() << "expected non-empty collection name:" << nss); - dassert(_opCtx->lockState()->isDbLockedForMode(nss.dbName(), - isSharedLockMode(mode) ? MODE_IS : MODE_IX)); - - _opCtx->lockState()->lock(_opCtx, _id, mode, deadline); - return; - } - - // 'nsOrUUID' must be a UUID and dbName. - - auto nss = CollectionCatalog::get(opCtx)->resolveNamespaceStringOrUUID(opCtx, nssOrUUID); - - // The UUID cannot move between databases so this one dassert is sufficient. - dassert(_opCtx->lockState()->isDbLockedForMode(nss.dbName(), + : _id(RESOURCE_COLLECTION, ns), _opCtx(opCtx) { + invariant(!ns.coll().empty()); + dassert(_opCtx->lockState()->isDbLockedForMode(ns.dbName(), isSharedLockMode(mode) ? MODE_IS : MODE_IX)); - // We cannot be sure that the namespace we lock matches the UUID given because we resolve the - // namespace from the UUID without the safety of a lock. Therefore, we will continue to re-lock - // until the namespace we resolve from the UUID before and after taking the lock is the same. - bool locked = false; - NamespaceString prevResolvedNss; - do { - if (locked) { - _opCtx->lockState()->unlock(_id); - } - - _id = ResourceId(RESOURCE_COLLECTION, nss); - _opCtx->lockState()->lock(_opCtx, _id, mode, deadline); - locked = true; - - // We looked up UUID without a collection lock so it's possible that the - // collection name changed now. Look it up again. - prevResolvedNss = nss; - nss = CollectionCatalog::get(opCtx)->resolveNamespaceStringOrUUID(opCtx, nssOrUUID); - } while (nss != prevResolvedNss); + _opCtx->lockState()->lock(_opCtx, _id, mode, deadline); } Lock::CollectionLock::CollectionLock(CollectionLock&& otherLock) diff --git a/src/mongo/db/concurrency/d_concurrency.h b/src/mongo/db/concurrency/d_concurrency.h index b999c6103da..2d4b5b6d6a8 100644 --- a/src/mongo/db/concurrency/d_concurrency.h +++ b/src/mongo/db/concurrency/d_concurrency.h @@ -37,8 +37,6 @@ namespace mongo { -class NamespaceStringOrUUID; - class Lock { public: /** @@ -350,7 +348,7 @@ public: public: CollectionLock(OperationContext* opCtx, - const NamespaceStringOrUUID& nssOrUUID, + const NamespaceString& ns, LockMode mode, Date_t deadline = Date_t::max()); |