diff options
author | Pavi Vetriselvan <pavithra.vetriselvan@mongodb.com> | 2021-09-22 17:18:31 -0400 |
---|---|---|
committer | Pavi Vetriselvan <pavithra.vetriselvan@mongodb.com> | 2021-09-22 17:18:31 -0400 |
commit | 2d9a6ac51c9331841d159f88ffa5759c6f108639 (patch) | |
tree | 72a4a5b437018d8bc4b4def65684c71e1005c549 | |
parent | ea575e9768e5df64d3855b1392abb180c734387f (diff) | |
download | mongo-pvselvan/SERVER-59934.tar.gz |
Always take a MODE_X lock when dropping viewspvselvan/SERVER-59934
-rw-r--r-- | src/mongo/db/catalog/drop_collection.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp index 932b6145757..bb087d0bf8d 100644 --- a/src/mongo/db/catalog/drop_collection.cpp +++ b/src/mongo/db/catalog/drop_collection.cpp @@ -87,7 +87,9 @@ 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); + // 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 collLock(opCtx, collectionName, MODE_X); // Operations all lock system.views in the end to prevent deadlock. Lock::CollectionLock systemViewsLock(opCtx, db->getSystemViewsName(), MODE_X); @@ -332,13 +334,9 @@ Status _dropCollection(OperationContext* opCtx, [opCtx, dropView, &collectionName, &reply](Database* db, const NamespaceString& bucketsNs) { if (dropView) { - // Take a MODE_X lock when dropping timeseries view. This is to prevent - // a concurrent create collection on the same namespace that will - // reserve an OpTime before this drop. We already hold a MODE_X lock on - // the bucket collection inside '_abortIndexBuildsAndDrop' above. When - // taking both these locks it needs to happen in this order to prevent a - // deadlock. - Lock::CollectionLock viewLock(opCtx, collectionName, MODE_X); + // We already hold a MODE_X lock on the bucket collection inside + // '_abortIndexBuildsAndDrop' above. Taking that MODE_X lock on the + // view must happen after in order to prevent a deadlock. auto status = _dropView(opCtx, db, collectionName, reply); if (!status.isOK()) { return status; |