diff options
author | Benety Goh <benety@mongodb.com> | 2019-11-07 01:25:42 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-11-07 01:25:42 +0000 |
commit | 7481fc02eb7a321d627e0bc458c9f3305303104f (patch) | |
tree | 68eb7e91c3e2f9c795a2e98d10a3a0c5f389f1d6 | |
parent | 045aa4415cf096c59509c6e6867fe3615f6fd43c (diff) | |
download | mongo-7481fc02eb7a321d627e0bc458c9f3305303104f.tar.gz |
SERVER-44439 add js helper function to check support for two phase index builds
10 files changed, 28 insertions, 44 deletions
diff --git a/jstests/noPassthrough/characterize_index_builds_on_restart.js b/jstests/noPassthrough/characterize_index_builds_on_restart.js index 5b2d104c580..b5520883a4f 100644 --- a/jstests/noPassthrough/characterize_index_builds_on_restart.js +++ b/jstests/noPassthrough/characterize_index_builds_on_restart.js @@ -12,6 +12,7 @@ 'use strict'; load("jstests/libs/check_log.js"); +load('jstests/noPassthrough/libs/index_build.js'); load("jstests/replsets/rslib.js"); const dbName = "testDb"; @@ -88,11 +89,8 @@ function startIndexBuildOnSecondaryAndLeaveUnfinished(primaryDB, writeConcern, s // createIndexes for each index spec. When two phase index builds are in effect, all four // index specs are built using the same builder, so we should expect to see only one fail // point log message instead of four. - const enableTwoPhaseIndexBuild = assert - .commandWorked(primaryDB.adminCommand( - {getParameter: 1, enableTwoPhaseIndexBuild: 1})) - .enableTwoPhaseIndexBuild; - const expectedFailPointMessageCount = enableTwoPhaseIndexBuild ? 1 : 4; + const expectedFailPointMessageCount = + IndexBuildTest.supportsTwoPhaseIndexBuild(primaryDB.getMongo()) ? 1 : 4; // Wait till all index builds hang. checkLog.containsWithCount( diff --git a/jstests/noPassthrough/index_secondary_wait_for_commit.js b/jstests/noPassthrough/index_secondary_wait_for_commit.js index 836e8e9bbb5..f21c2489839 100644 --- a/jstests/noPassthrough/index_secondary_wait_for_commit.js +++ b/jstests/noPassthrough/index_secondary_wait_for_commit.js @@ -32,10 +32,7 @@ const secondary = rst.getSecondary(); const secondaryDB = secondary.getDB(testDB.getName()); const secondaryColl = secondaryDB.getCollection(coll.getName()); -const enableTwoPhaseIndexBuild = - assert.commandWorked(primary.adminCommand({getParameter: 1, enableTwoPhaseIndexBuild: 1})) - .enableTwoPhaseIndexBuild; -if (!enableTwoPhaseIndexBuild) { +if (!IndexBuildTest.supportsTwoPhaseIndexBuild(primary)) { jsTestLog('Two phase index builds not enabled, skipping test.'); rst.stopSet(); return; diff --git a/jstests/noPassthrough/index_stepdown_after_init.js b/jstests/noPassthrough/index_stepdown_after_init.js index a20beef7f00..96ed6619e98 100644 --- a/jstests/noPassthrough/index_stepdown_after_init.js +++ b/jstests/noPassthrough/index_stepdown_after_init.js @@ -52,10 +52,7 @@ IndexBuildTest.waitForIndexBuildToStop(testDB); const exitCode = createIdx({checkExitSuccess: false}); assert.neq(0, exitCode, 'expected shell to exit abnormally due to index build being terminated'); -const enableTwoPhaseIndexBuild = - assert.commandWorked(primary.adminCommand({getParameter: 1, enableTwoPhaseIndexBuild: 1})) - .enableTwoPhaseIndexBuild; -if (!enableTwoPhaseIndexBuild) { +if (!IndexBuildTest.supportsTwoPhaseIndexBuild(primary)) { // Wait for the IndexBuildCoordinator thread, not the command thread, to report the index build // as failed. checkLog.contains(primary, '[IndexBuildsCoordinatorMongod-0] Index build failed: '); diff --git a/jstests/noPassthrough/index_stepdown_during_scan.js b/jstests/noPassthrough/index_stepdown_during_scan.js index 0ddf2c378f7..fa5633dc4c6 100644 --- a/jstests/noPassthrough/index_stepdown_during_scan.js +++ b/jstests/noPassthrough/index_stepdown_during_scan.js @@ -51,10 +51,7 @@ IndexBuildTest.waitForIndexBuildToStop(testDB); const exitCode = createIdx({checkExitSuccess: false}); assert.neq(0, exitCode, 'expected shell to exit abnormally due to index build being terminated'); -const enableTwoPhaseIndexBuild = - assert.commandWorked(primary.adminCommand({getParameter: 1, enableTwoPhaseIndexBuild: 1})) - .enableTwoPhaseIndexBuild; -if (!enableTwoPhaseIndexBuild) { +if (!IndexBuildTest.supportsTwoPhaseIndexBuild(primary)) { // 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_']); diff --git a/jstests/noPassthrough/index_stepdown_failover.js b/jstests/noPassthrough/index_stepdown_failover.js index 09e1a809952..717d07edaec 100644 --- a/jstests/noPassthrough/index_stepdown_failover.js +++ b/jstests/noPassthrough/index_stepdown_failover.js @@ -22,10 +22,7 @@ const primary = rst.getPrimary(); const testDB = primary.getDB('test'); const coll = testDB.getCollection('test'); -const enableTwoPhaseIndexBuild = - assert.commandWorked(primary.adminCommand({getParameter: 1, enableTwoPhaseIndexBuild: 1})) - .enableTwoPhaseIndexBuild; -if (!enableTwoPhaseIndexBuild) { +if (!IndexBuildTest.supportsTwoPhaseIndexBuild(primary)) { jsTestLog('Two phase index builds not enabled, skipping test.'); rst.stopSet(); return; diff --git a/jstests/noPassthrough/libs/index_build.js b/jstests/noPassthrough/libs/index_build.js index 094b0b37a87..975c46209a4 100644 --- a/jstests/noPassthrough/libs/index_build.js +++ b/jstests/noPassthrough/libs/index_build.js @@ -178,4 +178,13 @@ class IndexBuildTest { assert.commandWorked( conn.adminCommand({configureFailPoint: 'hangAfterStartingIndexBuild', mode: 'off'})); } + + /** + * Returns true if two phase index builds are supported. + */ + static supportsTwoPhaseIndexBuild(conn) { + return assert + .commandWorked(conn.adminCommand({getParameter: 1, enableTwoPhaseIndexBuild: 1})) + .enableTwoPhaseIndexBuild; + } } diff --git a/jstests/replsets/apply_ops_create_indexes.js b/jstests/replsets/apply_ops_create_indexes.js index 3ee558acf26..9e5e4c79b92 100644 --- a/jstests/replsets/apply_ops_create_indexes.js +++ b/jstests/replsets/apply_ops_create_indexes.js @@ -4,6 +4,9 @@ */ (function() { "use strict"; + +load('jstests/noPassthrough/libs/index_build.js'); + let ensureIndexExists = function(testDB, collName, indexName, expectedNumIndexes) { let cmd = {listIndexes: collName}; let res = testDB.runCommand(cmd); @@ -35,10 +38,7 @@ let ensureOplogEntryExists = function(localDB, indexName) { // If two phase index builds are enabled, index creation will show up in the oplog as a pair of // startIndexBuild and commitIndexBuild oplog entries rather than a single createIndexes entry. - const enableTwoPhaseIndexBuild = - assert.commandWorked(localDB.adminCommand({getParameter: 1, enableTwoPhaseIndexBuild: 1})) - .enableTwoPhaseIndexBuild; - if (enableTwoPhaseIndexBuild) { + if (IndexBuildTest.supportsTwoPhaseIndexBuild(localDB.getMongo())) { let query = { $and: [{"o.startIndexBuild": {$exists: true}}, {"o.indexes.0.name": indexName}] }; diff --git a/jstests/replsets/oplog_format_create_indexes.js b/jstests/replsets/oplog_format_create_indexes.js index a77da83b168..3fb914aeee4 100644 --- a/jstests/replsets/oplog_format_create_indexes.js +++ b/jstests/replsets/oplog_format_create_indexes.js @@ -6,6 +6,7 @@ "use strict"; load("jstests/libs/get_index_helpers.js"); +load('jstests/noPassthrough/libs/index_build.js'); const rst = new ReplSetTest({nodes: 1}); rst.startSet(); @@ -16,12 +17,6 @@ const primary = rst.getPrimary(); const testDB = primary.getDB("test"); const oplogColl = primary.getDB("local").oplog.rs; -// If two phase index builds are enabled, index creation will show up in the oplog as a pair of -// startIndexBuild and commitIndexBuild oplog entries rather than a single createIndexes entry. -const enableTwoPhaseIndexBuild = - assert.commandWorked(testDB.adminCommand({getParameter: 1, enableTwoPhaseIndexBuild: 1})) - .enableTwoPhaseIndexBuild; - function testOplogEntryContainsIndexInfoObj(coll, keyPattern, indexOptions) { assert.commandWorked(coll.createIndex(keyPattern, indexOptions)); const allIndexes = coll.getIndexes(); @@ -32,8 +27,9 @@ function testOplogEntryContainsIndexInfoObj(coll, keyPattern, indexOptions) { indexSpec, "Index with key pattern " + tojson(keyPattern) + " not found: " + tojson(allIndexes)); - // Find the createIndexes command entries. - const indexCreationOplogQuery = enableTwoPhaseIndexBuild + // If two phase index builds are enabled, index creation will show up in the oplog as a pair of + // startIndexBuild and commitIndexBuild oplog entries rather than a single createIndexes entry. + const indexCreationOplogQuery = IndexBuildTest.supportsTwoPhaseIndexBuild(primary) ? {op: "c", ns: testDB.getName() + ".$cmd", "o.startIndexBuild": coll.getName()} : {op: "c", ns: testDB.getName() + ".$cmd", "o.createIndexes": coll.getName()}; diff --git a/jstests/replsets/reconstruct_prepared_transactions_initial_sync_index_build.js b/jstests/replsets/reconstruct_prepared_transactions_initial_sync_index_build.js index ce5c06e2496..606495c00fd 100644 --- a/jstests/replsets/reconstruct_prepared_transactions_initial_sync_index_build.js +++ b/jstests/replsets/reconstruct_prepared_transactions_initial_sync_index_build.js @@ -70,10 +70,7 @@ jsTestLog("Running operations while collection cloning is paused"); // the oplog application stage of initial sync. assert.commandWorked(testColl.insert({_id: 1, a: 1})); -const enableTwoPhaseIndexBuild = - assert.commandWorked(primary.adminCommand({getParameter: 1, enableTwoPhaseIndexBuild: 1})) - .enableTwoPhaseIndexBuild; -if (!enableTwoPhaseIndexBuild) { +if (!IndexBuildTest.supportsTwoPhaseIndexBuild(primary)) { // Make the index build hang on the secondary so that initial sync gets to the prepared-txn // reconstruct stage with the index build still running. jsTest.log("Hanging index build on the secondary node"); @@ -112,7 +109,7 @@ assert.commandWorked(secondary.adminCommand( {configureFailPoint: "initialSyncHangDuringCollectionClone", mode: "off"})); // Unblock index build. -if (!enableTwoPhaseIndexBuild) { +if (!IndexBuildTest.supportsTwoPhaseIndexBuild(primary)) { // Wait for log message. assert.soon( () => rawMongoProgramOutput().indexOf( diff --git a/jstests/replsets/secondary_as_sync_source.js b/jstests/replsets/secondary_as_sync_source.js index 8e29d8bb28a..269105280d4 100644 --- a/jstests/replsets/secondary_as_sync_source.js +++ b/jstests/replsets/secondary_as_sync_source.js @@ -46,14 +46,10 @@ let secondaryDB = secondary.getDB(dbName); addTestDocuments(primaryDB); -const enableTwoPhaseIndexBuild = - assert.commandWorked(primary.adminCommand({getParameter: 1, enableTwoPhaseIndexBuild: 1})) - .enableTwoPhaseIndexBuild; - // Used to wait for two-phase builds to complete. let awaitIndex; -if (!enableTwoPhaseIndexBuild) { +if (!IndexBuildTest.supportsTwoPhaseIndexBuild(primary)) { jsTest.log("Hanging index build on the secondary node"); IndexBuildTest.pauseIndexBuilds(secondary); @@ -87,7 +83,7 @@ replSet.reInitiate(); waitForState(newNode, ReplSetTest.State.SECONDARY); jsTest.log("Removing index build hang to allow it to finish"); -if (!enableTwoPhaseIndexBuild) { +if (!IndexBuildTest.supportsTwoPhaseIndexBuild(primary)) { // Let the 'secondary' finish its index build. IndexBuildTest.resumeIndexBuilds(secondary); } else { |