summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2018-11-12 14:28:28 -0500
committerEric Milkie <milkie@10gen.com>2018-11-13 14:04:56 -0500
commitf69f5a743962b6350d5830db0d03aaa4f815acf7 (patch)
treeafa050a3ec035a31970d59b353102c744f491502 /src
parentd58b18005945d6bfc7f6456507e3b1733c245d1c (diff)
downloadmongo-f69f5a743962b6350d5830db0d03aaa4f815acf7.tar.gz
SERVER-37384 lock db prior to examining UUID catalog, to avoid phantom NamespaceNotFound errors
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/catalog_raii.cpp18
-rw-r--r--src/mongo/db/catalog_raii.h4
2 files changed, 7 insertions, 15 deletions
diff --git a/src/mongo/db/catalog_raii.cpp b/src/mongo/db/catalog_raii.cpp
index 339a72655ce..79e4e8e10d4 100644
--- a/src/mongo/db/catalog_raii.cpp
+++ b/src/mongo/db/catalog_raii.cpp
@@ -68,19 +68,11 @@ AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
LockMode modeColl,
ViewMode viewMode,
Date_t deadline)
- : // The UUID to NamespaceString resolution is performed outside of any locks
- _resolvedNss(resolveNamespaceStringOrUUID(opCtx, nsOrUUID)),
- // The database locking is performed based on the resolved NamespaceString
- _autoDb(opCtx, _resolvedNss.db(), modeDB, deadline) {
- // In order to account for possible collection rename happening because the resolution from UUID
- // to NamespaceString was done outside of database lock, if UUID was specified we need to
- // re-resolve the _resolvedNss after acquiring the database lock so it has the correct value.
- //
- // Holding a database lock prevents collection renames, so this guarantees a stable UUID to
- // NamespaceString mapping.
- if (nsOrUUID.uuid())
- _resolvedNss = resolveNamespaceStringOrUUID(opCtx, nsOrUUID);
-
+ : _autoDb(opCtx,
+ !nsOrUUID.dbname().empty() ? nsOrUUID.dbname() : nsOrUUID.nss()->db(),
+ modeDB,
+ deadline),
+ _resolvedNss(resolveNamespaceStringOrUUID(opCtx, nsOrUUID)) {
_collLock.emplace(opCtx->lockState(), _resolvedNss.ns(), modeColl, deadline);
uassertLockTimeout(
str::stream() << "collection " << nsOrUUID.toString(), modeColl, _collLock->isLocked());
diff --git a/src/mongo/db/catalog_raii.h b/src/mongo/db/catalog_raii.h
index 2f2ff984f4f..4bb0a610c44 100644
--- a/src/mongo/db/catalog_raii.h
+++ b/src/mongo/db/catalog_raii.h
@@ -138,12 +138,12 @@ public:
}
private:
+ AutoGetDb _autoDb;
+
// If the object was instantiated with a UUID, contains the resolved namespace, otherwise it is
// the same as the input namespace string
NamespaceString _resolvedNss;
- AutoGetDb _autoDb;
-
// This field is boost::optional, because in the case of lookup by UUID, the collection lock
// might need to be relocked for the correct namespace
boost::optional<Lock::CollectionLock> _collLock;