summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2020-03-05 13:08:59 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-06 14:05:40 +0000
commit0d8dbe14d81b9f3d6db3628b10cd6340787d1567 (patch)
tree3c744c885d436a964a5c629254e31cfdcd49ec03 /src/mongo
parent0fe66fac5c3f64ced0ab8897fac62c218a2ab0bb (diff)
downloadmongo-0d8dbe14d81b9f3d6db3628b10cd6340787d1567.tar.gz
SERVER-46647 Stepping down the primary when running 'dropDatabase' can hit an invariant due to yielded locks
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/catalog/drop_database.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/mongo/db/catalog/drop_database.cpp b/src/mongo/db/catalog/drop_database.cpp
index 64681932fd1..823343c641c 100644
--- a/src/mongo/db/catalog/drop_database.cpp
+++ b/src/mongo/db/catalog/drop_database.cpp
@@ -180,6 +180,18 @@ Status _dropDatabase(OperationContext* opCtx, const std::string& dbName, bool ab
indexBuildsCoord->abortDatabaseIndexBuildsNoWait(
opCtx, dbName, "dropDatabase command");
+ // Create a scope guard to reset the drop-pending state on the database to false if
+ // there is a replica state change that kills this operation while the locks were
+ // yielded.
+ auto dropPendingGuardWhileUnlocked = makeGuard([dbName, opCtx, &dropPendingGuard] {
+ UninterruptibleLockGuard noInterrupt(opCtx->lockState());
+ AutoGetDb autoDB(opCtx, dbName, MODE_IX);
+ if (auto db = autoDB.getDb()) {
+ db->setDropPending(opCtx, false);
+ }
+ dropPendingGuard.dismiss();
+ });
+
// Now that the abort signals were sent out to the active index builders for this
// database, we need to release the lock temporarily to allow those index builders
// to process the abort signal. Holding a lock here will cause the index builders to
@@ -197,6 +209,8 @@ Status _dropDatabase(OperationContext* opCtx, const std::string& dbName, bool ab
autoDB.emplace(opCtx, dbName, MODE_X);
db = autoDB->getDb();
+ dropPendingGuardWhileUnlocked.dismiss();
+
// Abandon the snapshot as the index catalog will compare the in-memory state to the
// disk state, which may have changed when we released the collection lock
// temporarily.