diff options
author | Benety Goh <benety@mongodb.com> | 2021-07-12 10:01:45 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-07-23 20:08:03 +0000 |
commit | ec7c30dbec28d9e6afbd9f6adf0cd279618fd315 (patch) | |
tree | a842a7952174c1006748e5571a087134253f1385 | |
parent | 7f22ea97d377da05e6a15422bf802fb0557f3e32 (diff) | |
download | mongo-ec7c30dbec28d9e6afbd9f6adf0cd279618fd315.tar.gz |
SERVER-58280 add base test for handling collMod during initial sync on collections with index buidls
The initial version of this test is identical to initial_sync_aborts_two_phase_index_builds.js.
(cherry picked from commit 7dc0e9f922fc025f8b6e6b7962398b9bd41f9570)
-rw-r--r-- | jstests/noPassthrough/initial_sync_aborts_two_phase_index_builds_hide_index.js | 96 |
1 files changed, 96 insertions, 0 deletions
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..81df8e8f6e4 --- /dev/null +++ b/jstests/noPassthrough/initial_sync_aborts_two_phase_index_builds_hide_index.js @@ -0,0 +1,96 @@ +/** + * 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, + }, + }, + { + // Disallow elections on secondary. + rsConfig: { + priority: 0, + }, + } + ] +}); + +rst.startSet(); +rst.initiate(); + +const primary = rst.getPrimary(); + +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, 23879, {reason: "Aborting 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; +}()); |