summaryrefslogtreecommitdiff
path: root/src/mongo/s/type_config_version.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/type_config_version.h')
-rw-r--r--src/mongo/s/type_config_version.h414
1 files changed, 216 insertions, 198 deletions
diff --git a/src/mongo/s/type_config_version.h b/src/mongo/s/type_config_version.h
index 778efab059f..c98bf531234 100644
--- a/src/mongo/s/type_config_version.h
+++ b/src/mongo/s/type_config_version.h
@@ -36,215 +36,233 @@
namespace mongo {
- /**
- * This class represents the layout and contents of documents contained in the
- * config.version collection. All manipulation of documents coming from that
- * collection should be done with this class.
- *
- * Usage Example:
- *
- * // Contact the config. 'conn' has been obtained before.
- * DBClientBase* conn;
- * BSONObj query = QUERY(VersionType::exampleField("exampleFieldName"));
- * exampleDoc = conn->findOne(VersionType::ConfigNS, query);
- *
- * // Process the response.
- * VersionType exampleType;
- * std::string errMsg;
- * if (!exampleType.parseBSON(exampleDoc, &errMsg) || !exampleType.isValid(&errMsg)) {
- * // Can't use 'exampleType'. Take action.
- * }
- * // use 'exampleType'
- *
- */
- class VersionType {
- MONGO_DISALLOW_COPYING(VersionType);
- public:
-
- //
- // schema declarations
- //
-
- // Name of the version collection in the config server.
- static const std::string ConfigNS;
-
- // Field names and types in the version collection type.
- static const BSONField<int> minCompatibleVersion;
- static const BSONField<int> currentVersion;
- static const BSONField<BSONArray> excludingMongoVersions;
- static const BSONField<OID> clusterId;
- static const BSONField<OID> upgradeId;
- static const BSONField<BSONObj> upgradeState;
-
- //
- // version type methods
- //
-
- VersionType();
- ~VersionType();
-
- /**
- * Returns true if all the mandatory fields are present and have valid
- * representations. Otherwise returns false and fills in the optional 'errMsg' string.
- */
- bool isValid(std::string* errMsg) const;
-
- /**
- * Returns the BSON representation of the entry.
- */
- BSONObj toBSON() const;
-
- /**
- * Clears and populates the internal state using the 'source' BSON object if the
- * latter contains valid values. Otherwise sets errMsg and returns false.
- */
- bool parseBSON(const BSONObj& source, std::string* errMsg);
-
- /**
- * Clears the internal state.
- */
- void clear();
-
- /**
- * Copies all the fields present in 'this' to 'other'.
- */
- void cloneTo(VersionType* other) const;
-
- /**
- * Returns a std::string representation of the current internal state.
- */
- std::string toString() const;
-
- //
- // individual field accessors
- //
-
- // Mandatory Fields
- void setMinCompatibleVersion(const int minCompatibleVersion) {
- _minCompatibleVersion = minCompatibleVersion;
- _isMinCompatibleVersionSet = true;
- }
-
- void unsetMinCompatibleVersion() { _isMinCompatibleVersionSet = false; }
-
- bool isMinCompatibleVersionSet() const { return _isMinCompatibleVersionSet; }
-
- // Calling get*() methods when the member is not set results in undefined behavior
- int getMinCompatibleVersion() const {
- dassert(_isMinCompatibleVersionSet);
- return _minCompatibleVersion;
- }
-
- void setCurrentVersion(const int currentVersion) {
- _currentVersion = currentVersion;
- _isCurrentVersionSet = true;
- }
-
- void unsetCurrentVersion() { _isCurrentVersionSet = false; }
-
- bool isCurrentVersionSet() const { return _isCurrentVersionSet; }
-
- // Calling get*() methods when the member is not set results in undefined behavior
- int getCurrentVersion() const {
- dassert(_isCurrentVersionSet);
- return _currentVersion;
- }
-
- void setExcludingMongoVersions(const BSONArray& excludingMongoVersions) {
- _excludingMongoVersions = excludingMongoVersions;
- _isExcludingMongoVersionsSet = true;
- }
+/**
+ * This class represents the layout and contents of documents contained in the
+ * config.version collection. All manipulation of documents coming from that
+ * collection should be done with this class.
+ *
+ * Usage Example:
+ *
+ * // Contact the config. 'conn' has been obtained before.
+ * DBClientBase* conn;
+ * BSONObj query = QUERY(VersionType::exampleField("exampleFieldName"));
+ * exampleDoc = conn->findOne(VersionType::ConfigNS, query);
+ *
+ * // Process the response.
+ * VersionType exampleType;
+ * std::string errMsg;
+ * if (!exampleType.parseBSON(exampleDoc, &errMsg) || !exampleType.isValid(&errMsg)) {
+ * // Can't use 'exampleType'. Take action.
+ * }
+ * // use 'exampleType'
+ *
+ */
+class VersionType {
+ MONGO_DISALLOW_COPYING(VersionType);
- void unsetExcludingMongoVersions() { _isExcludingMongoVersionsSet = false; }
+public:
+ //
+ // schema declarations
+ //
- bool isExcludingMongoVersionsSet() const {
- return _isExcludingMongoVersionsSet || excludingMongoVersions.hasDefault();
- }
+ // Name of the version collection in the config server.
+ static const std::string ConfigNS;
- // Calling get*() methods when the member is not set and has no default results in undefined
- // behavior
- const BSONArray getExcludingMongoVersions() const {
- if (_isExcludingMongoVersionsSet) {
- return _excludingMongoVersions;
- } else {
- dassert(excludingMongoVersions.hasDefault());
- return excludingMongoVersions.getDefault();
- }
- }
+ // Field names and types in the version collection type.
+ static const BSONField<int> minCompatibleVersion;
+ static const BSONField<int> currentVersion;
+ static const BSONField<BSONArray> excludingMongoVersions;
+ static const BSONField<OID> clusterId;
+ static const BSONField<OID> upgradeId;
+ static const BSONField<BSONObj> upgradeState;
- void setClusterId(const OID clusterId) {
- _clusterId = clusterId;
- _isClusterIdSet = true;
- }
+ //
+ // version type methods
+ //
- void unsetClusterId() { _isClusterIdSet = false; }
+ VersionType();
+ ~VersionType();
- bool isClusterIdSet() const { return _isClusterIdSet; }
+ /**
+ * Returns true if all the mandatory fields are present and have valid
+ * representations. Otherwise returns false and fills in the optional 'errMsg' string.
+ */
+ bool isValid(std::string* errMsg) const;
- // Calling get*() methods when the member is not set results in undefined behavior
- const OID getClusterId() const {
- dassert(_isClusterIdSet);
- return _clusterId;
- }
+ /**
+ * Returns the BSON representation of the entry.
+ */
+ BSONObj toBSON() const;
- // Optional Fields
- void setUpgradeId(OID upgradeId) {
- _upgradeId = upgradeId;
- _isUpgradeIdSet = true;
- }
+ /**
+ * Clears and populates the internal state using the 'source' BSON object if the
+ * latter contains valid values. Otherwise sets errMsg and returns false.
+ */
+ bool parseBSON(const BSONObj& source, std::string* errMsg);
- void unsetUpgradeId() { _isUpgradeIdSet = false; }
+ /**
+ * Clears the internal state.
+ */
+ void clear();
- bool isUpgradeIdSet() const {
- return _isUpgradeIdSet || upgradeId.hasDefault();
- }
+ /**
+ * Copies all the fields present in 'this' to 'other'.
+ */
+ void cloneTo(VersionType* other) const;
- // Calling get*() methods when the member is not set and has no default results in undefined
- // behavior
- OID getUpgradeId() const {
- if (_isUpgradeIdSet) {
- return _upgradeId;
- } else {
- dassert(upgradeId.hasDefault());
- return upgradeId.getDefault();
- }
- }
- void setUpgradeState(const BSONObj& upgradeState) {
- _upgradeState = upgradeState.getOwned();
- _isUpgradeStateSet = true;
+ /**
+ * Returns a std::string representation of the current internal state.
+ */
+ std::string toString() const;
+
+ //
+ // individual field accessors
+ //
+
+ // Mandatory Fields
+ void setMinCompatibleVersion(const int minCompatibleVersion) {
+ _minCompatibleVersion = minCompatibleVersion;
+ _isMinCompatibleVersionSet = true;
+ }
+
+ void unsetMinCompatibleVersion() {
+ _isMinCompatibleVersionSet = false;
+ }
+
+ bool isMinCompatibleVersionSet() const {
+ return _isMinCompatibleVersionSet;
+ }
+
+ // Calling get*() methods when the member is not set results in undefined behavior
+ int getMinCompatibleVersion() const {
+ dassert(_isMinCompatibleVersionSet);
+ return _minCompatibleVersion;
+ }
+
+ void setCurrentVersion(const int currentVersion) {
+ _currentVersion = currentVersion;
+ _isCurrentVersionSet = true;
+ }
+
+ void unsetCurrentVersion() {
+ _isCurrentVersionSet = false;
+ }
+
+ bool isCurrentVersionSet() const {
+ return _isCurrentVersionSet;
+ }
+
+ // Calling get*() methods when the member is not set results in undefined behavior
+ int getCurrentVersion() const {
+ dassert(_isCurrentVersionSet);
+ return _currentVersion;
+ }
+
+ void setExcludingMongoVersions(const BSONArray& excludingMongoVersions) {
+ _excludingMongoVersions = excludingMongoVersions;
+ _isExcludingMongoVersionsSet = true;
+ }
+
+ void unsetExcludingMongoVersions() {
+ _isExcludingMongoVersionsSet = false;
+ }
+
+ bool isExcludingMongoVersionsSet() const {
+ return _isExcludingMongoVersionsSet || excludingMongoVersions.hasDefault();
+ }
+
+ // Calling get*() methods when the member is not set and has no default results in undefined
+ // behavior
+ const BSONArray getExcludingMongoVersions() const {
+ if (_isExcludingMongoVersionsSet) {
+ return _excludingMongoVersions;
+ } else {
+ dassert(excludingMongoVersions.hasDefault());
+ return excludingMongoVersions.getDefault();
}
-
- void unsetUpgradeState() { _isUpgradeStateSet = false; }
-
- bool isUpgradeStateSet() const {
- return _isUpgradeStateSet || upgradeState.hasDefault();
+ }
+
+ void setClusterId(const OID clusterId) {
+ _clusterId = clusterId;
+ _isClusterIdSet = true;
+ }
+
+ void unsetClusterId() {
+ _isClusterIdSet = false;
+ }
+
+ bool isClusterIdSet() const {
+ return _isClusterIdSet;
+ }
+
+ // Calling get*() methods when the member is not set results in undefined behavior
+ const OID getClusterId() const {
+ dassert(_isClusterIdSet);
+ return _clusterId;
+ }
+
+ // Optional Fields
+ void setUpgradeId(OID upgradeId) {
+ _upgradeId = upgradeId;
+ _isUpgradeIdSet = true;
+ }
+
+ void unsetUpgradeId() {
+ _isUpgradeIdSet = false;
+ }
+
+ bool isUpgradeIdSet() const {
+ return _isUpgradeIdSet || upgradeId.hasDefault();
+ }
+
+ // Calling get*() methods when the member is not set and has no default results in undefined
+ // behavior
+ OID getUpgradeId() const {
+ if (_isUpgradeIdSet) {
+ return _upgradeId;
+ } else {
+ dassert(upgradeId.hasDefault());
+ return upgradeId.getDefault();
}
-
- // Calling get*() methods when the member is not set and has no default results in undefined
- // behavior
- BSONObj getUpgradeState() const {
- if (_isUpgradeStateSet) {
- return _upgradeState;
- } else {
- dassert(upgradeState.hasDefault());
- return upgradeState.getDefault();
- }
+ }
+ void setUpgradeState(const BSONObj& upgradeState) {
+ _upgradeState = upgradeState.getOwned();
+ _isUpgradeStateSet = true;
+ }
+
+ void unsetUpgradeState() {
+ _isUpgradeStateSet = false;
+ }
+
+ bool isUpgradeStateSet() const {
+ return _isUpgradeStateSet || upgradeState.hasDefault();
+ }
+
+ // Calling get*() methods when the member is not set and has no default results in undefined
+ // behavior
+ BSONObj getUpgradeState() const {
+ if (_isUpgradeStateSet) {
+ return _upgradeState;
+ } else {
+ dassert(upgradeState.hasDefault());
+ return upgradeState.getDefault();
}
-
- private:
- // Convention: (M)andatory, (O)ptional, (S)pecial rule.
- int _minCompatibleVersion; // (M) minimum compatible version
- bool _isMinCompatibleVersionSet;
- int _currentVersion; // (M) current version
- bool _isCurrentVersionSet;
- BSONArray _excludingMongoVersions; // (O) range of disallowed versions to upgrade to
- bool _isExcludingMongoVersionsSet;
- OID _clusterId; // (M) clusterId
- bool _isClusterIdSet;
- OID _upgradeId; // (O) upgrade id of current or last upgrade
- bool _isUpgradeIdSet;
- BSONObj _upgradeState; // (O) upgrade state of current or last upgrade
- bool _isUpgradeStateSet;
- };
-
-} // namespace mongo
+ }
+
+private:
+ // Convention: (M)andatory, (O)ptional, (S)pecial rule.
+ int _minCompatibleVersion; // (M) minimum compatible version
+ bool _isMinCompatibleVersionSet;
+ int _currentVersion; // (M) current version
+ bool _isCurrentVersionSet;
+ BSONArray _excludingMongoVersions; // (O) range of disallowed versions to upgrade to
+ bool _isExcludingMongoVersionsSet;
+ OID _clusterId; // (M) clusterId
+ bool _isClusterIdSet;
+ OID _upgradeId; // (O) upgrade id of current or last upgrade
+ bool _isUpgradeIdSet;
+ BSONObj _upgradeState; // (O) upgrade state of current or last upgrade
+ bool _isUpgradeStateSet;
+};
+
+} // namespace mongo