diff options
author | Ali Mir <ali.mir@mongodb.com> | 2020-02-26 15:00:57 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2020-02-26 15:00:57 +0000 |
commit | 687f9be7fa79ac6f3c2025784f942fdcafeb2a5f (patch) | |
tree | fcfb2ffe40332cdb5f7c8a71eb6ba7ddc184f5f6 /src/mongo | |
parent | 952fa6f3f323e5e6cfb4cf996ed1eef4ae52a9d6 (diff) | |
download | mongo-687f9be7fa79ac6f3c2025784f942fdcafeb2a5f.tar.gz |
SERVER-46284 Serialize term -1 as a missing field in repl_set_config.cpp
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/repl/repl_set_config.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_set_config_test.cpp | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/src/mongo/db/repl/repl_set_config.cpp b/src/mongo/db/repl/repl_set_config.cpp index 6b254b60f7e..416970f4905 100644 --- a/src/mongo/db/repl/repl_set_config.cpp +++ b/src/mongo/db/repl/repl_set_config.cpp @@ -864,8 +864,7 @@ BSONObj ReplSetConfig::toBSON() const { configBuilder.append(kIdFieldName, _replSetName); configBuilder.appendIntOrLL(kVersionFieldName, _version); - if (serverGlobalParams.featureCompatibility.isVersion( - ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo44)) { + if (_term != OpTime::kUninitializedTerm) { configBuilder.appendIntOrLL(kTermFieldName, _term); } diff --git a/src/mongo/db/repl/repl_set_config_test.cpp b/src/mongo/db/repl/repl_set_config_test.cpp index 506842f66a3..6e76d6d880f 100644 --- a/src/mongo/db/repl/repl_set_config_test.cpp +++ b/src/mongo/db/repl/repl_set_config_test.cpp @@ -320,6 +320,8 @@ TEST(ReplSetConfig, ParseFailsWithBadOrMissingTermField) { << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345"))))); ASSERT_EQUALS(config.getConfigTerm(), -1); + // Serializing the config to BSON should omit a term field with value -1. + ASSERT_FALSE(config.toBSON().hasField(ReplSetConfig::kTermFieldName)); ASSERT_EQUALS(ErrorCodes::TypeMismatch, config.initialize(BSON("_id" << "rs0" @@ -351,6 +353,7 @@ TEST(ReplSetConfig, ParseFailsWithBadOrMissingTermField) { << BSON_ARRAY(BSON("_id" << 0 << "host" << "localhost:12345"))))); ASSERT_OK(config.validate()); + ASSERT_FALSE(config.toBSON().hasField(ReplSetConfig::kTermFieldName)); ASSERT_OK(config.initialize(BSON("_id" << "rs0" << "version" << 1 << "term" << -2.0 << "protocolVersion" << 1 |