summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMisha Tyulenev <misha@mongodb.com>2018-01-21 15:25:24 -0500
committerMisha Tyulenev <misha@mongodb.com>2018-01-29 17:50:57 -0500
commit1b8cce46314746e106445896d70ca1611ab97ca3 (patch)
tree15ecb26e4e78ea4856611b96083b5a47c86b5710
parentfdb19a9d6b00a617ed86a33c7d2c5c3244204c1d (diff)
downloadmongo-1b8cce46314746e106445896d70ca1611ab97ca3.tar.gz
SERVER-32569 allow config servers and shard replica sets to start in non-cluster mode
-rw-r--r--jstests/noPassthrough/skip_sharding_configuration_checks.js55
-rw-r--r--src/mongo/db/SConscript1
-rw-r--r--src/mongo/db/mongod_options.cpp17
-rw-r--r--src/mongo/db/mongod_options.h2
-rw-r--r--src/mongo/db/repl/SConscript4
-rw-r--r--src/mongo/db/repl/replica_set_config.cpp14
-rw-r--r--src/mongo/db/repl/topology_coordinator_impl.cpp8
-rw-r--r--src/mongo/shell/replsettest.js13
-rw-r--r--src/mongo/shell/shardingtest.js6
9 files changed, 108 insertions, 12 deletions
diff --git a/jstests/noPassthrough/skip_sharding_configuration_checks.js b/jstests/noPassthrough/skip_sharding_configuration_checks.js
new file mode 100644
index 00000000000..d2a6651084d
--- /dev/null
+++ b/jstests/noPassthrough/skip_sharding_configuration_checks.js
@@ -0,0 +1,55 @@
+/**
+ * Starts standalone RS with skipShardingConfigurationChecks.
+ * This test requires users to persist across a restart.
+ * @tags: [requires_persistence]
+ */
+(function() {
+ 'use strict';
+
+ function expectState(rst, state) {
+ assert.soon(function() {
+ var status = rst.status();
+ if (status.myState != state) {
+ print("Waiting for state " + state + " in replSetGetStatus output: " +
+ tojson(status));
+ }
+ return status.myState == state;
+ });
+ }
+
+ var configSvr = MongoRunner.runMongod(
+ {configsvr: "", setParameter: 'skipShardingConfigurationChecks=true'});
+ assert.eq(configSvr, null);
+
+ var shardSvr = MongoRunner.runMongod(
+ {shardsvr: "", setParameter: 'skipShardingConfigurationChecks=true'});
+ assert.eq(shardSvr, null);
+
+ var st =
+ new ShardingTest({name: "skipConfig", shards: {rs0: {nodes: 1}}, other: {sync: false}});
+ var configRS = st.configRS;
+ var shardRS = st.rs0;
+
+ st.stopAllMongos();
+ shardRS.stopSet(15, true);
+ configRS.stopSet(undefined, true);
+
+ jsTestLog("Restarting configRS as a standalone ReplicaSet");
+
+ for (var i = 0; i < configRS.nodes.length; i++) {
+ delete configRS.nodes[i].fullOptions.configsvr;
+ configRS.nodes[i].fullOptions.setParameter = 'skipShardingConfigurationChecks=true';
+ }
+ configRS.startSet({}, true);
+ expectState(configRS, ReplSetTest.State.PRIMARY);
+ configRS.stopSet();
+
+ jsTestLog("Restarting shardRS as a standalone ReplicaSet");
+ for (var i = 0; i < shardRS.nodes.length; i++) {
+ delete shardRS.nodes[i].fullOptions.shardsvr;
+ shardRS.nodes[i].fullOptions.setParameter = 'skipShardingConfigurationChecks=true';
+ }
+ shardRS.startSet({}, true);
+ expectState(shardRS, ReplSetTest.State.PRIMARY);
+ shardRS.stopSet();
+})();
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index a8ce1b54416..5788a6efc11 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -420,6 +420,7 @@ env.Library(
"$BUILD_DIR/mongo/db/curop",
"$BUILD_DIR/mongo/util/net/miniwebserver",
"mongodandmongos",
+ 'repl/replica_set_messages',
'repl/repl_coordinator_global',
],
LIBDEPS_TAGS=[
diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp
index 610adbdbc3d..421501a1cba 100644
--- a/src/mongo/db/mongod_options.cpp
+++ b/src/mongo/db/mongod_options.cpp
@@ -59,6 +59,7 @@ using std::cout;
using std::endl;
using std::string;
+
MongodGlobalParams mongodGlobalParams;
extern DiagLog _diaglog;
@@ -1268,6 +1269,21 @@ Status storeMongodOptions(const moe::Environment& params, const std::vector<std:
log() << endl;
}
+ bool isClusterRoleShard = params.count("shardsvr");
+ bool isClusterRoleConfig = params.count("configsvr");
+ if (params.count("sharding.clusterRole")) {
+ auto clusterRole = params["sharding.clusterRole"].as<std::string>();
+ isClusterRoleShard = isClusterRoleShard || (clusterRole == "shardsvr");
+ isClusterRoleConfig = isClusterRoleConfig || (clusterRole == "configsvr");
+ }
+
+ if ((isClusterRoleShard || isClusterRoleConfig) && skipShardingConfigurationChecks) {
+ auto clusterRoleStr = isClusterRoleConfig ? "--configsvr" : "--shardsvr";
+ return Status(ErrorCodes::BadValue,
+ str::stream() << "Can not specify " << clusterRoleStr
+ << " and set skipShardingConfigurationChecks=true");
+ }
+
#ifdef _WIN32
// If dbPath is a default value, prepend with drive name so log entries are explicit
if (storageGlobalParams.dbpath == storageGlobalParams.kDefaultDbPath ||
@@ -1276,7 +1292,6 @@ Status storeMongodOptions(const moe::Environment& params, const std::vector<std:
storageGlobalParams.dbpath = currentPath.root_name().string() + storageGlobalParams.dbpath;
}
#endif
-
setGlobalReplSettings(replSettings);
return Status::OK();
}
diff --git a/src/mongo/db/mongod_options.h b/src/mongo/db/mongod_options.h
index 18a370f7f75..dccf7fa087d 100644
--- a/src/mongo/db/mongod_options.h
+++ b/src/mongo/db/mongod_options.h
@@ -50,6 +50,8 @@ struct MongodGlobalParams {
MongodGlobalParams() : scriptingEnabled(true) {}
};
+extern bool skipShardingConfigurationChecks;
+
extern MongodGlobalParams mongodGlobalParams;
Status addMongodOptions(moe::OptionSection* options);
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript
index af7515855f9..f158018db11 100644
--- a/src/mongo/db/repl/SConscript
+++ b/src/mongo/db/repl/SConscript
@@ -445,8 +445,8 @@ env.Library('replica_set_messages',
'repl_set_heartbeat_response.cpp',
'repl_set_html_summary.cpp',
'repl_set_request_votes_args.cpp',
- 'replica_set_config.cpp',
'replica_set_tag.cpp',
+ 'replica_set_config.cpp',
'update_position_args.cpp',
'last_vote.cpp',
],
@@ -454,7 +454,7 @@ env.Library('replica_set_messages',
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/bson/util/bson_extract',
'$BUILD_DIR/mongo/db/common',
- '$BUILD_DIR/mongo/db/server_options_core',
+ '$BUILD_DIR/mongo/db/server_options',
'$BUILD_DIR/mongo/util/net/hostandport',
'optime',
'read_concern_args',
diff --git a/src/mongo/db/repl/replica_set_config.cpp b/src/mongo/db/repl/replica_set_config.cpp
index 4c578feca3a..b501707be02 100644
--- a/src/mongo/db/repl/replica_set_config.cpp
+++ b/src/mongo/db/repl/replica_set_config.cpp
@@ -35,10 +35,18 @@
#include "mongo/bson/util/bson_check.h"
#include "mongo/bson/util/bson_extract.h"
#include "mongo/db/jsobj.h"
+#include "mongo/db/mongod_options.h"
#include "mongo/db/server_options.h"
+#include "mongo/db/server_parameters.h"
#include "mongo/stdx/functional.h"
namespace mongo {
+/**
+ * Dont run any sharding validations. Can not be combined with --configsvr or shardvr. Intended to
+ * allow restarting config server or shard as an independent replica set.
+ */
+MONGO_EXPORT_STARTUP_SERVER_PARAMETER(skipShardingConfigurationChecks, bool, false);
+
namespace repl {
#ifndef _MSC_VER
@@ -498,7 +506,7 @@ Status ReplicaSetConfig::validate() const {
"servers cannot have a non-zero slaveDelay");
}
}
- if (!serverGlobalParams.configsvr) {
+ if (!serverGlobalParams.configsvr && !skipShardingConfigurationChecks) {
return Status(ErrorCodes::BadValue,
"Nodes being used for config servers must be started with the "
"--configsvr flag");
@@ -646,7 +654,7 @@ void ReplicaSetConfig::_addInternalWriteConcernModes() {
} else if (status != ErrorCodes::NoSuchKey) {
// NoSuchKey means we have no $voter-tagged nodes in this config;
// other errors are unexpected.
- fassert(28693, status);
+ fassert(40418, status);
}
// $stepDownCheck: one electable node plus ourselves
@@ -658,7 +666,7 @@ void ReplicaSetConfig::_addInternalWriteConcernModes() {
} else if (status != ErrorCodes::NoSuchKey) {
// NoSuchKey means we have no $electable-tagged nodes in this config;
// other errors are unexpected
- fassert(28694, status);
+ fassert(40419, status);
}
}
diff --git a/src/mongo/db/repl/topology_coordinator_impl.cpp b/src/mongo/db/repl/topology_coordinator_impl.cpp
index 53c79c80b03..27d7e14300f 100644
--- a/src/mongo/db/repl/topology_coordinator_impl.cpp
+++ b/src/mongo/db/repl/topology_coordinator_impl.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/audit.h"
#include "mongo/db/client_basic.h"
#include "mongo/db/operation_context.h"
+#include "mongo/db/mongod_options.h"
#include "mongo/db/repl/heartbeat_response_action.h"
#include "mongo/db/repl/is_master_response.h"
#include "mongo/db/repl/isself.h"
@@ -2192,7 +2193,8 @@ MemberState TopologyCoordinatorImpl::getMemberState() const {
}
if (_rsConfig.isConfigServer()) {
- if (_options.configServerMode == CatalogManager::ConfigServerMode::NONE) {
+ if (_options.configServerMode == CatalogManager::ConfigServerMode::NONE &&
+ !skipShardingConfigurationChecks) {
return MemberState::RS_REMOVED;
}
if (_options.configServerMode == CatalogManager::ConfigServerMode::CSRS) {
@@ -2202,7 +2204,9 @@ MemberState TopologyCoordinatorImpl::getMemberState() const {
}
}
} else {
- if (_options.configServerMode != CatalogManager::ConfigServerMode::NONE) {
+ if (_options.configServerMode != CatalogManager::ConfigServerMode::NONE &&
+ (_options.configServerMode != CatalogManager::ConfigServerMode::SCCC &&
+ !skipShardingConfigurationChecks)) {
return MemberState::RS_REMOVED;
}
}
diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js
index 89ab91da580..08f058425a7 100644
--- a/src/mongo/shell/replsettest.js
+++ b/src/mongo/shell/replsettest.js
@@ -387,12 +387,12 @@ var ReplSetTest = function(opts) {
return this.name + "/" + hosts.join(",");
};
- this.startSet = function(options) {
+ this.startSet = function(options, restart) {
print("ReplSetTest starting set");
var nodes = [];
for (var n = 0; n < this.ports.length; n++) {
- nodes.push(this.start(n, options));
+ nodes.push(this.start(n, options, restart));
}
this.nodes = nodes;
@@ -967,7 +967,14 @@ var ReplSetTest = function(opts) {
options.binVersion = MongoRunner.versionIterator(options.binVersion);
}
- options = Object.merge(defaults, options);
+ // If restarting a node, use its existing options as the defaults.
+ if (((options && options.restart) || restart) && this.nodes[n] &&
+ this.nodes[n].hasOwnProperty("fullOptions")) {
+ options = Object.merge(this.nodes[n].fullOptions, options);
+ } else {
+ options = Object.merge(defaults, options);
+ }
+
options = Object.merge(options, this.nodeOptions["n" + n]);
delete options.rsConfig;
diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js
index e9df265f39b..c46ebe09749 100644
--- a/src/mongo/shell/shardingtest.js
+++ b/src/mongo/shell/shardingtest.js
@@ -284,10 +284,14 @@ var ShardingTest = function(params) {
throw Error("impossible");
};
- this.stop = function() {
+ this.stopAllMongos = function(opts) {
for (var i = 0; i < this._mongos.length; i++) {
this.stopMongos(i);
}
+ };
+
+ this.stop = function(opts) {
+ this.stopAllMongos(opts);
for (var i = 0; i < this._connections.length; i++) {
if (this._rs[i]) {