summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun Verch <shaun.verch@10gen.com>2013-01-25 12:47:32 +0000
committerShaun Verch <shaun.verch@10gen.com>2013-01-25 16:11:33 +0000
commit7f88e248007a5aa720ad1b712a235b867e63caa4 (patch)
tree90cc2965814b3438d29ca7b13d5ad641a6f50ff5
parenta0a114ba8baf09ed45d9ea8f1307fc604d12c1e7 (diff)
downloadmongo-7f88e248007a5aa720ad1b712a235b867e63caa4.tar.gz
Changed mongoVersion and configVersion to optional for backwards compatibility
-rw-r--r--src/mongo/s/type_mongos.cpp8
-rw-r--r--src/mongo/s/type_mongos.h42
-rw-r--r--src/mongo/s/type_mongos_test.cpp8
3 files changed, 33 insertions, 25 deletions
diff --git a/src/mongo/s/type_mongos.cpp b/src/mongo/s/type_mongos.cpp
index 8f5febb240b..ae515a94d9d 100644
--- a/src/mongo/s/type_mongos.cpp
+++ b/src/mongo/s/type_mongos.cpp
@@ -61,14 +61,6 @@ namespace mongo {
*errMsg = stream() << "missing " << waiting.name() << " field";
return false;
}
- if (!_isMongoVersionSet) {
- *errMsg = stream() << "missing " << mongoVersion.name() << " field";
- return false;
- }
- if (!_isConfigVersionSet) {
- *errMsg = stream() << "missing " << configVersion.name() << " field";
- return false;
- }
return true;
}
diff --git a/src/mongo/s/type_mongos.h b/src/mongo/s/type_mongos.h
index d69290883b4..7c3d412bd6f 100644
--- a/src/mongo/s/type_mongos.h
+++ b/src/mongo/s/type_mongos.h
@@ -168,6 +168,7 @@ namespace mongo {
return _waiting;
}
+ // Optional Fields
void setMongoVersion(const StringData& mongoVersion) {
_mongoVersion = mongoVersion.toString();
_isMongoVersionSet = true;
@@ -175,14 +176,20 @@ namespace mongo {
void unsetMongoVersion() { _isMongoVersionSet = false; }
- bool isMongoVersionSet() const { return _isMongoVersionSet; }
-
- // Calling get*() methods when the member is not set results in undefined behavior
- const std::string& getMongoVersion() const {
- dassert(_isMongoVersionSet);
- return _mongoVersion;
+ bool isMongoVersionSet() const {
+ return _isMongoVersionSet || mongoVersion.hasDefault();
}
+ // Calling get*() methods when the member is not set and has no default results in undefined
+ // behavior
+ std::string getMongoVersion() const {
+ if (_isMongoVersionSet) {
+ return _mongoVersion;
+ } else {
+ dassert(mongoVersion.hasDefault());
+ return mongoVersion.getDefault();
+ }
+ }
void setConfigVersion(const int configVersion) {
_configVersion = configVersion;
_isConfigVersionSet = true;
@@ -190,15 +197,20 @@ namespace mongo {
void unsetConfigVersion() { _isConfigVersionSet = false; }
- bool isConfigVersionSet() const { return _isConfigVersionSet; }
-
- // Calling get*() methods when the member is not set results in undefined behavior
- const int getConfigVersion() const {
- dassert(_isConfigVersionSet);
- return _configVersion;
+ bool isConfigVersionSet() const {
+ return _isConfigVersionSet || configVersion.hasDefault();
}
- // Optional Fields
+ // Calling get*() methods when the member is not set and has no default results in undefined
+ // behavior
+ int getConfigVersion() const {
+ if (_isConfigVersionSet) {
+ return _configVersion;
+ } else {
+ dassert(configVersion.hasDefault());
+ return configVersion.getDefault();
+ }
+ }
private:
// Convention: (M)andatory, (O)ptional, (S)pecial rule.
@@ -210,9 +222,9 @@ namespace mongo {
bool _isUpSet;
bool _waiting; // (M) for testing purposes
bool _isWaitingSet;
- std::string _mongoVersion; // (M) the mongodb version of the pinging mongos
+ std::string _mongoVersion; // (O) the mongodb version of the pinging mongos
bool _isMongoVersionSet;
- int _configVersion; // (M) the config version of the pinging mongos
+ int _configVersion; // (O) the config version of the pinging mongos
bool _isConfigVersionSet;
};
diff --git a/src/mongo/s/type_mongos_test.cpp b/src/mongo/s/type_mongos_test.cpp
index 0d27d057db6..4f2a69e9ccd 100644
--- a/src/mongo/s/type_mongos_test.cpp
+++ b/src/mongo/s/type_mongos_test.cpp
@@ -117,7 +117,9 @@ namespace {
ASSERT_TRUE(mongos.isWaitingSet());
ASSERT_FALSE(mongos.isMongoVersionSet());
ASSERT_TRUE(mongos.isConfigVersionSet());
- ASSERT_FALSE(mongos.isValid(NULL));
+ /* NOTE: mongoVersion should eventually become mandatory, but is optional now for backward
+ * compatibility reasons */
+ ASSERT_TRUE(mongos.isValid(NULL));
}
TEST(Validity, MissingConfigVersion) {
@@ -136,7 +138,9 @@ namespace {
ASSERT_TRUE(mongos.isWaitingSet());
ASSERT_TRUE(mongos.isMongoVersionSet());
ASSERT_FALSE(mongos.isConfigVersionSet());
- ASSERT_FALSE(mongos.isValid(NULL));
+ /* NOTE: configVersion should eventually become mandatory, but is optional now for backward
+ * compatibility reasons */
+ ASSERT_TRUE(mongos.isValid(NULL));
}
TEST(Validity, Valid) {