summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2019-07-11 17:34:16 -0400
committerBenety Goh <benety@mongodb.com>2019-07-11 17:35:25 -0400
commit96f983169f2217dea3336f45df6bd59aef3a0714 (patch)
tree8dde21a2e47b6be0dd1463e7fc8812277371ee59
parent8c51287e54f87d0a32e5d1eb59bb94af16917011 (diff)
downloadmongo-96f983169f2217dea3336f45df6bd59aef3a0714.tar.gz
SERVER-42154 add js test to step down before index build begins collection scan
-rw-r--r--jstests/noPassthrough/index_stepdown_after_init.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/jstests/noPassthrough/index_stepdown_after_init.js b/jstests/noPassthrough/index_stepdown_after_init.js
new file mode 100644
index 00000000000..0b5eccc27d8
--- /dev/null
+++ b/jstests/noPassthrough/index_stepdown_after_init.js
@@ -0,0 +1,71 @@
+/**
+ * Confirms that background index builds on a primary are aborted when the node steps down between
+ * the initialization and collection scan phases.
+ * @tags: [requires_replication]
+ */
+(function() {
+ "use strict";
+
+ load('jstests/libs/check_log.js');
+ load('jstests/noPassthrough/libs/index_build.js');
+
+ const rst = new ReplSetTest({
+ nodes: [
+ {},
+ {
+ // Disallow elections on secondary.
+ rsConfig: {
+ priority: 0,
+ votes: 0,
+ },
+ },
+ ]
+ });
+ const nodes = rst.startSet();
+ rst.initiate();
+
+ const primary = rst.getPrimary();
+ const testDB = primary.getDB('test');
+ const coll = testDB.getCollection('test');
+
+ const enableIndexBuildsCoordinator =
+ assert
+ .commandWorked(primary.adminCommand(
+ {getParameter: 1, enableIndexBuildsCoordinatorForCreateIndexesCommand: 1}))
+ .enableIndexBuildsCoordinatorForCreateIndexesCommand;
+ if (!enableIndexBuildsCoordinator) {
+ jsTestLog(
+ 'IndexBuildsCoordinator not enabled for index creation on primary, skipping test.');
+ rst.stopSet();
+ return;
+ }
+
+ assert.writeOK(coll.insert({a: 1}));
+
+ assert.commandWorked(primary.adminCommand(
+ {configureFailPoint: 'hangAfterInitializingIndexBuild', mode: 'alwaysOn'}));
+
+ const createIdx = IndexBuildTest.startIndexBuild(primary, coll.getFullName(), {a: 1});
+
+ checkLog.contains(
+ primary,
+ 'index build: starting on ' + coll.getFullName() + ' properties: { v: 2, key: { a:');
+
+ try {
+ // Step down the primary.
+ assert.commandWorked(primary.adminCommand({replSetStepDown: 60, force: true}));
+ } finally {
+ assert.commandWorked(primary.adminCommand(
+ {configureFailPoint: 'hangAfterInitializingIndexBuild', mode: 'off'}));
+ }
+
+ 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.');
+
+ rst.stopSet();
+})();