summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuganthi Mani <suganthi.mani@mongodb.com>2020-02-04 22:01:44 +0000
committerevergreen <evergreen@mongodb.com>2020-02-04 22:01:44 +0000
commit6bcdb9197f45c6791740cf696f9174974b114ecd (patch)
treee3e72bf693a0a6c91353ae5a2a3b2f4e8c5a45d8
parent7fa0a642fa7e99740b83e61040b01498dfb889eb (diff)
downloadmongo-6bcdb9197f45c6791740cf696f9174974b114ecd.tar.gz
SERVER-39532 standalones doesn't support commitQuorum.
-rw-r--r--jstests/noPassthrough/commit_quorum_standalones.js19
-rw-r--r--src/mongo/db/commands/create_indexes.cpp6
2 files changed, 24 insertions, 1 deletions
diff --git a/jstests/noPassthrough/commit_quorum_standalones.js b/jstests/noPassthrough/commit_quorum_standalones.js
new file mode 100644
index 00000000000..2be7fa95e7c
--- /dev/null
+++ b/jstests/noPassthrough/commit_quorum_standalones.js
@@ -0,0 +1,19 @@
+/**
+ * Test that commitQuorum option is not supported on standalones for index creation.
+ * Note: noPassthrough/commit_quorum.js - Verifies the commitQuorum behavior for replica sets.
+ */
+
+(function() {
+'use strict';
+
+const standalone = MongoRunner.runMongod();
+const db = standalone.getDB("test");
+
+jsTestLog("Create index");
+assert.commandFailedWithCode(
+ db.runCommand(
+ {createIndexes: "coll", indexes: [{name: "x_1", key: {x: 1}}], commitQuorum: "majority"}),
+ ErrorCodes.BadValue);
+
+MongoRunner.stopMongod(standalone);
+})();
diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp
index b534acba487..adb56fa19e2 100644
--- a/src/mongo/db/commands/create_indexes.cpp
+++ b/src/mongo/db/commands/create_indexes.cpp
@@ -274,14 +274,18 @@ Status validateTTLOptions(OperationContext* opCtx, const BSONObj& cmdObj) {
*/
boost::optional<CommitQuorumOptions> parseAndGetCommitQuorum(OperationContext* opCtx,
const BSONObj& cmdObj) {
+ auto replCoord = repl::ReplicationCoordinator::get(opCtx);
+
if (cmdObj.hasField(kCommitQuorumFieldName)) {
+ uassert(ErrorCodes::BadValue,
+ str::stream() << "Standalones can't specify commitQuorum",
+ replCoord->isReplEnabled());
CommitQuorumOptions commitQuorum;
uassertStatusOK(commitQuorum.parse(cmdObj.getField(kCommitQuorumFieldName)));
return commitQuorum;
} else {
// Retrieve the default commit quorum if one wasn't passed in, which consists of all
// data-bearing nodes.
- auto replCoord = repl::ReplicationCoordinator::get(opCtx);
int numDataBearingMembers =
replCoord->isReplEnabled() ? replCoord->getConfig().getNumDataBearingMembers() : 1;
return CommitQuorumOptions(numDataBearingMembers);