diff options
-rw-r--r-- | jstests/libs/command_line/test_parsed_options.js | 12 | ||||
-rw-r--r-- | jstests/sharding/sharding_options.js | 6 | ||||
-rw-r--r-- | src/mongo/db/mongod_options.cpp | 8 |
3 files changed, 26 insertions, 0 deletions
diff --git a/jstests/libs/command_line/test_parsed_options.js b/jstests/libs/command_line/test_parsed_options.js index 50e2733c520..5c32f3a8774 100644 --- a/jstests/libs/command_line/test_parsed_options.js +++ b/jstests/libs/command_line/test_parsed_options.js @@ -204,3 +204,15 @@ function testGetCmdLineOptsMongos(mongoRunnerConfig, expectedResult) { // Make sure the options are equal to what we expect assert.docEq(getCmdLineOptsResult.parsed, expectedResult.parsed); } + +// Tests that the passed configuration will not run a new mongod instances. Mainly used to test +// conflicting parameters at startup. +// +// Arguments: +// mongoRunnerConfig - Configuration object to pass to the mongo runner +// Example: +// +// testGetCmdLineOptsMongodFailed({ shardsvr : "" }); +function testGetCmdLineOptsMongodFailed(mongoRunnerConfig) { + assert.throws(() => MongoRunner.runMongod(mongoRunnerConfig)); +}
\ No newline at end of file diff --git a/jstests/sharding/sharding_options.js b/jstests/sharding/sharding_options.js index a26731aabc7..1ba6bc5844a 100644 --- a/jstests/sharding/sharding_options.js +++ b/jstests/sharding/sharding_options.js @@ -86,4 +86,10 @@ expectedResult = { testGetCmdLineOptsMongod({config: "jstests/libs/config_files/disable_nomoveparanoia.ini"}, expectedResult); +jsTest.log("Ensure starting a standalone with --shardsvr fails"); +testGetCmdLineOptsMongodFailed({shardsvr: ""}); + +jsTest.log("Ensure starting a standalone with --configsvr fails"); +testGetCmdLineOptsMongodFailed({configsvr: ""}); + print(baseName + " succeeded."); diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp index 881f83c1abc..12e369d5e11 100644 --- a/src/mongo/db/mongod_options.cpp +++ b/src/mongo/db/mongod_options.cpp @@ -603,6 +603,14 @@ Status storeMongodOptions(const moe::Environment& params) { } if (params.count("sharding.clusterRole")) { auto clusterRoleParam = params["sharding.clusterRole"].as<std::string>(); + // Force to set up the node as a replica set, unless we're using queryable backup mode. + if (!params.count("storage.queryableBackupMode") && !params.count("replication.replSet") && + !params.count("replication.replSetName")) { + return Status(ErrorCodes::BadValue, + str::stream() << "Cannot start a " << clusterRoleParam + << " as a standalone server. Please use the option " + "--replset to start the node as a replica set."); + } if (clusterRoleParam == "configsvr") { serverGlobalParams.clusterRole = ClusterRole::ConfigServer; // Config server requires majority read concern. |