summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2021-06-15 08:39:29 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-16 14:57:11 +0000
commita616859a60e6cbb40ab0b7ddbeed06e726bd40bc (patch)
tree2ac76456c39994f4d6c585dc3fbedbfa5d8ee589
parent271be23a14c7b66c29c3ae0bf48724ef50d17db8 (diff)
downloadmongo-a616859a60e6cbb40ab0b7ddbeed06e726bd40bc.tar.gz
SERVER-57678 Take MODE_X collection lock when dropping timeseries view.
This is to prevent a concurrent create collection on the same namespace that will reserve an OpTime before the drop.
-rw-r--r--src/mongo/db/catalog/drop_collection.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp
index b11300a566b..5377d433fe2 100644
--- a/src/mongo/db/catalog/drop_collection.cpp
+++ b/src/mongo/db/catalog/drop_collection.cpp
@@ -334,6 +334,13 @@ 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);
auto status = _dropView(opCtx, db, collectionName, reply);
if (!status.isOK()) {
return status;