diff options
-rw-r--r-- | src/mongo/db/repl/member_config.h | 8 | ||||
-rw-r--r-- | src/mongo/db/repl/member_config_test.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_set_config_checks.cpp | 39 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_set_config_checks_test.cpp | 68 |
4 files changed, 36 insertions, 88 deletions
diff --git a/src/mongo/db/repl/member_config.h b/src/mongo/db/repl/member_config.h index 39fbc30750b..d6bb75622f3 100644 --- a/src/mongo/db/repl/member_config.h +++ b/src/mongo/db/repl/member_config.h @@ -76,14 +76,6 @@ public: static const std::string kConfigVoterTagName; /** - * Inline `kMaxUserMemberId` to allow others use - * the constant without linking to `member_config.cpp`. - * - * Maximum allowed member id for new nodes added by user. - */ - inline static const int kMaxUserMemberId = 255; - - /** * Construct a MemberConfig from the contents of "mcfg". * * If "mcfg" describes any tags, builds ReplSetTags for this diff --git a/src/mongo/db/repl/member_config_test.cpp b/src/mongo/db/repl/member_config_test.cpp index 64bafe6330c..8b52a238b16 100644 --- a/src/mongo/db/repl/member_config_test.cpp +++ b/src/mongo/db/repl/member_config_test.cpp @@ -89,23 +89,22 @@ TEST(MemberConfig, ParseMemberConfigId) { } // Pass cases { - MemberConfig mc(BSON("_id" << 0 << "host" << "localhost:12345"), &tagConfig); ASSERT_EQUALS(MemberId(0), mc.getId()); } { - MemberConfig mc(BSON("_id" << MemberConfig::kMaxUserMemberId << "host" + MemberConfig mc(BSON("_id" << 255 << "host" << "localhost:12345"), &tagConfig); - ASSERT_EQUALS(MemberId(MemberConfig::kMaxUserMemberId), mc.getId()); + ASSERT_EQUALS(MemberId(255), mc.getId()); } { - MemberConfig mc(BSON("_id" << (MemberConfig::kMaxUserMemberId + 1) << "host" + MemberConfig mc(BSON("_id" << 256 << "host" << "localhost:12345"), &tagConfig); - ASSERT_EQUALS(MemberId(MemberConfig::kMaxUserMemberId + 1), mc.getId()); + ASSERT_EQUALS(MemberId(256), mc.getId()); } } diff --git a/src/mongo/db/repl/repl_set_config_checks.cpp b/src/mongo/db/repl/repl_set_config_checks.cpp index df7049f9d25..b768317f041 100644 --- a/src/mongo/db/repl/repl_set_config_checks.cpp +++ b/src/mongo/db/repl/repl_set_config_checks.cpp @@ -142,35 +142,6 @@ Status validateSingleNodeChange(const ReplSetConfig& oldConfig, const ReplSetCon } /** - * Returns ErrorCodes::BadValue if the user tries to add new nodes with member id greater than - * MemberConfig::kMaxUserMemberId(255). - * - * validateMemberId() will be called only for replSetReconfig and replSetInitiate commands. - * - * TODO SERVER-48345: Remove this method on MongoDB v4.6 as we allow users to add new nodes - * with member id > MemberConfig::kMaxUserMemberId(255). - */ -Status validateMemberId(const ReplSetConfig& newConfig, - const ReplSetConfig& oldConfig = ReplSetConfig()) { - for (ReplSetConfig::MemberIterator mNew = newConfig.membersBegin(); - mNew != newConfig.membersEnd(); - ++mNew) { - auto mNewConfigId = mNew->getId().getData(); - // Existing members are allowed to have member id greater than kMaxUserMemberId. And, - // it can happen only if this node was previously running on MongoDB version greater - // than v4.4. - if (oldConfig.findMemberIndexByConfigId(mNewConfigId) == -1 && - mNewConfigId > MemberConfig::kMaxUserMemberId) { - return Status(ErrorCodes::BadValue, - str::stream() - << "Replica set configuration contains new members with " - << "member id greater than " << MemberConfig::kMaxUserMemberId); - } - } - return Status::OK(); -} - -/** * Compares two initialized and validated replica set configurations, and checks to * see if "newConfig" is a legal successor configuration to "oldConfig". * @@ -360,11 +331,6 @@ StatusWith<int> validateConfigForInitiate(ReplicationCoordinatorExternalState* e return StatusWith<int>(status); } - status = validateMemberId(newConfig); - if (!status.isOK()) { - return status; - } - status = newConfig.checkIfWriteConcernCanBeSatisfied(newConfig.getDefaultWriteConcern()); if (!status.isOK()) { return status.withContext( @@ -415,11 +381,6 @@ Status validateConfigForReconfig(const ReplSetConfig& oldConfig, return status; } - status = validateMemberId(newConfig, oldConfig); - if (!status.isOK()) { - return status; - } - // For non-force reconfigs, verify that the reconfig only adds or removes a single node. // This ensures that all quorums of the new config overlap with all quorums of the old // config. diff --git a/src/mongo/db/repl/repl_set_config_checks_test.cpp b/src/mongo/db/repl/repl_set_config_checks_test.cpp index 0b6f573cc18..efa438491b6 100644 --- a/src/mongo/db/repl/repl_set_config_checks_test.cpp +++ b/src/mongo/db/repl/repl_set_config_checks_test.cpp @@ -89,16 +89,15 @@ TEST_F(ServiceContextTest, ValidateConfigForInitiate_memberId) { // Config with Member id > 255. OID newReplSetId = OID::gen(); - auto invalidConfig = ReplSetConfig::parseForInitiate( - BSON("_id" - << "rs0" - << "version" << 1 << "protocolVersion" << 1 << "members" - << BSON_ARRAY(BSON("_id" << (MemberConfig::kMaxUserMemberId + 1) << "host" - << "h1"))), - newReplSetId); - ASSERT_EQUALS( - ErrorCodes::BadValue, - validateConfigForInitiate(&rses, invalidConfig, getGlobalServiceContext()).getStatus()); + auto validConfig = + ReplSetConfig::parseForInitiate(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 + << "members" + << BSON_ARRAY(BSON("_id" << 256 << "host" + << "h1"))), + newReplSetId); + ASSERT_OK(validateConfigForInitiate(&rses, validConfig, getGlobalServiceContext()).getStatus()); } TEST_F(ServiceContextTest, ValidateConfigForInitiate_MustFindSelf) { @@ -341,36 +340,33 @@ TEST_F(ServiceContextTest, ValidateConfigForReconfig_memberId) { << "version" << 1 << "protocolVersion" << 1 << "members" << BSON_ARRAY(BSON("_id" << 1 << "host" << "h1")))); - newConfig = ReplSetConfig::parse( - BSON("_id" - << "rs0" - << "version" << 2 << "protocolVersion" << 1 << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1") - << BSON("_id" << (MemberConfig::kMaxUserMemberId + 1) << "host" - << "h2")))); + newConfig = ReplSetConfig::parse(BSON("_id" + << "rs0" + << "version" << 2 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1") + << BSON("_id" << 256 << "host" + << "h2")))); ASSERT_OK(oldConfig.validate()); ASSERT_OK(newConfig.validate()); - ASSERT_EQUALS(ErrorCodes::BadValue, validateConfigForReconfig(oldConfig, newConfig, false)); + ASSERT_OK(validateConfigForReconfig(oldConfig, newConfig, false)); // Case 2: Change the member config setting for the existing member with member id > 255. - oldConfig = ReplSetConfig::parse( - BSON("_id" - << "rs0" - << "version" << 1 << "protocolVersion" << 1 << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1") - << BSON("_id" << (MemberConfig::kMaxUserMemberId + 1) << "host" - << "h2")))); - newConfig = ReplSetConfig::parse( - BSON("_id" - << "rs0" - << "version" << 2 << "protocolVersion" << 1 << "members" - << BSON_ARRAY(BSON("_id" << 1 << "host" - << "h1") - << BSON("_id" << (MemberConfig::kMaxUserMemberId + 1) << "host" - << "h2" - << "priority" << 0)))); + oldConfig = ReplSetConfig::parse(BSON("_id" + << "rs0" + << "version" << 1 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1") + << BSON("_id" << 256 << "host" + << "h2")))); + newConfig = ReplSetConfig::parse(BSON("_id" + << "rs0" + << "version" << 2 << "protocolVersion" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 1 << "host" + << "h1") + << BSON("_id" << 256 << "host" + << "h2" + << "priority" << 0)))); ASSERT_OK(oldConfig.validate()); ASSERT_OK(newConfig.validate()); ASSERT_OK(validateConfigForReconfig(oldConfig, newConfig, false)); |