From 69ef3ed5cf4ac634fd7a749f9428871ec6f40fd2 Mon Sep 17 00:00:00 2001 From: Benety Goh Date: Thu, 10 Oct 2019 12:55:41 +0000 Subject: SERVER-43639 fix tests to support two phase index builds --- jstests/noPassthrough/indexbg_shutdown.js | 4 +++- jstests/noPassthrough/list_indexes_with_build_uuids.js | 13 ++++++++----- jstests/noPassthrough/timestamp_index_builds.js | 8 +++++--- .../indexbg_restart_secondary_noretry.js | 9 +++++++-- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/jstests/noPassthrough/indexbg_shutdown.js b/jstests/noPassthrough/indexbg_shutdown.js index 7907780140c..ae7d1f3c3e6 100644 --- a/jstests/noPassthrough/indexbg_shutdown.js +++ b/jstests/noPassthrough/indexbg_shutdown.js @@ -65,7 +65,6 @@ const indexSpecs = [ assert.commandWorked(masterDB.runCommand({ createIndexes: collection, indexes: indexSpecs, - writeConcern: {w: 2}, })); const indexes = masterColl.getIndexes(); // Number of indexes passed to createIndexes plus one for the _id index. @@ -87,6 +86,9 @@ checkLog.containsWithCount( jsTest.log("Restarting secondary to retry replication"); // Secondary should restart cleanly. +assert.commandWorked(second.adminCommand( + {configureFailPoint: 'leaveIndexBuildUnfinishedForShutdown', mode: 'alwaysOn'})); +IndexBuildTest.resumeIndexBuilds(second); replTest.restart(secondaryId, {}, /*wait=*/true); // There should again be a message for each index we tried to create, because the server diff --git a/jstests/noPassthrough/list_indexes_with_build_uuids.js b/jstests/noPassthrough/list_indexes_with_build_uuids.js index 102f6560c1e..938ffa67a76 100644 --- a/jstests/noPassthrough/list_indexes_with_build_uuids.js +++ b/jstests/noPassthrough/list_indexes_with_build_uuids.js @@ -6,6 +6,8 @@ (function() { 'use strict'; +load('jstests/noPassthrough/libs/index_build.js'); + const dbName = "test"; const collName = "coll"; @@ -49,16 +51,18 @@ assert.commandWorked(primaryDB.runCommand( replSet.waitForAllIndexBuildsToFinish(dbName, collName); // Start hanging index builds on the secondary. -assert.commandWorked(secondaryDB.adminCommand( - {configureFailPoint: "hangAfterStartingIndexBuild", mode: "alwaysOn"})); +IndexBuildTest.pauseIndexBuilds(secondary); // Build and hang on the second index. assert.commandWorked(primaryDB.runCommand({ createIndexes: collName, indexes: [{key: {j: 1}, name: secondIndexName, background: true}], - writeConcern: {w: 2} })); +// Wait for index builds to start on the secondary. +const opId = IndexBuildTest.waitForIndexBuildToStart(secondaryDB); +jsTestLog('Index builds started on secondary. Op ID of one of the builds: ' + opId); + // Check the listIndexes() output. let res = secondaryDB.runCommand({listIndexes: collName, includeBuildUUIDs: true}); @@ -74,8 +78,7 @@ assert.eq(indexes[2].spec.name, "second"); assert(indexes[2].hasOwnProperty("buildUUID")); // Allow the secondary to finish the index build. -assert.commandWorked( - secondaryDB.adminCommand({configureFailPoint: "hangAfterStartingIndexBuild", mode: "off"})); +IndexBuildTest.resumeIndexBuilds(secondary); replSet.stopSet(); }()); diff --git a/jstests/noPassthrough/timestamp_index_builds.js b/jstests/noPassthrough/timestamp_index_builds.js index 7b0613bfff0..5296dc44d8f 100644 --- a/jstests/noPassthrough/timestamp_index_builds.js +++ b/jstests/noPassthrough/timestamp_index_builds.js @@ -25,6 +25,8 @@ (function() { "use strict"; +load('jstests/noPassthrough/libs/index_build.js'); + const rst = new ReplSetTest({ name: "timestampingIndexBuilds", nodes: 2, @@ -74,7 +76,7 @@ for (let nodeIdx = 0; nodeIdx < 2; ++nodeIdx) { nodeIdentity); let conn = rst.start(nodeIdx, {noReplSet: true, noCleanData: true}); assert.neq(null, conn, "failed to restart node"); - assert.eq(1, getColl(conn).getIndexes().length); + IndexBuildTest.assertIndexes(getColl(conn), 1, ['_id_']); rst.stop(nodeIdx); } @@ -84,7 +86,7 @@ for (let nodeIdx = 0; nodeIdx < 2; ++nodeIdx) { jsTestLog("Starting as a replica set. Both indexes should exist. Node: " + nodeIdentity); let conn = rst.start(nodeIdx, {startClean: false}, true); conn.setSlaveOk(); - assert.eq(2, getColl(conn).getIndexes().length); + IndexBuildTest.assertIndexes(getColl(conn), 2, ['_id_', 'foo_1']); rst.stop(nodeIdx); } @@ -95,7 +97,7 @@ for (let nodeIdx = 0; nodeIdx < 2; ++nodeIdx) { nodeIdentity); let conn = rst.start(nodeIdx, {noReplSet: true, noCleanData: true}); assert.neq(null, conn, "failed to restart node"); - assert.eq(1, getColl(conn).getIndexes().length); + IndexBuildTest.assertIndexes(getColl(conn), 1, ['_id_']); rst.stop(nodeIdx); } } diff --git a/jstests/noPassthroughWithMongod/indexbg_restart_secondary_noretry.js b/jstests/noPassthroughWithMongod/indexbg_restart_secondary_noretry.js index 19fbb4b4879..9de2404e836 100644 --- a/jstests/noPassthroughWithMongod/indexbg_restart_secondary_noretry.js +++ b/jstests/noPassthroughWithMongod/indexbg_restart_secondary_noretry.js @@ -2,9 +2,14 @@ * Starts a replica set, builds an index in background. Kills the secondary with a failpoint once * the index build starts. It should *not* build an index on the secondary on restart due to * `--noIndexBuildRetry` option being supplied. + * + * @tags: [ + * requires_persistence, + * requires_journaling, + * requires_replication, + * two_phase_index_builds_unsupported, + * ] */ - -// @tags: [requires_persistence, requires_journaling, requires_replication] (function() { 'use strict'; -- cgit v1.2.1