summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun Verch <shaun.verch@mongodb.com>2014-03-28 10:43:58 -0400
committerShaun Verch <shaun.verch@mongodb.com>2014-03-28 13:46:54 -0400
commit3fe346dedc89c9d154b1de30d497ae0caa529ecc (patch)
tree367a5b64960ebd55740eca50e0a75bef91978160
parent8d7e71c8c07ff15ece15d5494a77ed42fc309f11 (diff)
downloadmongo-3fe346dedc89c9d154b1de30d497ae0caa529ecc.tar.gz
SERVER-13379 Ensure replication.replSet overrides replication.replSetName
-rw-r--r--jstests/libs/config_files/set_replsetname.json5
-rw-r--r--jstests/repl/repl_options.js67
-rw-r--r--src/mongo/db/mongod_options.cpp53
3 files changed, 97 insertions, 28 deletions
diff --git a/jstests/libs/config_files/set_replsetname.json b/jstests/libs/config_files/set_replsetname.json
new file mode 100644
index 00000000000..522ca2b766f
--- /dev/null
+++ b/jstests/libs/config_files/set_replsetname.json
@@ -0,0 +1,5 @@
+{
+ "replication" : {
+ "replSetName" : "myconfigname"
+ }
+}
diff --git a/jstests/repl/repl_options.js b/jstests/repl/repl_options.js
new file mode 100644
index 00000000000..42787048eb4
--- /dev/null
+++ b/jstests/repl/repl_options.js
@@ -0,0 +1,67 @@
+var baseName = "jstests_repl_repl_options";
+
+function removeOptionsAddedByFramework(getCmdLineOptsResult) {
+ // Remove options that we are not interested in checking, but that get set by the test
+ delete getCmdLineOptsResult.parsed.setParameter
+ delete getCmdLineOptsResult.parsed.storage
+ delete getCmdLineOptsResult.parsed.net
+ delete getCmdLineOptsResult.parsed.fastsync
+ delete getCmdLineOptsResult.parsed.security
+ return getCmdLineOptsResult;
+}
+
+function testGetCmdLineOpts(mongoRunnerConfig, expectedResult) {
+
+ // Start mongod with options
+ var mongod = MongoRunner.runMongod(mongoRunnerConfig);
+
+ // Get the parsed options
+ var getCmdLineOptsResult = mongod.adminCommand("getCmdLineOpts");
+ printjson(getCmdLineOptsResult);
+
+ // Remove options added by the test framework
+ getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
+
+ // Make sure the options are equal to what we expect
+ assert.docEq(getCmdLineOptsResult.parsed, expectedResult.parsed);
+
+ // Cleanup
+ MongoRunner.stopMongod(mongod.port);
+}
+
+jsTest.log("Testing \"replSet\" command line option");
+var expectedResult = {
+ "parsed" : {
+ "replication" : {
+ "replSet" : "mycmdlinename"
+ }
+ }
+};
+testGetCmdLineOpts({ replSet : "mycmdlinename" }, expectedResult);
+
+jsTest.log("Testing \"replication.replSetName\" config file option");
+expectedResult = {
+ "parsed" : {
+ "config" : "jstests/libs/config_files/set_replsetname.json",
+ "replication" : {
+ "replSetName" : "myconfigname"
+ }
+ }
+};
+testGetCmdLineOpts({ config : "jstests/libs/config_files/set_replsetname.json" }, expectedResult);
+
+jsTest.log("Testing override of \"replication.replSetName\" config file option with \"replSet\"");
+expectedResult = {
+ "parsed" : {
+ "config" : "jstests/libs/config_files/set_replsetname.json",
+ "replication" : {
+ "replSet" : "mycmdlinename"
+ }
+ }
+};
+testGetCmdLineOpts({ config : "jstests/libs/config_files/set_replsetname.json",
+ replSet : "mycmdlinename" }, expectedResult);
+
+
+
+print(baseName + " succeeded.");
diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp
index a1b6829262d..f79c1715278 100644
--- a/src/mongo/db/mongod_options.cpp
+++ b/src/mongo/db/mongod_options.cpp
@@ -288,25 +288,37 @@ namespace mongo {
// Master Slave Options
ms_options.addOptionChaining("master", "master", moe::Switch, "master mode")
+ .incompatibleWith("replication.replSet")
+ .incompatibleWith("replication.replSetName")
.setSources(moe::SourceAllLegacy);
ms_options.addOptionChaining("slave", "slave", moe::Switch, "slave mode")
+ .incompatibleWith("replication.replSet")
+ .incompatibleWith("replication.replSetName")
.setSources(moe::SourceAllLegacy);
ms_options.addOptionChaining("source", "source", moe::String,
"when slave: specify master as <server:port>")
+ .incompatibleWith("replication.replSet")
+ .incompatibleWith("replication.replSetName")
.setSources(moe::SourceAllLegacy);
ms_options.addOptionChaining("only", "only", moe::String,
"when slave: specify a single database to replicate")
+ .incompatibleWith("replication.replSet")
+ .incompatibleWith("replication.replSetName")
.setSources(moe::SourceAllLegacy);
ms_options.addOptionChaining("slavedelay", "slavedelay", moe::Int,
"specify delay (in seconds) to be used when applying master ops to slave")
+ .incompatibleWith("replication.replSet")
+ .incompatibleWith("replication.replSetName")
.setSources(moe::SourceAllLegacy);
ms_options.addOptionChaining("autoresync", "autoresync", moe::Switch,
"automatically resync if slave data is stale")
+ .incompatibleWith("replication.replSet")
+ .incompatibleWith("replication.replSetName")
.setSources(moe::SourceAllLegacy);
// Replication Options
@@ -317,13 +329,11 @@ namespace mongo {
rs_options.addOptionChaining("replication.replSet", "replSet", moe::String,
"arg is <setname>[/<optionalseedhostlist>]")
- .setSources(moe::SourceAllLegacy)
- .incompatibleWith("replication.replSetName");
+ .setSources(moe::SourceAllLegacy);
rs_options.addOptionChaining("replication.replSetName", "", moe::String, "arg is <setname>")
.setSources(moe::SourceYAMLConfig)
- .format("[^/]+", "[replica set name with no \"/\"]")
- .incompatibleWith("replication.replSet");
+ .format("[^/]+", "[replica set name with no \"/\"]");
rs_options.addOptionChaining("replication.secondaryIndexPrefetch", "replIndexPrefetch", moe::String,
"specify index prefetching behavior (if secondary) [none|_id_only|all]")
@@ -753,6 +763,17 @@ namespace mongo {
}
}
+ // Ensure that "replication.replSet" logically overrides "replication.replSetName". We
+ // can't canonicalize them as the same option, because they mean slightly different things.
+ // "replication.replSet" can include a seed list, while "replication.replSetName" just has
+ // the replica set name.
+ if (params->count("replication.replSet") && params->count("replication.replSetName")) {
+ ret = params->remove("replication.replSetName");
+ if (!ret.isOK()) {
+ return ret;
+ }
+ }
+
return Status::OK();
}
@@ -941,16 +962,6 @@ namespace mongo {
}
if (params.count("autoresync")) {
replSettings.autoresync = true;
- if( params.count("replication.replSet") ) {
- return Status(ErrorCodes::BadValue,
- "--autoresync is not used with --replSet\nsee "
- "http://dochub.mongodb.org/core/resyncingaverystalereplicasetmember");
- }
- if( params.count("replication.replSetName") ) {
- return Status(ErrorCodes::BadValue,
- "--autoresync is not used with replication.replSetName\nsee "
- "http://dochub.mongodb.org/core/resyncingaverystalereplicasetmember");
- }
}
if (params.count("source")) {
/* specifies what the source in local.sources should be */
@@ -960,23 +971,9 @@ namespace mongo {
replSettings.pretouch = params["pretouch"].as<int>();
}
if (params.count("replication.replSetName")) {
- if (params.count("slavedelay")) {
- return Status(ErrorCodes::BadValue,
- "--slavedelay cannot be used with replication.replSetName");
- }
- else if (params.count("only")) {
- return Status(ErrorCodes::BadValue,
- "--only cannot be used with replication.replSetName");
- }
replSettings.replSet = params["replication.replSetName"].as<string>().c_str();
}
if (params.count("replication.replSet")) {
- if (params.count("slavedelay")) {
- return Status(ErrorCodes::BadValue, "--slavedelay cannot be used with --replSet");
- }
- else if (params.count("only")) {
- return Status(ErrorCodes::BadValue, "--only cannot be used with --replSet");
- }
/* seed list of hosts for the repl set */
replSettings.replSet = params["replication.replSet"].as<string>().c_str();
}