summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/replica_set_config.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/repl/replica_set_config.h')
-rw-r--r--src/mongo/db/repl/replica_set_config.h446
1 files changed, 238 insertions, 208 deletions
diff --git a/src/mongo/db/repl/replica_set_config.h b/src/mongo/db/repl/replica_set_config.h
index fcd880705ea..2db58856234 100644
--- a/src/mongo/db/repl/replica_set_config.h
+++ b/src/mongo/db/repl/replica_set_config.h
@@ -41,219 +41,249 @@
namespace mongo {
- class BSONObj;
+class BSONObj;
namespace repl {
+/**
+ * Representation of the configuration information about a particular replica set.
+ */
+class ReplicaSetConfig {
+public:
+ typedef std::vector<MemberConfig>::const_iterator MemberIterator;
+
+ static const std::string kVersionFieldName;
+ static const std::string kMajorityWriteConcernModeName;
+
+ static const size_t kMaxMembers = 50;
+ static const size_t kMaxVotingMembers = 7;
+ static const Seconds kDefaultHeartbeatTimeoutPeriod;
+
+ ReplicaSetConfig();
+ std::string asBson() {
+ return "";
+ }
+ /**
+ * Initializes this ReplicaSetConfig from the contents of "cfg".
+ */
+ 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;
+
+ /**
+ * Checks if this configuration can satisfy the given write concern.
+ *
+ * Things that are taken into consideration include:
+ * 1. If the set has enough data-bearing members.
+ * 2. If the write concern mode exists.
+ * 3. If there are enough members for the write concern mode specified.
+ */
+ Status checkIfWriteConcernCanBeSatisfied(const WriteConcernOptions& writeConcern) const;
+
+ /**
+ * Gets the version of this configuration.
+ *
+ * The version number sequences configurations of the replica set, so that
+ * nodes may distinguish between "older" and "newer" configurations.
+ */
+ long long getConfigVersion() const {
+ return _version;
+ }
+
+ /**
+ * Gets the name (_id field value) of the replica set described by this configuration.
+ */
+ const std::string& getReplSetName() const {
+ return _replSetName;
+ }
+
+ /**
+ * Gets the number of members in this configuration.
+ */
+ int getNumMembers() const {
+ return _members.size();
+ }
+
+ /**
+ * Gets a begin iterator over the MemberConfigs stored in this ReplicaSetConfig.
+ */
+ MemberIterator membersBegin() const {
+ return _members.begin();
+ }
+
+ /**
+ * Gets an end iterator over the MemberConfigs stored in this ReplicaSetConfig.
+ */
+ MemberIterator membersEnd() const {
+ return _members.end();
+ }
+
+ /**
+ * Access a MemberConfig element by index.
+ */
+ const MemberConfig& getMemberAt(size_t i) const;
+
+ /**
+ * Returns a pointer to the MemberConfig corresponding to the member with the given _id in
+ * the config, or NULL if there is no member with that ID.
+ */
+ const MemberConfig* findMemberByID(int id) const;
+
+ /**
+ * Returns a pointer to the MemberConfig corresponding to the member with the given
+ * HostAndPort in the config, or NULL if there is no member with that address.
+ */
+ const MemberConfig* findMemberByHostAndPort(const HostAndPort& hap) const;
+
+ /**
+ * Returns a MemberConfig index position corresponding to the member with the given
+ * HostAndPort in the config, or -1 if there is no member with that address.
+ */
+ const int findMemberIndexByHostAndPort(const HostAndPort& hap) const;
+
+ /**
+ * Returns a MemberConfig index position corresponding to the member with the given
+ * _id in the config, or -1 if there is no member with that address.
+ */
+ const int findMemberIndexByConfigId(long long configId) const;
+
+ /**
+ * Gets the default write concern for the replica set described by this configuration.
+ */
+ const WriteConcernOptions& getDefaultWriteConcern() const {
+ return _defaultWriteConcern;
+ }
+
+ /**
+ * Gets the amount of time to wait for a response to hearbeats sent to other
+ * nodes in the replica set.
+ */
+ Seconds getHeartbeatTimeoutPeriod() const {
+ return _heartbeatTimeoutPeriod;
+ }
+
+ /**
+ * Gets the amount of time to wait for a response to hearbeats sent to other
+ * nodes in the replica set, as above, but returns a Milliseconds instead of
+ * Seconds object.
+ */
+ Milliseconds getHeartbeatTimeoutPeriodMillis() const {
+ return _heartbeatTimeoutPeriod;
+ }
+
+ /**
+ * Gets the number of votes required to win an election.
+ */
+ int getMajorityVoteCount() const {
+ return _majorityVoteCount;
+ }
+
+ /**
+ * Gets the number of voters.
+ */
+ int getTotalVotingMembers() const {
+ return _totalVotingMembers;
+ }
+
+ /**
+ * Returns true if automatic (not explicitly set) chaining is allowed.
+ */
+ bool isChainingAllowed() const {
+ return _chainingAllowed;
+ }
+
+ /**
+ * Returns a ReplicaSetTag with the given "key" and "value", or an invalid
+ * tag if the configuration describes no such tag.
+ */
+ ReplicaSetTag findTag(StringData key, StringData value) const;
+
+ /**
+ * Returns the pattern corresponding to "patternName" in this configuration.
+ * If "patternName" is not a valid pattern in this configuration, returns
+ * ErrorCodes::NoSuchKey.
+ */
+ StatusWith<ReplicaSetTagPattern> findCustomWriteMode(StringData patternName) const;
+
+ /**
+ * Returns the "tags configuration" for this replicaset.
+ *
+ * NOTE(schwerin): Not clear if this should be used other than for reporting/debugging.
+ */
+ const ReplicaSetTagConfig& getTagConfig() const {
+ return _tagConfig;
+ }
+
+ /**
+ * Returns the config as a BSONObj.
+ */
+ BSONObj toBSON() const;
+
+ /**
+ * Returns a vector of strings which are the names of the WriteConcernModes.
+ * Currently used in unit tests to compare two configs.
+ */
+ std::vector<std::string> getWriteConcernNames() const;
+
+ /**
+ * Returns the number of voting data-bearing members that must acknowledge a write
+ * in order to satisfy a write concern of {w: "majority"}.
+ */
+ int getWriteMajority() const {
+ return _writeMajority;
+ }
+
+ /**
+ * Gets the protocol version for this configuration.
+ *
+ * The protocol version number currently determines what election protocol is used by the
+ * cluster; 0 is the default and indicates the old 3.0 election protocol.
+ */
+ long long getProtocolVersion() const {
+ return _protocolVersion;
+ }
+
+private:
+ /**
+ * Parses the "settings" subdocument of a replica set configuration.
+ */
+ Status _parseSettingsSubdocument(const BSONObj& settings);
+
+ /**
+ * Calculates and stores the majority for electing a primary (_majorityVoteCount).
+ */
+ void _calculateMajorities();
+
/**
- * Representation of the configuration information about a particular replica set.
+ * Adds internal write concern modes to the getLastErrorModes list.
*/
- class ReplicaSetConfig {
- public:
- typedef std::vector<MemberConfig>::const_iterator MemberIterator;
-
- static const std::string kVersionFieldName;
- static const std::string kMajorityWriteConcernModeName;
-
- static const size_t kMaxMembers = 50;
- static const size_t kMaxVotingMembers = 7;
- static const Seconds kDefaultHeartbeatTimeoutPeriod;
-
- ReplicaSetConfig();
- std::string asBson() { return ""; }
- /**
- * Initializes this ReplicaSetConfig from the contents of "cfg".
- */
- 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;
-
- /**
- * Checks if this configuration can satisfy the given write concern.
- *
- * Things that are taken into consideration include:
- * 1. If the set has enough data-bearing members.
- * 2. If the write concern mode exists.
- * 3. If there are enough members for the write concern mode specified.
- */
- Status checkIfWriteConcernCanBeSatisfied(const WriteConcernOptions& writeConcern) const;
-
- /**
- * Gets the version of this configuration.
- *
- * The version number sequences configurations of the replica set, so that
- * nodes may distinguish between "older" and "newer" configurations.
- */
- long long getConfigVersion() const { return _version; }
-
- /**
- * Gets the name (_id field value) of the replica set described by this configuration.
- */
- const std::string& getReplSetName() const { return _replSetName; }
-
- /**
- * Gets the number of members in this configuration.
- */
- int getNumMembers() const { return _members.size(); }
-
- /**
- * Gets a begin iterator over the MemberConfigs stored in this ReplicaSetConfig.
- */
- MemberIterator membersBegin() const { return _members.begin(); }
-
- /**
- * Gets an end iterator over the MemberConfigs stored in this ReplicaSetConfig.
- */
- MemberIterator membersEnd() const { return _members.end(); }
-
- /**
- * Access a MemberConfig element by index.
- */
- const MemberConfig& getMemberAt(size_t i) const;
-
- /**
- * Returns a pointer to the MemberConfig corresponding to the member with the given _id in
- * the config, or NULL if there is no member with that ID.
- */
- const MemberConfig* findMemberByID(int id) const;
-
- /**
- * Returns a pointer to the MemberConfig corresponding to the member with the given
- * HostAndPort in the config, or NULL if there is no member with that address.
- */
- const MemberConfig* findMemberByHostAndPort(const HostAndPort& hap) const;
-
- /**
- * Returns a MemberConfig index position corresponding to the member with the given
- * HostAndPort in the config, or -1 if there is no member with that address.
- */
- const int findMemberIndexByHostAndPort(const HostAndPort& hap) const;
-
- /**
- * Returns a MemberConfig index position corresponding to the member with the given
- * _id in the config, or -1 if there is no member with that address.
- */
- const int findMemberIndexByConfigId(long long configId) const;
-
- /**
- * Gets the default write concern for the replica set described by this configuration.
- */
- const WriteConcernOptions& getDefaultWriteConcern() const { return _defaultWriteConcern; }
-
- /**
- * Gets the amount of time to wait for a response to hearbeats sent to other
- * nodes in the replica set.
- */
- Seconds getHeartbeatTimeoutPeriod() const { return _heartbeatTimeoutPeriod; }
-
- /**
- * Gets the amount of time to wait for a response to hearbeats sent to other
- * nodes in the replica set, as above, but returns a Milliseconds instead of
- * Seconds object.
- */
- Milliseconds getHeartbeatTimeoutPeriodMillis() const {
- return _heartbeatTimeoutPeriod;
- }
-
- /**
- * Gets the number of votes required to win an election.
- */
- int getMajorityVoteCount() const { return _majorityVoteCount; }
-
- /**
- * Gets the number of voters.
- */
- int getTotalVotingMembers() const { return _totalVotingMembers; }
-
- /**
- * Returns true if automatic (not explicitly set) chaining is allowed.
- */
- bool isChainingAllowed() const { return _chainingAllowed; }
-
- /**
- * Returns a ReplicaSetTag with the given "key" and "value", or an invalid
- * tag if the configuration describes no such tag.
- */
- ReplicaSetTag findTag(StringData key, StringData value) const;
-
- /**
- * Returns the pattern corresponding to "patternName" in this configuration.
- * If "patternName" is not a valid pattern in this configuration, returns
- * ErrorCodes::NoSuchKey.
- */
- StatusWith<ReplicaSetTagPattern> findCustomWriteMode(StringData patternName) const;
-
- /**
- * Returns the "tags configuration" for this replicaset.
- *
- * NOTE(schwerin): Not clear if this should be used other than for reporting/debugging.
- */
- const ReplicaSetTagConfig& getTagConfig() const { return _tagConfig; }
-
- /**
- * Returns the config as a BSONObj.
- */
- BSONObj toBSON() const;
-
- /**
- * Returns a vector of strings which are the names of the WriteConcernModes.
- * Currently used in unit tests to compare two configs.
- */
- std::vector<std::string> getWriteConcernNames() const;
-
- /**
- * Returns the number of voting data-bearing members that must acknowledge a write
- * in order to satisfy a write concern of {w: "majority"}.
- */
- int getWriteMajority() const { return _writeMajority; }
-
- /**
- * Gets the protocol version for this configuration.
- *
- * The protocol version number currently determines what election protocol is used by the
- * cluster; 0 is the default and indicates the old 3.0 election protocol.
- */
- long long getProtocolVersion() const { return _protocolVersion; }
-
- private:
- /**
- * Parses the "settings" subdocument of a replica set configuration.
- */
- Status _parseSettingsSubdocument(const BSONObj& settings);
-
- /**
- * Calculates and stores the majority for electing a primary (_majorityVoteCount).
- */
- void _calculateMajorities();
-
- /**
- * Adds internal write concern modes to the getLastErrorModes list.
- */
- void _addInternalWriteConcernModes();
-
- bool _isInitialized;
- long long _version;
- std::string _replSetName;
- std::vector<MemberConfig> _members;
- WriteConcernOptions _defaultWriteConcern;
- Seconds _heartbeatTimeoutPeriod;
- bool _chainingAllowed;
- int _majorityVoteCount;
- int _writeMajority;
- int _totalVotingMembers;
- ReplicaSetTagConfig _tagConfig;
- StringMap<ReplicaSetTagPattern> _customWriteConcernModes;
- long long _protocolVersion;
- };
+ void _addInternalWriteConcernModes();
+
+ bool _isInitialized;
+ long long _version;
+ std::string _replSetName;
+ std::vector<MemberConfig> _members;
+ WriteConcernOptions _defaultWriteConcern;
+ Seconds _heartbeatTimeoutPeriod;
+ bool _chainingAllowed;
+ int _majorityVoteCount;
+ int _writeMajority;
+ int _totalVotingMembers;
+ ReplicaSetTagConfig _tagConfig;
+ StringMap<ReplicaSetTagPattern> _customWriteConcernModes;
+ long long _protocolVersion;
+};
} // namespace repl