summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2021-07-12 10:01:45 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-08-09 21:43:25 +0000
commit58fb882fea697627e40a8d5cca9a34785c3e9659 (patch)
tree1a523a849f94b90d4ef202d5e47d02c74e3d37d0
parentedd5982ae7352a920d835ddae1433540e640eead (diff)
downloadmongo-58fb882fea697627e40a8d5cca9a34785c3e9659.tar.gz
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)
-rw-r--r--jstests/noPassthrough/initial_sync_aborts_two_phase_index_builds_hide_index.js97
1 files changed, 97 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..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;
+}());