summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatt dannenberg <matt.dannenberg@10gen.com>2015-03-09 04:41:32 -0400
committermatt dannenberg <matt.dannenberg@10gen.com>2015-03-12 10:09:15 -0400
commit64894f2b7394c4f46b9de40ffb6d6e95a74c7c41 (patch)
treebd644a6eab39573489a97a909a31b36467d38836
parentd8f3c2e618f69662d20ee684c9d8fe26ff3bace5 (diff)
downloadmongo-64894f2b7394c4f46b9de40ffb6d6e95a74c7c41.tar.gz
SERVER-17491 better error message when running replSetInitiate against a standalone node
-rw-r--r--src/mongo/db/repl/SConscript3
-rw-r--r--src/mongo/db/repl/repl_set_seed_list.cpp95
-rw-r--r--src/mongo/db/repl/repl_set_seed_list.h63
-rw-r--r--src/mongo/db/repl/replset_commands.cpp68
4 files changed, 63 insertions, 166 deletions
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript
index 8174482b19f..f4709cb2d8c 100644
--- a/src/mongo/db/repl/SConscript
+++ b/src/mongo/db/repl/SConscript
@@ -153,8 +153,7 @@ env.CppUnitTest('repl_coordinator_impl_reconfig_test',
env.Library('repl_coordinator_interface',
['replication_coordinator.cpp',
- 'replication_coordinator_external_state.cpp',
- 'repl_set_seed_list.cpp'],
+ 'replication_coordinator_external_state.cpp'],
LIBDEPS=[
'$BUILD_DIR/mongo/hostandport',
])
diff --git a/src/mongo/db/repl/repl_set_seed_list.cpp b/src/mongo/db/repl/repl_set_seed_list.cpp
deleted file mode 100644
index 60cfab0c877..00000000000
--- a/src/mongo/db/repl/repl_set_seed_list.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
-* Copyright (C) 2008 10gen Inc.
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU Affero General Public License, version 3,
-* as published by the Free Software Foundation.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU Affero General Public License for more details.
-*
-* You should have received a copy of the GNU Affero General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-* As a special exception, the copyright holders give permission to link the
-* code of portions of this program with the OpenSSL library under certain
-* conditions as described in each individual source file and distribute
-* linked combinations including the program with the OpenSSL library. You
-* must comply with the GNU Affero General Public License in all respects for
-* all of the code used other than as permitted herein. If you modify file(s)
-* with this exception, you may extend this exception to your version of the
-* file(s), but you are not obligated to do so. If you do not wish to do so,
-* delete this exception statement from your version. If you delete this
-* exception statement from all source files in the program, then also delete
-* it in the license file.
-*/
-
-#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kReplication
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/db/repl/repl_set_seed_list.h"
-
-#include "mongo/db/repl/replication_coordinator_external_state.h"
-#include "mongo/util/assert_util.h"
-#include "mongo/util/log.h"
-
-namespace mongo {
-
-namespace repl {
-
- using std::string;
-
- /** @param cfgString <setname>/<seedhost1>,<seedhost2> */
- void parseReplSetSeedList(ReplicationCoordinatorExternalState* externalState,
- const std::string& cfgString,
- std::string& setname,
- std::vector<HostAndPort>& seeds,
- std::set<HostAndPort>& seedSet) {
- const char *p = cfgString.c_str();
- const char *slash = strchr(p, '/');
- if( slash )
- setname = string(p, slash-p);
- else
- setname = p;
- uassert(13093,
- "bad --replSet config string format is: <setname>[/<seedhost1>,<seedhost2>,...]",
- !setname.empty());
-
- if( slash == 0 )
- return;
-
- p = slash + 1;
- while( 1 ) {
- const char *comma = strchr(p, ',');
- if( comma == 0 ) comma = strchr(p,0);
- if( p == comma )
- break;
- {
- HostAndPort m;
- try {
- m = HostAndPort( string(p, comma-p) );
- }
- catch(...) {
- uassert(13114, "bad --replSet seed hostname", false);
- }
- uassert(13096, "bad --replSet command line config string - dups?",
- seedSet.count(m) == 0);
- seedSet.insert(m);
- //uassert(13101, "can't use localhost in replset host list", !m.isLocalHost());
- if (externalState->isSelf(m)) {
- LOG(1) << "ignoring seed " << m.toString() << " (=self)";
- }
- else
- seeds.push_back(m);
- if( *comma == 0 )
- break;
- p = comma + 1;
- }
- }
- }
-
-} // namespace repl
-} // namespace mongo
diff --git a/src/mongo/db/repl/repl_set_seed_list.h b/src/mongo/db/repl/repl_set_seed_list.h
deleted file mode 100644
index 761928d2a7a..00000000000
--- a/src/mongo/db/repl/repl_set_seed_list.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
-* Copyright (C) 2008 10gen Inc.
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU Affero General Public License, version 3,
-* as published by the Free Software Foundation.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU Affero General Public License for more details.
-*
-* You should have received a copy of the GNU Affero General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-* As a special exception, the copyright holders give permission to link the
-* code of portions of this program with the OpenSSL library under certain
-* conditions as described in each individual source file and distribute
-* linked combinations including the program with the OpenSSL library. You
-* must comply with the GNU Affero General Public License in all respects for
-* all of the code used other than as permitted herein. If you modify file(s)
-* with this exception, you may extend this exception to your version of the
-* file(s), but you are not obligated to do so. If you do not wish to do so,
-* delete this exception statement from your version. If you delete this
-* exception statement from all source files in the program, then also delete
-* it in the license file.
-*/
-
-#pragma once
-
-#include <set>
-#include <string>
-#include <vector>
-
-#include "mongo/util/net/hostandport.h"
-
-namespace mongo {
-namespace repl {
-
- class ReplicationCoordinatorExternalState;
-
- void parseReplSetSeedList(ReplicationCoordinatorExternalState* externalState,
- const std::string& cfgString,
- std::string& setname,
- std::vector<HostAndPort>& seeds,
- std::set<HostAndPort>& seedSet);
-
- /** Parameter given to the --replSet command line option (parsed).
- Syntax is "<setname>/<seedhost1>,<seedhost2>"
- where setname is a name and seedhost is "<host>[:<port>]" */
- class ReplSetSeedList {
- public:
- ReplSetSeedList(ReplicationCoordinatorExternalState* externalState,
- const std::string& cfgString) {
- parseReplSetSeedList(externalState, cfgString, setname, seeds, seedSet);
- }
- std::string setname;
- std::vector<HostAndPort> seeds;
- std::set<HostAndPort> seedSet;
- };
-
-} // namespace repl
-} // namespace mongo
diff --git a/src/mongo/db/repl/replset_commands.cpp b/src/mongo/db/repl/replset_commands.cpp
index f3ad62ead42..290e25f4928 100644
--- a/src/mongo/db/repl/replset_commands.cpp
+++ b/src/mongo/db/repl/replset_commands.cpp
@@ -45,7 +45,6 @@
#include "mongo/db/repl/oplog.h"
#include "mongo/db/repl/repl_set_heartbeat_args.h"
#include "mongo/db/repl/repl_set_heartbeat_response.h"
-#include "mongo/db/repl/repl_set_seed_list.h"
#include "mongo/db/repl/replication_coordinator_global.h"
#include "mongo/db/repl/replication_coordinator_external_state_impl.h"
#include "mongo/db/repl/replication_executor.h"
@@ -203,6 +202,57 @@ namespace {
verify(h != "localhost");
return HostAndPort(h, serverGlobalParams.port);
}
+
+ void parseReplSetSeedList(ReplicationCoordinatorExternalState* externalState,
+ const std::string& replSetString,
+ std::string* setname,
+ std::vector<HostAndPort>* seeds) {
+ const char *p = replSetString.c_str();
+ const char *slash = strchr(p, '/');
+ std::set<HostAndPort> seedSet;
+ if (slash) {
+ *setname = string(p, slash-p);
+ }
+ else {
+ *setname = p;
+ }
+
+ if (slash == 0) {
+ return;
+ }
+
+ p = slash + 1;
+ while (1) {
+ const char *comma = strchr(p, ',');
+ if (comma == 0) {
+ comma = strchr(p,0);
+ }
+ if (p == comma) {
+ break;
+ }
+ HostAndPort m;
+ try {
+ m = HostAndPort( string(p, comma-p) );
+ }
+ catch (...) {
+ uassert(13114, "bad --replSet seed hostname", false);
+ }
+ uassert(13096, "bad --replSet command line config string - dups?",
+ seedSet.count(m) == 0);
+ seedSet.insert(m);
+ //uassert(13101, "can't use localhost in replset host list", !m.isLocalHost());
+ if (externalState->isSelf(m)) {
+ LOG(1) << "ignoring seed " << m.toString() << " (=self)";
+ }
+ else {
+ seeds->push_back(m);
+ }
+ if (*comma == 0) {
+ break;
+ }
+ p = comma + 1;
+ }
+ }
} // namespace
class CmdReplSetInitiate : public ReplSetCommand {
@@ -232,6 +282,14 @@ namespace {
configObj = cmdObj["replSetInitiate"].Obj();
}
+ std::string replSetString = getGlobalReplicationCoordinator()->getSettings().replSet;
+ if (replSetString.empty()) {
+ return appendCommandStatus(result,
+ Status(ErrorCodes::NoReplicationEnabled,
+ "This node was not started with the replSet "
+ "option"));
+ }
+
if (configObj.isEmpty()) {
string noConfigMessage = "no configuration specified. "
"Using a default configuration for the set";
@@ -241,13 +299,11 @@ namespace {
ReplicationCoordinatorExternalStateImpl externalState;
std::string name;
std::vector<HostAndPort> seeds;
- std::set<HostAndPort> seedSet;
parseReplSetSeedList(
&externalState,
- getGlobalReplicationCoordinator()->getSettings().replSet,
- name,
- seeds,
- seedSet); // may throw...
+ replSetString,
+ &name,
+ &seeds); // may throw...
BSONObjBuilder b;
b.append("_id", name);