From 58fb882fea697627e40a8d5cca9a34785c3e9659 Mon Sep 17 00:00:00 2001 From: Benety Goh Date: Mon, 12 Jul 2021 10:01:45 -0400 Subject: SERVER-58280 add base test for handling collMod during initial sync on collections with index builds The initial version of this test is identical to initial_sync_aborts_two_phase_index_builds.js. (cherry picked from commit 7dc0e9f922fc025f8b6e6b7962398b9bd41f9570) --- ...ync_aborts_two_phase_index_builds_hide_index.js | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 jstests/noPassthrough/initial_sync_aborts_two_phase_index_builds_hide_index.js diff --git a/jstests/noPassthrough/initial_sync_aborts_two_phase_index_builds_hide_index.js b/jstests/noPassthrough/initial_sync_aborts_two_phase_index_builds_hide_index.js new file mode 100644 index 00000000000..000f72410a9 --- /dev/null +++ b/jstests/noPassthrough/initial_sync_aborts_two_phase_index_builds_hide_index.js @@ -0,0 +1,97 @@ +/** + * Verifies that an initial syncing node can abort in-progress two phase index builds during the + * oplog replay phase. + * + * @tags: [requires_replication] + */ +(function() { +"use strict"; + +load("jstests/noPassthrough/libs/index_build.js"); + +const dbName = jsTest.name(); +const collName = "test"; + +const rst = new ReplSetTest({ + nodes: [ + {}, + { + // Disallow elections on secondary. + rsConfig: { + priority: 0, + }, + }, + ] +}); + +rst.startSet(); +rst.initiate(); + +const primary = rst.getPrimary(); + +if (!(IndexBuildTest.supportsTwoPhaseIndexBuild(primary) && + IndexBuildTest.indexBuildCommitQuorumEnabled(primary))) { + jsTestLog( + 'Skipping test because two phase index build and index build commit quorum are not supported.'); + rst.stopSet(); + return; +} + +const db = primary.getDB(dbName); +const coll = db.getCollection(collName); + +assert.commandWorked(coll.insert({a: 1})); +assert.commandWorked(coll.createIndex({a: 1}, {}, "votingMembers")); +rst.awaitReplication(); + +// Forcefully re-sync the secondary. +let secondary = rst.restart(1, { + startClean: true, + setParameter: { + 'failpoint.initialSyncHangDuringCollectionClone': tojson( + {mode: 'alwaysOn', data: {namespace: "admin.system.version", numDocsToClone: 0}}), + } +}); + +// Wait until we block on cloning 'admin.system.version'. +checkLog.containsJson(secondary, 21138); + +assert.commandWorked(coll.insert({a: 2})); +assert.commandWorked(coll.dropIndex({a: 1})); + +IndexBuildTest.pauseIndexBuilds(secondary); + +// Start an index build on the primary, so that when initial sync is cloning the user collection it +// sees an in-progress two phase index build. +TestData.dbName = dbName; +TestData.collName = collName; +const awaitIndexBuild = startParallelShell(() => { + const coll = db.getSiblingDB(TestData.dbName).getCollection(TestData.collName); + assert.commandWorked(coll.createIndex({a: 1}, {}, "votingMembers")); +}, primary.port); + +IndexBuildTest.waitForIndexBuildToStart(db, collName, "a_1"); + +assert.commandWorked(secondary.adminCommand( + {configureFailPoint: "initialSyncHangDuringCollectionClone", mode: "off"})); + +rst.awaitReplication(); +rst.awaitSecondaryNodes(); + +// Check the that secondary hit the background operation in progress error. +checkLog.containsJson( + secondary, 5500800, {reason: "Aborting two phase index builds during initial sync"}); + +IndexBuildTest.resumeIndexBuilds(secondary); + +awaitIndexBuild(); + +let indexes = secondary.getDB(dbName).getCollection(collName).getIndexes(); +assert.eq(2, indexes.length); + +indexes = coll.getIndexes(); +assert.eq(2, indexes.length); + +rst.stopSet(); +return; +}()); -- cgit v1.2.1