diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2022-03-17 19:12:11 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-04-07 15:07:03 +0000 |
commit | 9f581fbeec8157a0e083f6b50c791c979f957556 (patch) | |
tree | b0d1dd65e7674a4c94afad9f7dc0cf2465eafa43 | |
parent | 319d8d8145fb5893ab3bf5d077730226f3f2af7c (diff) | |
download | mongo-9f581fbeec8157a0e083f6b50c791c979f957556.tar.gz |
SERVER-64554 the abortIndexBuild oplog entry drops unfinished indexes when run with --recoverFromOplogAsStandalone
(cherry picked from commit 52e9dc623220c1467b075cca141eb4113e792117)
-rw-r--r-- | src/mongo/db/index_builds_coordinator.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp index e3fb2e9aa01..c37a7c2c7a1 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -854,8 +854,39 @@ void IndexBuildsCoordinator::applyAbortIndexBuild(OperationContext* opCtx, std::string abortReason(str::stream() << "abortIndexBuild oplog entry encountered: " << *oplogEntry.cause); auto indexBuildsCoord = IndexBuildsCoordinator::get(opCtx); - indexBuildsCoord->abortIndexBuildByBuildUUID( - opCtx, buildUUID, IndexBuildAction::kOplogAbort, abortReason); + if (indexBuildsCoord->abortIndexBuildByBuildUUID( + opCtx, buildUUID, IndexBuildAction::kOplogAbort, abortReason)) { + return; + } + + auto replCoord = repl::ReplicationCoordinator::get(opCtx); + if (replCoord->getSettings().shouldRecoverFromOplogAsStandalone()) { + // Unfinished index builds are not restarted in standalone mode. That means there will be no + // index builder threads to abort. Instead, we should drop the unfinished indexes that were + // aborted. + AutoGetCollection autoColl{opCtx, nss, MODE_X}; + auto coll = autoColl.getCollection(); + + WriteUnitOfWork wuow(opCtx); + + auto indexCatalog = coll->getIndexCatalog(); + for (const auto& indexSpec : oplogEntry.indexSpecs) { + const IndexDescriptor* desc = indexCatalog->findIndexByName( + opCtx, + indexSpec.getStringField(IndexDescriptor::kIndexNameFieldName), + /*includeUnfinishedIndexes=*/true); + + LOGV2(6455400, + "Dropping unfinished index during oplog recovery as standalone", + "spec"_attr = indexSpec); + + invariant(desc); + invariant(indexCatalog->dropUnfinishedIndex(opCtx, desc)); + } + + wuow.commit(); + return; + } } boost::optional<UUID> IndexBuildsCoordinator::abortIndexBuildByIndexNames( |