diff options
author | Benety Goh <benety@mongodb.com> | 2019-07-22 12:18:34 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2019-07-22 12:18:47 -0400 |
commit | 121972781acf4a5db3cc26e6151044954d612574 (patch) | |
tree | 8f641a89b8b88d0729438d2e131cfa0e0bca6f9f | |
parent | ca5fd3f9a99ac1bba3bbeecf8bc8b819368b0a6a (diff) | |
download | mongo-121972781acf4a5db3cc26e6151044954d612574.tar.gz |
SERVER-42281 IndexBuildsCoordinator::_runIndexBuildInner() cleans up index build if lock acquisition fails
-rw-r--r-- | src/mongo/db/index_builds_coordinator.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp index 58b9f38c9f6..52025d39fb8 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -735,12 +735,11 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx, // Set up the thread's currentOp information to display createIndexes cmd information. _updateCurOpOpDescription(opCtx, *nss, replState->indexSpecs); - AutoGetDb autoDb(opCtx, nss->db(), MODE_IX); + boost::optional<AutoGetDb> autoDb; // Do not use AutoGetCollection since the lock will be in various modes throughout the index // build. boost::optional<Lock::CollectionLock> collLock; - collLock.emplace(opCtx, *nss, MODE_X); auto collection = CollectionCatalog::get(opCtx).lookupCollectionByUUID(replState->collectionUUID); @@ -755,6 +754,10 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx, auto replSetAndNotPrimary = indexBuildOptions.replSetAndNotPrimary; try { + // Acquire locks here to ensure that we clean up the index build. + autoDb.emplace(opCtx, nss->db(), MODE_IX); + collLock.emplace(opCtx, *nss, MODE_X); + if (replSetAndNotPrimary) { // This index build can only be interrupted at shutdown. For the duration of the // OperationContext::runWithoutInterruptionExceptAtGlobalShutdown() invocation, any kill |