summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatt dannenberg <matt.dannenberg@10gen.com>2014-08-04 13:22:58 -0400
committermatt dannenberg <matt.dannenberg@10gen.com>2014-08-12 06:07:42 -0400
commitf8097fb0f8c4c52bbf117e5d5aaa16f9008937c1 (patch)
treed0c794a379e0db0860f5e3dabb5c9ae4bfb0dcdd
parentba26e58774f11d1ca8ef234af461f601f75d4c0a (diff)
downloadmongo-f8097fb0f8c4c52bbf117e5d5aaa16f9008937c1.tar.gz
SERVER-14453 Implement checkReplEnabledForCommand in ReplicationCoordinatorImpl
-rw-r--r--src/mongo/db/repl/repl_coordinator_impl.cpp13
-rw-r--r--src/mongo/db/repl/repl_coordinator_impl_test.cpp51
2 files changed, 63 insertions, 1 deletions
diff --git a/src/mongo/db/repl/repl_coordinator_impl.cpp b/src/mongo/db/repl/repl_coordinator_impl.cpp
index a284066aed7..121b4f7889d 100644
--- a/src/mongo/db/repl/repl_coordinator_impl.cpp
+++ b/src/mongo/db/repl/repl_coordinator_impl.cpp
@@ -981,7 +981,18 @@ namespace repl {
}
Status ReplicationCoordinatorImpl::checkReplEnabledForCommand(BSONObjBuilder* result) {
- //TODO
+ if (!_settings.usingReplSets()) {
+ if (serverGlobalParams.configsvr) {
+ result->append("info", "configsvr"); // for shell prompt
+ }
+ return Status(ErrorCodes::NoReplicationEnabled, "not running with --replSet");
+ }
+
+ if (getReplicationMode() != modeReplSet) {
+ result->append("info", "run rs.initiate(...) if not yet done for the set");
+ return Status(ErrorCodes::NotYetInitialized, "no replset config has been received");
+ }
+
return Status::OK();
}
diff --git a/src/mongo/db/repl/repl_coordinator_impl_test.cpp b/src/mongo/db/repl/repl_coordinator_impl_test.cpp
index 924ae02029f..4c7906572ff 100644
--- a/src/mongo/db/repl/repl_coordinator_impl_test.cpp
+++ b/src/mongo/db/repl/repl_coordinator_impl_test.cpp
@@ -251,6 +251,57 @@ namespace {
ASSERT_OK(statusAndDur.status);
}
+ TEST_F(ReplCoordTest, checkReplEnabledForCommandNotRepl) {
+ // pass in settings to avoid having a replSet
+ ReplSettings settings;
+ init(settings);
+ start();
+
+ // check status NoReplicationEnabled and empty result
+ BSONObjBuilder result;
+ Status status = getReplCoord()->checkReplEnabledForCommand(&result);
+ ASSERT_EQUALS(status, ErrorCodes::NoReplicationEnabled);
+ ASSERT_TRUE(result.obj().isEmpty());
+ }
+
+ TEST_F(ReplCoordTest, checkReplEnabledForCommandConfigSvr) {
+ ReplSettings settings;
+ serverGlobalParams.configsvr = true;
+ init(settings);
+ start();
+
+ // check status NoReplicationEnabled and result mentions configsrv
+ BSONObjBuilder result;
+ Status status = getReplCoord()->checkReplEnabledForCommand(&result);
+ ASSERT_EQUALS(status, ErrorCodes::NoReplicationEnabled);
+ ASSERT_EQUALS(result.obj()["info"].String(), "configsvr");
+ serverGlobalParams.configsvr = false;
+ }
+
+ TEST_F(ReplCoordTest, checkReplEnabledForCommandNoConfig) {
+ start();
+
+ // check status NotYetInitialized and result mentions rs.initiate
+ BSONObjBuilder result;
+ Status status = getReplCoord()->checkReplEnabledForCommand(&result);
+ ASSERT_EQUALS(status, ErrorCodes::NotYetInitialized);
+ ASSERT_TRUE(result.obj()["info"].String().find("rs.initiate") != std::string::npos);
+ }
+
+ TEST_F(ReplCoordTest, checkReplEnabledForCommandWorking) {
+ assertStartSuccess(BSON("_id" << "mySet" <<
+ "version" << 2 <<
+ "members" << BSON_ARRAY(BSON("host" << "node1:12345" <<
+ "_id" << 0 ))),
+ HostAndPort("node1", 12345));
+
+ // check status OK and result is empty
+ BSONObjBuilder result;
+ Status status = getReplCoord()->checkReplEnabledForCommand(&result);
+ ASSERT_EQUALS(status, Status::OK());
+ ASSERT_TRUE(result.obj().isEmpty());
+ }
+
TEST_F(ReplCoordTest, BasicRBIDUsage) {
start();
BSONObjBuilder result;