From 7f88e248007a5aa720ad1b712a235b867e63caa4 Mon Sep 17 00:00:00 2001 From: Shaun Verch Date: Fri, 25 Jan 2013 12:47:32 +0000 Subject: Changed mongoVersion and configVersion to optional for backwards compatibility --- src/mongo/s/type_mongos.cpp | 8 -------- src/mongo/s/type_mongos.h | 42 ++++++++++++++++++++++++++-------------- src/mongo/s/type_mongos_test.cpp | 8 ++++++-- 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) { -- cgit v1.2.1