diff options
author | Benety Goh <benety@mongodb.com> | 2019-07-12 11:20:33 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2019-07-12 11:20:47 -0400 |
commit | 0009dffe8fff9dc14b9cb31ce11851d916c2484a (patch) | |
tree | 24959151b4f03e1bdc0576e95f5b1c23ed0098bc | |
parent | 8bf0eddec8a2f5c9a3bfb49162a36a651615534f (diff) | |
download | mongo-0009dffe8fff9dc14b9cb31ce11851d916c2484a.tar.gz |
SERVER-42154 IndexBuildsCoordinator uses repl state info provided by caller
This affects index builds managed by the IndexBuildsCoordinator on primaries and mitigates
changes in the replication state observed since the start of the index build that may affect
how the index build handles interruptions and errors.
-rw-r--r-- | jstests/noPassthrough/index_stepdown_after_init.js | 11 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator.cpp | 7 |
2 files changed, 12 insertions, 6 deletions
diff --git a/jstests/noPassthrough/index_stepdown_after_init.js b/jstests/noPassthrough/index_stepdown_after_init.js index 0b5eccc27d8..c27df900ce0 100644 --- a/jstests/noPassthrough/index_stepdown_after_init.js +++ b/jstests/noPassthrough/index_stepdown_after_init.js @@ -59,13 +59,18 @@ {configureFailPoint: 'hangAfterInitializingIndexBuild', mode: 'off'})); } + // Wait for the index build to stop. + IndexBuildTest.waitForIndexBuildToStop(testDB); + const exitCode = createIdx({checkExitSuccess: false}); assert.neq( 0, exitCode, 'expected shell to exit abnormally due to index build being terminated'); - rst.stop(primary, undefined, {allowedExitCode: MongoRunner.EXIT_ABORT}); - assert(rawMongoProgramOutput().match('Fatal assertion 51101 IndexBuildAborted: Index build: '), - 'Index build should have aborted on step down.'); + checkLog.contains(primary, 'IndexBuildAborted: Index build aborted: '); + + // Check that no new index has been created. This verifies that the index build was aborted + // rather than successfully completed. + IndexBuildTest.assertIndexes(coll, 1, ['_id_']); rst.stopSet(); })(); diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp index 7bb6004d42b..542677d9ce8 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -761,9 +761,10 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx, str::stream() << "Collection " << *nss << " should exist because an index build is in progress."); - auto replCoord = repl::ReplicationCoordinator::get(opCtx); - auto replSetAndNotPrimary = replCoord->getSettings().usingReplSets() && - !replCoord->canAcceptWritesForDatabase(opCtx, replState->dbName); + // TODO(SERVER-39484): Since 'replSetAndNotPrimary' is derived from the replication state at the + // start of the index build, this value is not resilient to member state changes like + // stepup/stepdown. + auto replSetAndNotPrimary = indexBuildOptions.replSetAndNotPrimary; try { if (replSetAndNotPrimary) { |