diff options
author | Andy Schwerin <schwerin@mongodb.com> | 2014-07-21 11:52:34 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@mongodb.com> | 2014-07-21 13:41:21 -0400 |
commit | fcab456c204a1c5eccfc3d700337cb5bff0621fc (patch) | |
tree | 40a8a67e579fe11f6c0e74f5e15ac32226b71f2a /src/mongo | |
parent | 33bfa479a3ec71230aad30ccc1ab9ac55794ca20 (diff) | |
download | mongo-fcab456c204a1c5eccfc3d700337cb5bff0621fc.tar.gz |
SERVER-14624 Add isInitialized() concept to ReplicaSetConfig; expose some field name constants.
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/repl/replica_set_config.cpp | 21 | ||||
-rw-r--r-- | src/mongo/db/repl/replica_set_config.h | 12 |
2 files changed, 23 insertions, 10 deletions
diff --git a/src/mongo/db/repl/replica_set_config.cpp b/src/mongo/db/repl/replica_set_config.cpp index a67a1f00fcb..5bc674a035a 100644 --- a/src/mongo/db/repl/replica_set_config.cpp +++ b/src/mongo/db/repl/replica_set_config.cpp @@ -46,19 +46,18 @@ namespace repl { #endif const Seconds ReplicaSetConfig::kDefaultHeartbeatTimeoutPeriod(10); + const std::string ReplicaSetConfig::kIdFieldName = "_id"; + const std::string ReplicaSetConfig::kVersionFieldName = "version"; + const std::string ReplicaSetConfig::kMembersFieldName = "members"; + const std::string ReplicaSetConfig::kSettingsFieldName = "settings"; namespace { - const std::string kIdFieldName = "_id"; - const std::string kVersionFieldName = "version"; - const std::string kMembersFieldName = "members"; - const std::string kSettingsFieldName = "settings"; - const std::string kLegalConfigTopFieldNames[] = { - kIdFieldName, - kVersionFieldName, - kMembersFieldName, - kSettingsFieldName + ReplicaSetConfig::kIdFieldName, + ReplicaSetConfig::kVersionFieldName, + ReplicaSetConfig::kMembersFieldName, + ReplicaSetConfig::kSettingsFieldName }; const std::string kHeartbeatTimeoutFieldName = "heartbeatTimeoutSecs"; @@ -68,9 +67,10 @@ namespace { } // namespace - ReplicaSetConfig::ReplicaSetConfig() : _heartbeatTimeoutPeriod(0) {} + ReplicaSetConfig::ReplicaSetConfig() : _isInitialized(false), _heartbeatTimeoutPeriod(0) {} Status ReplicaSetConfig::initialize(const BSONObj& cfg) { + _isInitialized = false; _members.clear(); Status status = bsonCheckOnlyHasFields( "replica set configuration", cfg, kLegalConfigTopFieldNames); @@ -130,6 +130,7 @@ namespace { return status; _calculateMajorityNumber(); + _isInitialized = true; return Status::OK(); } diff --git a/src/mongo/db/repl/replica_set_config.h b/src/mongo/db/repl/replica_set_config.h index 31b14cc8438..f82375ca317 100644 --- a/src/mongo/db/repl/replica_set_config.h +++ b/src/mongo/db/repl/replica_set_config.h @@ -52,6 +52,11 @@ namespace repl { public: typedef std::vector<MemberConfig>::const_iterator MemberIterator; + static const std::string kIdFieldName; + static const std::string kVersionFieldName; + static const std::string kMembersFieldName; + static const std::string kSettingsFieldName; + static const size_t kMaxMembers = 12; static const size_t kMaxVotingMembers = 7; static const Seconds kDefaultHeartbeatTimeoutPeriod; @@ -64,6 +69,12 @@ namespace repl { Status initialize(const BSONObj& cfg); /** + * Returns true if this object has been successfully initialized or copied from + * an initialized object. + */ + bool isInitialized() const { return _isInitialized; } + + /** * Performs basic consistency checks on the replica set configuration. */ Status validate() const; @@ -166,6 +177,7 @@ namespace repl { */ void _calculateMajorityNumber(); + bool _isInitialized; long long _version; std::string _replSetName; std::vector<MemberConfig> _members; |