From d471957fc37ef6cafe9ffeda3e231cdc871c3ce3 Mon Sep 17 00:00:00 2001 From: Daniel Gottlieb Date: Tue, 26 Nov 2019 04:48:50 +0000 Subject: SERVER-43859: Take MODE_IX locks for collection creation. Two concurrent storage transactions can now create collections with the same collection name. These transactions will conflict at commit time; the first committer will win and register their collection into the global catalog. The losing transactions will bubble a WriteConflictException. Top-level callers that should fail if the collection already existed must now check and fail with a NamespaceExists error code. Previously, those callers could rely on lower level code returning the NamespaceExists error. Callers that were implicitly creating a collection may retry the operation, using the now-registered collection. These transaction-local collections (UncommittedCollections) are returned when doing any CollectionCatalog::lookup* call. --- src/mongo/db/dbhelpers.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/mongo/db/dbhelpers.cpp') diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp index 7c1e045f497..e7748aa1e9a 100644 --- a/src/mongo/db/dbhelpers.cpp +++ b/src/mongo/db/dbhelpers.cpp @@ -139,7 +139,7 @@ bool Helpers::findById(OperationContext* opCtx, invariant(database); Collection* collection = - CollectionCatalog::get(opCtx).lookupCollectionByNamespace(NamespaceString(ns)); + CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, NamespaceString(ns)); if (!collection) { return false; } @@ -263,8 +263,9 @@ BSONObj Helpers::inferKeyPattern(const BSONObj& o) { void Helpers::emptyCollection(OperationContext* opCtx, const NamespaceString& nss) { OldClientContext context(opCtx, nss.ns()); repl::UnreplicatedWritesBlock uwb(opCtx); - Collection* collection = - context.db() ? CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss) : nullptr; + Collection* collection = context.db() + ? CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, nss) + : nullptr; deleteObjects(opCtx, collection, nss, BSONObj(), false); } -- cgit v1.2.1