summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2019-07-12 11:20:33 -0400
committerBenety Goh <benety@mongodb.com>2019-07-12 11:20:47 -0400
commit0009dffe8fff9dc14b9cb31ce11851d916c2484a (patch)
tree24959151b4f03e1bdc0576e95f5b1c23ed0098bc
parent8bf0eddec8a2f5c9a3bfb49162a36a651615534f (diff)
downloadmongo-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.js11
-rw-r--r--src/mongo/db/index_builds_coordinator.cpp7
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) {