summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEsha Maharishi <esha.maharishi@mongodb.com>2017-11-27 17:17:17 -0500
committerEsha Maharishi <esha.maharishi@mongodb.com>2017-12-05 13:48:04 -0500
commiteda6982ae8f5ebac140cb2420210776828cae947 (patch)
treea1e533720e03d69ebe42f74ac1be0be110d9ff2e
parent18851f31bbee892d558680536894968efa72feb7 (diff)
downloadmongo-eda6982ae8f5ebac140cb2420210776828cae947.tar.gz
SERVER-32105 Require shard servers and config servers to be started with --replSet or 'replSetName'
-rw-r--r--jstests/libs/config_files/set_shardingrole_configsvr.json (renamed from jstests/libs/config_files/set_shardingrole.json)3
-rw-r--r--jstests/libs/config_files/set_shardingrole_shardsvr.json8
-rw-r--r--jstests/sharding/require_shardsvrs_and_configsvrs_to_be_replica_sets.js62
-rw-r--r--jstests/sharding/shard_config_db_collections.js2
-rw-r--r--jstests/sharding/sharding_options.js18
-rw-r--r--src/mongo/db/SConscript1
-rw-r--r--src/mongo/db/mongod_options.cpp26
7 files changed, 110 insertions, 10 deletions
diff --git a/jstests/libs/config_files/set_shardingrole.json b/jstests/libs/config_files/set_shardingrole_configsvr.json
index 71f92f122db..f6121cfd52b 100644
--- a/jstests/libs/config_files/set_shardingrole.json
+++ b/jstests/libs/config_files/set_shardingrole_configsvr.json
@@ -1,5 +1,8 @@
{
"sharding" : {
"clusterRole" : "configsvr"
+ },
+ "replication": {
+ "replSetName" : "dummy"
}
}
diff --git a/jstests/libs/config_files/set_shardingrole_shardsvr.json b/jstests/libs/config_files/set_shardingrole_shardsvr.json
new file mode 100644
index 00000000000..333a33528b9
--- /dev/null
+++ b/jstests/libs/config_files/set_shardingrole_shardsvr.json
@@ -0,0 +1,8 @@
+{
+ "sharding" : {
+ "clusterRole" : "shardsvr"
+ },
+ "replication" : {
+ "replSetName" : "dummy"
+ }
+}
diff --git a/jstests/sharding/require_shardsvrs_and_configsvrs_to_be_replica_sets.js b/jstests/sharding/require_shardsvrs_and_configsvrs_to_be_replica_sets.js
new file mode 100644
index 00000000000..5157a8ac12d
--- /dev/null
+++ b/jstests/sharding/require_shardsvrs_and_configsvrs_to_be_replica_sets.js
@@ -0,0 +1,62 @@
+/**
+ * Ensures that a server started with --shardsvr or --configsvr must also be started as a replica
+ * set, unless it is started with enableTestCommands=1.
+ */
+(function() {
+ var testAllPermutations = function(enableTestCommands) {
+ jsTest.setOption('enableTestCommands', enableTestCommands);
+ var mongod;
+
+ // Standalone tests.
+
+ jsTest.log("Starting shardsvr with enableTestCommands=" + enableTestCommands);
+ mongod = MongoRunner.runMongod({shardsvr: ''});
+ if (enableTestCommands) {
+ assert.neq(null, mongod);
+ MongoRunner.stopMongod(mongod);
+ } else {
+ assert.eq(null, mongod);
+ }
+
+ jsTest.log("Starting configsvr with enableTestCommands=" + enableTestCommands);
+ mongod = MongoRunner.runMongod({configsvr: ''});
+ if (enableTestCommands) {
+ assert.neq(null, mongod);
+ MongoRunner.stopMongod(mongod);
+ } else {
+ assert.eq(null, mongod);
+ }
+
+ // Replica set tests using the command line 'replSet' option.
+
+ jsTest.log("Starting shardsvr with --replSet and enableTestCommands=" + enableTestCommands);
+ mongod = MongoRunner.runMongod({shardsvr: '', replSet: 'dummy'});
+ assert.neq(null, mongod);
+ MongoRunner.stopMongod(mongod);
+
+ jsTest.log("Starting configsvr with --replSet and enableTestCommands=" +
+ enableTestCommands);
+ mongod = MongoRunner.runMongod({configsvr: '', replSet: 'dummy'});
+ assert.neq(null, mongod);
+ MongoRunner.stopMongod(mongod);
+
+ // Replica set tests using the config file 'replSetName' option.
+
+ jsTest.log("Starting shardsvr with 'replication.replSetName' and enableTestCommands=" +
+ enableTestCommands);
+ mongod = MongoRunner.runMongod(
+ {config: "jstests/libs/config_files/set_shardingrole_shardsvr.json"});
+ assert.neq(null, mongod);
+ MongoRunner.stopMongod(mongod);
+
+ jsTest.log("Starting configsvr with 'replication.replSetName' and enableTestCommands=" +
+ enableTestCommands);
+ mongod = MongoRunner.runMongod(
+ {config: "jstests/libs/config_files/set_shardingrole_configsvr.json"});
+ assert.neq(null, mongod);
+ MongoRunner.stopMongod(mongod);
+ };
+
+ testAllPermutations(true /* enableTestCommands */);
+ testAllPermutations(false /* enableTestCommands */);
+})();
diff --git a/jstests/sharding/shard_config_db_collections.js b/jstests/sharding/shard_config_db_collections.js
index d666f3c8d43..68f78f6bf94 100644
--- a/jstests/sharding/shard_config_db_collections.js
+++ b/jstests/sharding/shard_config_db_collections.js
@@ -148,7 +148,7 @@
{
jsTest.setOption('enableTestCommands', false);
- var st = new ShardingTest({shards: 2});
+ var st = new ShardingTest({shards: 2, rs: true});
var admin = st.s.getDB('admin');
assert.commandWorked(
diff --git a/jstests/sharding/sharding_options.js b/jstests/sharding/sharding_options.js
index 8af7bf01c53..8d6c63335b7 100644
--- a/jstests/sharding/sharding_options.js
+++ b/jstests/sharding/sharding_options.js
@@ -37,14 +37,26 @@ expectedResult = {
};
testGetCmdLineOptsMongod({shardsvr: ""}, expectedResult);
-jsTest.log("Testing \"sharding.clusterRole\" config file option");
+jsTest.log("Testing \"sharding.clusterRole\" config file option with 'configsvr'");
expectedResult = {
"parsed": {
- "config": "jstests/libs/config_files/set_shardingrole.json",
+ "config": "jstests/libs/config_files/set_shardingrole_configsvr.json",
+ "replication": {"replSetName": "dummy"},
"sharding": {"clusterRole": "configsvr"}
}
};
-testGetCmdLineOptsMongod({config: "jstests/libs/config_files/set_shardingrole.json"},
+testGetCmdLineOptsMongod({config: "jstests/libs/config_files/set_shardingrole_configsvr.json"},
+ expectedResult);
+
+jsTest.log("Testing \"sharding.clusterRole\" config file option with 'shardsvr'");
+expectedResult = {
+ "parsed": {
+ "config": "jstests/libs/config_files/set_shardingrole_shardsvr.json",
+ "replication": {"replSetName": "dummy"},
+ "sharding": {"clusterRole": "shardsvr"}
+ }
+};
+testGetCmdLineOptsMongod({config: "jstests/libs/config_files/set_shardingrole_shardsvr.json"},
expectedResult);
// Test that we preserve switches explicitly set to false in config files. See SERVER-13439.
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index ea3c3797310..45b2c134b87 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -414,6 +414,7 @@ env.Library(
],
LIBDEPS=[
'$BUILD_DIR/mongo/db/storage/mmap_v1/mmap_v1_options',
+ 'commands/test_commands_enabled',
'repl/repl_settings',
'server_options',
'storage/storage_options',
diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp
index 4360c0e155b..c0648eaf105 100644
--- a/src/mongo/db/mongod_options.cpp
+++ b/src/mongo/db/mongod_options.cpp
@@ -449,11 +449,12 @@ Status addMongodOptions(moe::OptionSection* options) {
// Sharding Options
sharding_options
- .addOptionChaining("configsvr",
- "configsvr",
- moe::Switch,
- "declare this is a config db of a cluster; default port 27019; "
- "default dir /data/configdb")
+ .addOptionChaining(
+ "configsvr",
+ "configsvr",
+ moe::Switch,
+ "declare this is a config db of a cluster; default port 27019; "
+ "default dir /data/configdb; requires starting this server as a replica set")
.setSources(moe::SourceAllLegacy)
.incompatibleWith("shardsvr")
.incompatibleWith("nojournal");
@@ -462,7 +463,8 @@ Status addMongodOptions(moe::OptionSection* options) {
.addOptionChaining("shardsvr",
"shardsvr",
moe::Switch,
- "declare this is a shard db of a cluster; default port 27018")
+ "declare this is a shard db of a cluster; default port 27018; requires "
+ "starting this server as a replica set")
.setSources(moe::SourceAllLegacy)
.incompatibleWith("configsvr")
.incompatibleWith("master")
@@ -1198,6 +1200,18 @@ Status storeMongodOptions(const moe::Environment& params) {
}
if (params.count("sharding.clusterRole")) {
auto clusterRoleParam = params["sharding.clusterRole"].as<std::string>();
+
+ if (!(params.count("replication.replSet") || params.count("replication.replSetName")) &&
+ !Command::testCommandsEnabled) {
+ return {
+ ErrorCodes::InvalidOptions,
+ str::stream()
+ << "Cannot start a "
+ << clusterRoleParam
+ << " as a standalone server. Please start this node as a replica "
+ "set using --replSet or the config file option replication.replSetName."};
+ }
+
if (clusterRoleParam == "configsvr") {
serverGlobalParams.clusterRole = ClusterRole::ConfigServer;