diff options
author | Spencer T Brody <spencer@mongodb.com> | 2015-07-31 16:56:58 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2015-08-03 11:48:17 -0400 |
commit | e8b4e57b8d399e50b7f9202e1739f188dadf9bfb (patch) | |
tree | 369265516e26f67bc4a90e264b9e5ba23b67ebc3 /src/mongo/db/repl/replica_set_config.cpp | |
parent | e5c0c5db34af022fa5f931f93c48129e5cbbb678 (diff) | |
download | mongo-e8b4e57b8d399e50b7f9202e1739f188dadf9bfb.tar.gz |
SERVER-19524 Add configServer field to replica set configurations
Diffstat (limited to 'src/mongo/db/repl/replica_set_config.cpp')
-rw-r--r-- | src/mongo/db/repl/replica_set_config.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/mongo/db/repl/replica_set_config.cpp b/src/mongo/db/repl/replica_set_config.cpp index 70bc1156470..1f394956f91 100644 --- a/src/mongo/db/repl/replica_set_config.cpp +++ b/src/mongo/db/repl/replica_set_config.cpp @@ -45,6 +45,7 @@ const size_t ReplicaSetConfig::kMaxMembers; const size_t ReplicaSetConfig::kMaxVotingMembers; #endif +const std::string ReplicaSetConfig::kConfigServerFieldName = "configServer"; const std::string ReplicaSetConfig::kVersionFieldName = "version"; const std::string ReplicaSetConfig::kMajorityWriteConcernModeName = "$majority"; const Seconds ReplicaSetConfig::kDefaultHeartbeatTimeoutPeriod(10); @@ -61,7 +62,8 @@ const std::string kLegalConfigTopFieldNames[] = {kIdFieldName, ReplicaSetConfig::kVersionFieldName, kMembersFieldName, kSettingsFieldName, - kProtocolVersionFieldName}; + kProtocolVersionFieldName, + ReplicaSetConfig::kConfigServerFieldName}; const std::string kHeartbeatTimeoutFieldName = "heartbeatTimeoutSecs"; const std::string kChainingAllowedFieldName = "chainingAllowed"; @@ -71,7 +73,10 @@ const std::string kGetLastErrorModesFieldName = "getLastErrorModes"; } // namespace ReplicaSetConfig::ReplicaSetConfig() - : _isInitialized(false), _heartbeatTimeoutPeriod(0), _protocolVersion(0) {} + : _isInitialized(false), + _heartbeatTimeoutPeriod(0), + _protocolVersion(0), + _configServer(false) {} Status ReplicaSetConfig::initialize(const BSONObj& cfg) { _isInitialized = false; @@ -118,6 +123,14 @@ Status ReplicaSetConfig::initialize(const BSONObj& cfg) { } // + // Parse configServer + // + status = bsonExtractBooleanFieldWithDefault(cfg, kConfigServerFieldName, false, &_configServer); + if (!status.isOK()) { + return status; + } + + // // Parse settings // BSONElement settingsElement; @@ -364,6 +377,19 @@ Status ReplicaSetConfig::validate() const { << _protocolVersion << " is out of range"); } + if (_configServer) { + if (arbiterCount > 0) { + return Status(ErrorCodes::BadValue, + "Arbiters are not allowed in replica set configurations being used for " + "config servers"); + } + if (_protocolVersion < 1) { + return Status(ErrorCodes::BadValue, + "Replica sets must have protocol version of at least 1 in order to be " + "used as sharding config servers"); + } + } + return Status::OK(); } @@ -511,6 +537,11 @@ BSONObj ReplicaSetConfig::toBSON() const { BSONObjBuilder configBuilder; configBuilder.append(kIdFieldName, _replSetName); configBuilder.appendIntOrLL(kVersionFieldName, _version); + if (_protocolVersion > 0) { + // Don't include "configServer" field if protocol version is less than 1 to preserve + // backwards compatibility + configBuilder.append(kConfigServerFieldName, _configServer); + } BSONArrayBuilder members(configBuilder.subarrayStart(kMembersFieldName)); for (MemberIterator mem = membersBegin(); mem != membersEnd(); mem++) { |