diff options
author | Louis Williams <louis.williams@mongodb.com> | 2019-11-21 22:36:46 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-11-21 22:36:46 +0000 |
commit | 300458bb1ed89940649560e92ff84c81a4a77678 (patch) | |
tree | 88f1e90d56f9d67b3335d7162a123d40b3d05996 /jstests/noPassthroughWithMongod | |
parent | 92d0ebf34f39f82f430869273ae751c1d97ec960 (diff) | |
download | mongo-300458bb1ed89940649560e92ff84c81a4a77678.tar.gz |
SERVER-44467 Implement startup recovery for two-phase index builds
Diffstat (limited to 'jstests/noPassthroughWithMongod')
-rw-r--r-- | jstests/noPassthroughWithMongod/indexbg_restart_secondary.js | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/jstests/noPassthroughWithMongod/indexbg_restart_secondary.js b/jstests/noPassthroughWithMongod/indexbg_restart_secondary.js index e12973b7ff8..462236d8c63 100644 --- a/jstests/noPassthroughWithMongod/indexbg_restart_secondary.js +++ b/jstests/noPassthroughWithMongod/indexbg_restart_secondary.js @@ -3,20 +3,18 @@ * Kills the secondary once the index build starts with a failpoint. * The index build should resume when the secondary is restarted. * - * TODO: (SERVER-44467) Remove two_phase_index_builds_unsupported tag when startup recovery works - * for two-phase index builds. - * * @tags: [ * requires_persistence, * requires_journaling, * requires_replication, - * two_phase_index_builds_unsupported, * ] */ (function() { 'use strict'; +load('jstests/noPassthrough/libs/index_build.js'); + // Set up replica set var replTest = new ReplSetTest({name: 'bgIndex', nodes: 3}); var nodes = replTest.nodeList(); @@ -57,19 +55,31 @@ replTest.awaitReplication(); assert.commandWorked(secondDB.adminCommand( {configureFailPoint: 'leaveIndexBuildUnfinishedForShutdown', mode: 'alwaysOn'})); + try { - coll.createIndex({i: 1}, {background: true}); - masterDB.getLastError(2); - assert.eq(2, coll.getIndexes().length); - - // Make sure all writes are durable on the secondary so that we can restart it knowing that - // the index build will be found on startup. - // Waiting for durable is important for both (A) the record that we started the index build - // so it is rebuild on restart, and (B) the update to minvalid to show that we've already - // applied the oplog entry so it isn't replayed. If (A) is present without (B), then there - // are two ways that the index can be rebuilt on startup and this test is only for the one - // triggered by (A). - secondDB.adminCommand({fsync: 1}); + if (IndexBuildTest.supportsTwoPhaseIndexBuild(master)) { + // Pause the index build on the secondary to wait for it to start. + IndexBuildTest.pauseIndexBuilds(secondDB); + IndexBuildTest.startIndexBuild(master, coll.getFullName(), {i: 1}); + + // Wait for build to start on the secondary. + jsTestLog("waiting for index build to start on secondary"); + IndexBuildTest.waitForIndexBuildToStart(secondDB); + IndexBuildTest.resumeIndexBuilds(secondDB); + } else { + coll.createIndex({i: 1}, {background: true}); + masterDB.getLastError(2); + assert.eq(2, coll.getIndexes().length); + + // Make sure all writes are durable on the secondary so that we can restart it knowing that + // the index build will be found on startup. + // Waiting for durable is important for both (A) the record that we started the index build + // so it is rebuild on restart, and (B) the update to minvalid to show that we've already + // applied the oplog entry so it isn't replayed. If (A) is present without (B), then there + // are two ways that the index can be rebuilt on startup and this test is only for the one + // triggered by (A). + secondDB.adminCommand({fsync: 1}); + } } finally { assert.commandWorked(secondDB.adminCommand( {configureFailPoint: 'leaveIndexBuildUnfinishedForShutdown', mode: 'off'})); |