diff options
author | Pavi Vetriselvan <pavithra.vetriselvan@mongodb.com> | 2021-09-29 17:31:46 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-09-29 17:57:24 +0000 |
commit | 45bc7a2c06d788a2fddc8601450d4a1fb8dbf489 (patch) | |
tree | 34dcb0d5f0491442c7c2c0397a9064eb7b466039 | |
parent | 45041b9e5aece67df50f549d67df2ff8f5fcce3e (diff) | |
download | mongo-45bc7a2c06d788a2fddc8601450d4a1fb8dbf489.tar.gz |
SERVER-59934 Take a MODE_X collection lock when dropping regular views
-rw-r--r-- | src/mongo/db/catalog/drop_collection.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp index 932b6145757..3475a499248 100644 --- a/src/mongo/db/catalog/drop_collection.cpp +++ b/src/mongo/db/catalog/drop_collection.cpp @@ -87,7 +87,6 @@ Status _dropView(OperationContext* opCtx, // Validates the view or throws an "invalid view" error. ViewCatalog::get(db)->lookup(opCtx, collectionName); - Lock::CollectionLock collLock(opCtx, collectionName, MODE_IX); // Operations all lock system.views in the end to prevent deadlock. Lock::CollectionLock systemViewsLock(opCtx, db->getSystemViewsName(), MODE_X); @@ -378,6 +377,9 @@ Status _dropCollection(OperationContext* opCtx, return dropTimeseries(view->viewOn(), true); } + // Take a MODE_X lock when dropping a view. This is to prevent a concurrent create + // collection on the same namespace that will reserve an OpTime before this drop. + Lock::CollectionLock viewLock(opCtx, collectionName, MODE_X); return _dropView(opCtx, db, collectionName, reply); }); } catch (ExceptionFor<ErrorCodes::NamespaceNotFound>&) { @@ -456,6 +458,7 @@ Status dropCollectionForApplyOps(OperationContext* opCtx, DropReply unusedReply; if (!coll) { + Lock::CollectionLock viewLock(opCtx, collectionName, MODE_IX); return _dropView(opCtx, db, collectionName, &unusedReply); } else { return _dropCollectionForApplyOps( |