summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2021-01-29 14:57:59 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-02-01 18:07:43 +0000
commit645b608b8ba2488dc28a88532852fef8f7b9854b (patch)
tree9dc78febaa888ed7ee1b0d38e31c2c354201298f
parentf952f10948d21b0fc588837d8937b0d04330c353 (diff)
downloadmongo-645b608b8ba2488dc28a88532852fef8f7b9854b.tar.gz
SERVER-54126 buildindexes*.js should not assume commitQuorum is always accepted
-rw-r--r--jstests/noPassthrough/libs/index_build.js6
-rw-r--r--jstests/replsets/buildindexes.js25
-rw-r--r--jstests/replsets/buildindexes_false_commit_quorum.js60
3 files changed, 59 insertions, 32 deletions
diff --git a/jstests/noPassthrough/libs/index_build.js b/jstests/noPassthrough/libs/index_build.js
index e67cc602bf9..113a8478cc0 100644
--- a/jstests/noPassthrough/libs/index_build.js
+++ b/jstests/noPassthrough/libs/index_build.js
@@ -217,4 +217,10 @@ var IndexBuildTest = class {
.commandWorked(conn.adminCommand({getParameter: 1, enableIndexBuildCommitQuorum: 1}))
.enableIndexBuildCommitQuorum;
}
+
+ static twoPhaseIndexBuildEnabled(conn) {
+ return assert
+ .commandWorked(conn.adminCommand({getParameter: 1, enableTwoPhaseIndexBuild: 1}))
+ .enableTwoPhaseIndexBuild;
+ }
};
diff --git a/jstests/replsets/buildindexes.js b/jstests/replsets/buildindexes.js
index f6e8c755a9b..23379a9618f 100644
--- a/jstests/replsets/buildindexes.js
+++ b/jstests/replsets/buildindexes.js
@@ -4,6 +4,9 @@
// ]
(function() {
+
+load('jstests/noPassthrough/libs/index_build.js');
+
// Skip db hash check because secondary will have different number of indexes due to
// buildIndexes=false on the secondary.
TestData.skipCheckDBHashes = true;
@@ -29,13 +32,21 @@ for (var i in slaveConns) {
}
replTest.awaitReplication();
-// Need to use a commitQuorum of 2 rather than the default of 'votingMembers', which includes the
-// buildIndexes:false node. The index build will otherwise fail early.
-assert.commandWorked(master.runCommand({
- createIndexes: 'x',
- indexes: [{key: {y: 1}, name: 'y_1'}],
- commitQuorum: 2,
-}));
+if (IndexBuildTest.twoPhaseIndexBuildEnabled(master) &&
+ IndexBuildTest.indexBuildCommitQuorumEnabled(master)) {
+ // Need to use a commitQuorum of 2 rather than the default of 'votingMembers', which includes
+ // the buildIndexes:false node. The index build will otherwise fail early.
+ assert.commandWorked(master.runCommand({
+ createIndexes: 'x',
+ indexes: [{key: {y: 1}, name: 'y_1'}],
+ commitQuorum: 2,
+ }));
+} else {
+ assert.commandWorked(master.runCommand({
+ createIndexes: 'x',
+ indexes: [{key: {y: 1}, name: 'y_1'}],
+ }));
+}
for (i = 0; i < 100; i++) {
master.x.insert({x: 1, y: "abc", c: 1});
diff --git a/jstests/replsets/buildindexes_false_commit_quorum.js b/jstests/replsets/buildindexes_false_commit_quorum.js
index 2f3aa70a1ee..d044ae7d5f4 100644
--- a/jstests/replsets/buildindexes_false_commit_quorum.js
+++ b/jstests/replsets/buildindexes_false_commit_quorum.js
@@ -29,7 +29,8 @@ replTest.initiate();
const dbName = "buildIndexes";
const collName = "test";
-const primaryDb = replTest.getPrimary().getDB(dbName);
+const primary = replTest.getPrimary();
+const primaryDb = primary.getDB(dbName);
// Ensure the collection is populated. Index builds on empty collection circumvent the two-phase
// index build machinery, and we want to exercise that in this test.
@@ -37,31 +38,40 @@ for (let i = 0; i < 100; i++) {
primaryDb[collName].insert({x: 1, y: "abc", c: 1});
}
-// The default commit quorum is 'votingMembers', and this index build should fail early because the
-// voting buildIndexes:false node will never build the index.
-assert.commandFailedWithCode(primaryDb.runCommand({
- createIndexes: collName,
- indexes: [{key: {y: 1}, name: 'y_1_default_commitQuorum'}],
-}),
- ErrorCodes.UnsatisfiableCommitQuorum);
+let indexName;
+if (IndexBuildTest.twoPhaseIndexBuildEnabled(primary) &&
+ IndexBuildTest.indexBuildCommitQuorumEnabled(primary)) {
+ // The default commit quorum is 'votingMembers', and this index build should fail early because
+ // the voting buildIndexes:false node will never build the index.
+ assert.commandFailedWithCode(primaryDb.runCommand({
+ createIndexes: collName,
+ indexes: [{key: {y: 1}, name: 'y_1_default_commitQuorum'}],
+ }),
+ ErrorCodes.UnsatisfiableCommitQuorum);
-// With a commit quorum that includes all nodes, the quorum is unsatisfiable for the same reason as
-// 'votingMembers'.
-assert.commandFailedWithCode(primaryDb.runCommand({
- createIndexes: collName,
- indexes: [{key: {y: 1}, name: 'y_1_commitQuorum_3'}],
- commitQuorum: 3,
-}),
- ErrorCodes.UnsatisfiableCommitQuorum);
-
-// This commit quorum does not need to include the buildIndexes:false node so it should be
-// satisfiable.
-const indexName = 'y_1_commitQuorum_majority';
-assert.commandWorked(primaryDb.runCommand({
- createIndexes: collName,
- indexes: [{key: {y: 1}, name: indexName}],
- commitQuorum: 'majority',
-}));
+ // With a commit quorum that includes all nodes, the quorum is unsatisfiable for the same reason
+ // as 'votingMembers'.
+ assert.commandFailedWithCode(primaryDb.runCommand({
+ createIndexes: collName,
+ indexes: [{key: {y: 1}, name: 'y_1_commitQuorum_3'}],
+ commitQuorum: 3,
+ }),
+ ErrorCodes.UnsatisfiableCommitQuorum);
+ // This commit quorum does not need to include the buildIndexes:false node so it should be
+ // satisfiable.
+ indexName = 'y_1_commitQuorum_majority';
+ assert.commandWorked(primaryDb.runCommand({
+ createIndexes: collName,
+ indexes: [{key: {y: 1}, name: indexName}],
+ commitQuorum: 'majority',
+ }));
+} else {
+ indexName = 'y_1';
+ assert.commandWorked(primaryDb.runCommand({
+ createIndexes: collName,
+ indexes: [{key: {y: 1}, name: indexName}],
+ }));
+}
replTest.awaitReplication();