diff options
-rw-r--r-- | src/mongo/db/repl/check_quorum_for_config_change_test.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_fetcher_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl_test.cpp | 74 | ||||
-rw-r--r-- | src/mongo/db/repl/topology_coordinator.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/repl/topology_coordinator_v1_test.cpp | 3 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/repl_set_metadata.cpp | 13 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/repl_set_metadata.h | 11 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/repl_set_metadata_test.cpp | 37 | ||||
-rw-r--r-- | src/mongo/s/catalog/sharding_catalog_test.cpp | 4 |
10 files changed, 95 insertions, 54 deletions
diff --git a/src/mongo/db/repl/check_quorum_for_config_change_test.cpp b/src/mongo/db/repl/check_quorum_for_config_change_test.cpp index e84b1881961..5526328e077 100644 --- a/src/mongo/db/repl/check_quorum_for_config_change_test.cpp +++ b/src/mongo/db/repl/check_quorum_for_config_change_test.cpp @@ -447,6 +447,7 @@ TEST_F(CheckQuorumForInitiate, QuorumCheckFailedDueToSetIdMismatch) { {opTime, wallTime}, opTime, rsConfig.getConfigVersion(), + rsConfig.getConfigTerm(), unexpectedId, rpc::ReplSetMetadata::kNoPrimary, -1, diff --git a/src/mongo/db/repl/oplog_fetcher_test.cpp b/src/mongo/db/repl/oplog_fetcher_test.cpp index 0309db2f51a..2161222f77c 100644 --- a/src/mongo/db/repl/oplog_fetcher_test.cpp +++ b/src/mongo/db/repl/oplog_fetcher_test.cpp @@ -336,7 +336,7 @@ const rpc::OplogQueryMetadata OplogFetcherTest::staleOqMetadata = rpc::OplogQuer {staleOpTime, staleWallTime}, staleOpTime, rbid, primaryIndex, syncSourceIndex); const rpc::ReplSetMetadata OplogFetcherTest::replSetMetadata = rpc::ReplSetMetadata( - 1, OpTimeAndWallTime(), OpTime(), 1, OID(), primaryIndex, syncSourceIndex, false); + 1, OpTimeAndWallTime(), OpTime(), 1, 0, OID(), primaryIndex, syncSourceIndex, false); void OplogFetcherTest::setUp() { executor::ThreadPoolExecutorTest::setUp(); diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp index b497d407730..ed453a28f1f 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp @@ -784,6 +784,7 @@ TEST_F(ReplCoordHBV1Test, IgnoreTheContentsOfMetadataWhenItsReplicaSetIdDoesNotM {opTime, Date_t()}, opTime, rsConfig.getConfigVersion(), + 0, unexpectedId, 1, -1, @@ -870,6 +871,7 @@ TEST_F(ReplCoordHBV1Test, {commitPoint, Date_t() + Seconds(commitPoint.getSecs())}, // committed OpTime commitPoint, // visibleOpTime config.getConfigVersion(), + 0, {}, // replset id 1, // currentPrimaryIndex, 1, // currentSyncSourceIndex @@ -946,6 +948,7 @@ TEST_F(ReplCoordHBV1Test, LastCommittedOpTimeOnlyUpdatesFromHeartbeatIfNotInStar {commitPoint, Date_t() + Seconds(commitPoint.getSecs())}, // committed OpTime commitPoint, // visibleOpTime config.getConfigVersion(), + 0, {}, // replset id 1, // currentPrimaryIndex, 1, // currentSyncSourceIndex diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp index 7d1498d80b2..01b81e95d7c 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp @@ -5621,8 +5621,8 @@ TEST_F(ReplCoordTest, DoNotIgnoreTheContentsOfMetadataWhenItsConfigVersionDoesNo "lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 2) << "lastCommittedWall" << Date_t() + Seconds(100) << "lastOpVisible" << BSON("ts" << Timestamp(10, 0) << "t" << 2) << "configVersion" - << lowerConfigVersion << "primaryIndex" << 2 << "term" << 2 - << "syncSourceIndex" << 1 << "isPrimary" << true))); + << lowerConfigVersion << "configTerm" << 2 << "primaryIndex" << 2 + << "term" << 2 << "syncSourceIndex" << 1 << "isPrimary" << true))); getReplCoord()->processReplSetMetadata(metadata.getValue()); // term should advance ASSERT_EQUALS(2, getReplCoord()->getTerm()); @@ -5634,8 +5634,8 @@ TEST_F(ReplCoordTest, DoNotIgnoreTheContentsOfMetadataWhenItsConfigVersionDoesNo "lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 2) << "lastCommittedWall" << Date_t() + Seconds(100) << "lastOpVisible" << BSON("ts" << Timestamp(10, 0) << "t" << 2) << "configVersion" - << higherConfigVersion << "primaryIndex" << 2 << "term" << 2 - << "syncSourceIndex" << 1 << "isPrimary" << true))); + << higherConfigVersion << "configTerm" << 2 << "primaryIndex" << 2 + << "term" << 2 << "syncSourceIndex" << 1 << "isPrimary" << true))); getReplCoord()->processReplSetMetadata(metadata2.getValue()); // term should advance ASSERT_EQUALS(2, getReplCoord()->getTerm()); @@ -5705,12 +5705,12 @@ TEST_F(ReplCoordTest, UpdateTermWhenTheTermFromMetadataIsNewerButNeverUpdateCurr // higher term, should change StatusWith<rpc::ReplSetMetadata> metadata = rpc::ReplSetMetadata::readFromMetadata(BSON( - rpc::kReplSetMetadataFieldName - << BSON("lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 3) - << "lastCommittedWall" << Date_t() + Seconds(100) - << "lastOpVisible" << BSON("ts" << Timestamp(10, 0) << "t" << 3) - << "configVersion" << 2 << "primaryIndex" << 2 << "term" << 3 - << "syncSourceIndex" << 1 << "isPrimary" << true))); + rpc::kReplSetMetadataFieldName << BSON( + "lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 3) << "lastCommittedWall" + << Date_t() + Seconds(100) << "lastOpVisible" + << BSON("ts" << Timestamp(10, 0) << "t" << 3) << "configVersion" << 2 + << "configTerm" << 2 << "primaryIndex" << 2 << "term" << 3 + << "syncSourceIndex" << 1 << "isPrimary" << true))); getReplCoord()->processReplSetMetadata(metadata.getValue()); ASSERT_EQUALS(3, getReplCoord()->getTerm()); ASSERT_EQUALS(-1, getTopoCoord().getCurrentPrimaryIndex()); @@ -5718,12 +5718,12 @@ TEST_F(ReplCoordTest, UpdateTermWhenTheTermFromMetadataIsNewerButNeverUpdateCurr // lower term, should not change StatusWith<rpc::ReplSetMetadata> metadata2 = rpc::ReplSetMetadata::readFromMetadata(BSON( - rpc::kReplSetMetadataFieldName - << BSON("lastOpCommitted" << BSON("ts" << Timestamp(11, 0) << "t" << 3) - << "lastCommittedWall" << Date_t() + Seconds(100) - << "lastOpVisible" << BSON("ts" << Timestamp(11, 0) << "t" << 3) - << "configVersion" << 2 << "primaryIndex" << 1 << "term" << 2 - << "syncSourceIndex" << 1 << "isPrimary" << true))); + rpc::kReplSetMetadataFieldName << BSON( + "lastOpCommitted" << BSON("ts" << Timestamp(11, 0) << "t" << 3) << "lastCommittedWall" + << Date_t() + Seconds(100) << "lastOpVisible" + << BSON("ts" << Timestamp(11, 0) << "t" << 3) << "configVersion" << 2 + << "configTerm" << 2 << "primaryIndex" << 1 << "term" << 2 + << "syncSourceIndex" << 1 << "isPrimary" << true))); getReplCoord()->processReplSetMetadata(metadata2.getValue()); ASSERT_EQUALS(3, getReplCoord()->getTerm()); ASSERT_EQUALS(-1, getTopoCoord().getCurrentPrimaryIndex()); @@ -5731,12 +5731,12 @@ TEST_F(ReplCoordTest, UpdateTermWhenTheTermFromMetadataIsNewerButNeverUpdateCurr // same term, should not change StatusWith<rpc::ReplSetMetadata> metadata3 = rpc::ReplSetMetadata::readFromMetadata(BSON( - rpc::kReplSetMetadataFieldName - << BSON("lastOpCommitted" << BSON("ts" << Timestamp(11, 0) << "t" << 3) - << "lastCommittedWall" << Date_t() + Seconds(100) - << "lastOpVisible" << BSON("ts" << Timestamp(11, 0) << "t" << 3) - << "configVersion" << 2 << "primaryIndex" << 1 << "term" << 3 - << "syncSourceIndex" << 1 << "isPrimary" << true))); + rpc::kReplSetMetadataFieldName << BSON( + "lastOpCommitted" << BSON("ts" << Timestamp(11, 0) << "t" << 3) << "lastCommittedWall" + << Date_t() + Seconds(100) << "lastOpVisible" + << BSON("ts" << Timestamp(11, 0) << "t" << 3) << "configVersion" << 2 + << "configTerm" << 2 << "primaryIndex" << 1 << "term" << 3 + << "syncSourceIndex" << 1 << "isPrimary" << true))); getReplCoord()->processReplSetMetadata(metadata3.getValue()); ASSERT_EQUALS(3, getReplCoord()->getTerm()); ASSERT_EQUALS(-1, getTopoCoord().getCurrentPrimaryIndex()); @@ -5767,12 +5767,13 @@ TEST_F(ReplCoordTest, // Higher term - should update term but not last committed optime. StatusWith<rpc::ReplSetMetadata> metadata = rpc::ReplSetMetadata::readFromMetadata(BSON( - rpc::kReplSetMetadataFieldName << BSON( - "lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 3) << "lastCommittedWall" - << Date_t() + Seconds(100) << "lastOpVisible" - << BSON("ts" << Timestamp(10, 0) << "t" << 3) << "configVersion" - << config.getConfigVersion() << "primaryIndex" << 1 << "term" << 3 - << "syncSourceIndex" << 1 << "isPrimary" << true))); + rpc::kReplSetMetadataFieldName + << BSON("lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 3) + << "lastCommittedWall" << Date_t() + Seconds(100) + << "lastOpVisible" << BSON("ts" << Timestamp(10, 0) << "t" << 3) + << "configVersion" << config.getConfigVersion() << "configTerm" + << config.getConfigTerm() << "primaryIndex" << 1 << "term" << 3 + << "syncSourceIndex" << 1 << "isPrimary" << true))); BSONObjBuilder responseBuilder; ASSERT_OK(metadata.getValue().writeToMetadata(&responseBuilder)); @@ -5827,7 +5828,7 @@ TEST_F(ReplCoordTest, AdvanceCommitPointFromSyncSourceCanSetCommitPointToLastApp TEST_F(ReplCoordTest, PrepareOplogQueryMetadata) { assertStartSuccess(BSON("_id" << "mySet" - << "version" << 2 << "members" + << "version" << 2 << "term" << 0 << "members" << BSON_ARRAY(BSON("host" << "node1:12345" << "_id" << 0) @@ -5876,6 +5877,7 @@ TEST_F(ReplCoordTest, PrepareOplogQueryMetadata) { ASSERT_EQ(replMetadata.getValue().getLastOpCommitted().wallTime, wallTime1); ASSERT_EQ(replMetadata.getValue().getLastOpVisible(), OpTime()); ASSERT_EQ(replMetadata.getValue().getConfigVersion(), 2); + ASSERT_EQ(replMetadata.getValue().getConfigTerm(), 0); ASSERT_EQ(replMetadata.getValue().getTerm(), 0); ASSERT_EQ(replMetadata.getValue().getSyncSourceIndex(), -1); ASSERT_EQ(replMetadata.getValue().getPrimaryIndex(), -1); @@ -5906,12 +5908,13 @@ TEST_F(ReplCoordTest, TermAndLastCommittedOpTimeUpdatedFromHeartbeatWhenArbiter) // Higher term - should update term and lastCommittedOpTime since arbiters learn of the // commit point via heartbeats. StatusWith<rpc::ReplSetMetadata> metadata = rpc::ReplSetMetadata::readFromMetadata(BSON( - rpc::kReplSetMetadataFieldName << BSON( - "lastOpCommitted" << BSON("ts" << Timestamp(10, 1) << "t" << 3) << "lastCommittedWall" - << Date_t() + Seconds(100) << "lastOpVisible" - << BSON("ts" << Timestamp(10, 1) << "t" << 3) << "configVersion" - << config.getConfigVersion() << "primaryIndex" << 1 << "term" << 3 - << "syncSourceIndex" << 1 << "isPrimary" << true))); + rpc::kReplSetMetadataFieldName + << BSON("lastOpCommitted" << BSON("ts" << Timestamp(10, 1) << "t" << 3) + << "lastCommittedWall" << Date_t() + Seconds(100) + << "lastOpVisible" << BSON("ts" << Timestamp(10, 1) << "t" << 3) + << "configVersion" << config.getConfigVersion() << "configTerm" + << config.getConfigTerm() << "primaryIndex" << 1 << "term" << 3 + << "syncSourceIndex" << 1 << "isPrimary" << true))); BSONObjBuilder responseBuilder; ASSERT_OK(metadata.getValue().writeToMetadata(&responseBuilder)); @@ -6628,6 +6631,7 @@ TEST_F(ReplCoordTest, UpdatePositionCmdHasMetadata) { {optime, Date_t() + Seconds(optime.getSecs())}, optime, 1, + 0, OID(), -1, 1, diff --git a/src/mongo/db/repl/topology_coordinator.cpp b/src/mongo/db/repl/topology_coordinator.cpp index 88be564cd2a..e6f18e4ec02 100644 --- a/src/mongo/db/repl/topology_coordinator.cpp +++ b/src/mongo/db/repl/topology_coordinator.cpp @@ -3024,6 +3024,7 @@ rpc::ReplSetMetadata TopologyCoordinator::prepareReplSetMetadata( _lastCommittedOpTimeAndWallTime, lastVisibleOpTime, _rsConfig.getConfigVersion(), + _rsConfig.getConfigTerm(), _rsConfig.getReplicaSetId(), _currentPrimaryIndex, _rsConfig.findMemberIndexByHostAndPort(getSyncSourceAddress()), diff --git a/src/mongo/db/repl/topology_coordinator_v1_test.cpp b/src/mongo/db/repl/topology_coordinator_v1_test.cpp index bffb58ece9a..2e919421d53 100644 --- a/src/mongo/db/repl/topology_coordinator_v1_test.cpp +++ b/src/mongo/db/repl/topology_coordinator_v1_test.cpp @@ -226,6 +226,7 @@ protected: OpTimeAndWallTime(), visibleOpTime, configIn, + 0, OID(), primaryIndex, syncSourceIndex, @@ -4386,7 +4387,7 @@ TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenMemberHasYetToHeart TEST_F(HeartbeatResponseTestV1, ShouldNotChangeSyncSourceWhenMemberNotInConfig) { // In this test, the TopologyCoordinator should tell us to change sync sources away from // "host4" since "host4" is absent from the config of version 10. - ReplSetMetadata replMetadata(0, {OpTime(), Date_t()}, OpTime(), 10, OID(), -1, -1, false); + ReplSetMetadata replMetadata(0, {OpTime(), Date_t()}, OpTime(), 10, 0, OID(), -1, -1, false); ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource( HostAndPort("host4"), replMetadata, makeOplogQueryMetadata(), now())); } diff --git a/src/mongo/rpc/metadata/repl_set_metadata.cpp b/src/mongo/rpc/metadata/repl_set_metadata.cpp index 9698ded3eb5..2d01a732960 100644 --- a/src/mongo/rpc/metadata/repl_set_metadata.cpp +++ b/src/mongo/rpc/metadata/repl_set_metadata.cpp @@ -49,6 +49,7 @@ const char kLastOpCommittedFieldName[] = "lastOpCommitted"; const char kLastCommittedWallFieldName[] = "lastCommittedWall"; const char kLastOpVisibleFieldName[] = "lastOpVisible"; const char kConfigVersionFieldName[] = "configVersion"; +const char kConfigTermFieldName[] = "configTerm"; const char kReplicaSetIdFieldName[] = "replicaSetId"; const char kPrimaryIndexFieldName[] = "primaryIndex"; const char kSyncSourceIndexFieldName[] = "syncSourceIndex"; @@ -63,6 +64,7 @@ ReplSetMetadata::ReplSetMetadata(long long term, OpTimeAndWallTime committedOpTime, OpTime visibleOpTime, long long configVersion, + long long configTerm, OID id, int currentPrimaryIndex, int currentSyncSourceIndex, @@ -71,6 +73,7 @@ ReplSetMetadata::ReplSetMetadata(long long term, _lastOpVisible(std::move(visibleOpTime)), _currentTerm(term), _configVersion(configVersion), + _configTerm(configTerm), _replicaSetId(id), _currentPrimaryIndex(currentPrimaryIndex), _currentSyncSourceIndex(currentSyncSourceIndex), @@ -90,6 +93,13 @@ StatusWith<ReplSetMetadata> ReplSetMetadata::readFromMetadata(const BSONObj& met if (!status.isOK()) return status; + // TODO(SERVER-47157): require configTerm. + long long configTerm; + status = bsonExtractIntegerFieldWithDefault( + replMetadataObj, kConfigTermFieldName, OpTime::kUninitializedTerm, &configTerm); + if (!status.isOK()) + return status; + OID id; status = bsonExtractOIDFieldWithDefault(replMetadataObj, kReplicaSetIdFieldName, OID(), &id); if (!status.isOK()) @@ -149,6 +159,7 @@ StatusWith<ReplSetMetadata> ReplSetMetadata::readFromMetadata(const BSONObj& met lastOpCommitted, lastOpVisible, configVersion, + configTerm, id, primaryIndex, syncSourceIndex, @@ -162,6 +173,7 @@ Status ReplSetMetadata::writeToMetadata(BSONObjBuilder* builder) const { replMetadataBuilder.appendDate(kLastCommittedWallFieldName, _lastOpCommitted.wallTime); _lastOpVisible.append(&replMetadataBuilder, kLastOpVisibleFieldName); replMetadataBuilder.append(kConfigVersionFieldName, _configVersion); + replMetadataBuilder.append(kConfigTermFieldName, _configTerm); replMetadataBuilder.append(kReplicaSetIdFieldName, _replicaSetId); replMetadataBuilder.append(kPrimaryIndexFieldName, _currentPrimaryIndex); replMetadataBuilder.append(kSyncSourceIndexFieldName, _currentSyncSourceIndex); @@ -175,6 +187,7 @@ std::string ReplSetMetadata::toString() const { str::stream output; output << "ReplSetMetadata"; output << " Config Version: " << _configVersion; + output << " Config Term: " << _configTerm; output << " Replicaset ID: " << _replicaSetId; output << " Term: " << _currentTerm; output << " Primary Index: " << _currentPrimaryIndex; diff --git a/src/mongo/rpc/metadata/repl_set_metadata.h b/src/mongo/rpc/metadata/repl_set_metadata.h index 02dc867701e..1a34493d967 100644 --- a/src/mongo/rpc/metadata/repl_set_metadata.h +++ b/src/mongo/rpc/metadata/repl_set_metadata.h @@ -58,7 +58,8 @@ public: repl::OpTimeAndWallTime committedOpTime, repl::OpTime visibleOpTime, long long configVersion, - OID replicaSetId, + long long configTerm, + OID id, int currentPrimaryIndex, int currentSyncSourceIndex, boost::optional<bool> isPrimary); @@ -101,6 +102,13 @@ public: } /** + * Returns the ReplSetConfig term number of the sender. + */ + long long getConfigTerm() const { + return _configTerm; + } + + /** * Returns true if the sender has a replica set ID. */ bool hasReplicaSetId() const { @@ -157,6 +165,7 @@ private: repl::OpTime _lastOpVisible; long long _currentTerm = -1; long long _configVersion = -1; + long long _configTerm = repl::OpTime::kUninitializedTerm; OID _replicaSetId; // TODO(SERVER-47125): remove this member variable post-4.4. int _currentPrimaryIndex = kNoPrimary; diff --git a/src/mongo/rpc/metadata/repl_set_metadata_test.cpp b/src/mongo/rpc/metadata/repl_set_metadata_test.cpp index ca89b0f7e64..7aa199fa046 100644 --- a/src/mongo/rpc/metadata/repl_set_metadata_test.cpp +++ b/src/mongo/rpc/metadata/repl_set_metadata_test.cpp @@ -44,10 +44,10 @@ static const OpTime opTime(Timestamp(1234, 100), 5); static const OpTime opTime2(Timestamp(7777, 100), 6); static const Date_t committedWallTime = Date_t() + Seconds(opTime.getSecs()); static const ReplSetMetadata metadata( - 3, {opTime, committedWallTime}, opTime2, 6, OID("abcdefabcdefabcdefabcdef"), 12, -1, false); + 3, {opTime, committedWallTime}, opTime2, 6, 0, OID("abcdefabcdefabcdefabcdef"), 12, -1, false); TEST(ReplResponseMetadataTest, ReplicaSetIdNotSet) { - ASSERT_FALSE(ReplSetMetadata(3, OpTimeAndWallTime(), OpTime(), 6, OID(), 12, -1, false) + ASSERT_FALSE(ReplSetMetadata(3, OpTimeAndWallTime(), OpTime(), 6, 0, OID(), 12, -1, false) .hasReplicaSetId()); } @@ -60,14 +60,15 @@ TEST(ReplResponseMetadataTest, Roundtrip) { BSONObjBuilder builder; metadata.writeToMetadata(&builder).transitional_ignore(); - BSONObj expectedObj(BSON( - kReplSetMetadataFieldName << BSON( - "term" << 3 << "lastOpCommitted" - << BSON("ts" << opTime.getTimestamp() << "t" << opTime.getTerm()) - << "lastCommittedWall" << committedWallTime << "lastOpVisible" - << BSON("ts" << opTime2.getTimestamp() << "t" << opTime2.getTerm()) - << "configVersion" << 6 << "replicaSetId" << metadata.getReplicaSetId() - << "primaryIndex" << 12 << "syncSourceIndex" << -1 << "isPrimary" << false))); + BSONObj expectedObj( + BSON(kReplSetMetadataFieldName + << BSON("term" << 3 << "lastOpCommitted" + << BSON("ts" << opTime.getTimestamp() << "t" << opTime.getTerm()) + << "lastCommittedWall" << committedWallTime << "lastOpVisible" + << BSON("ts" << opTime2.getTimestamp() << "t" << opTime2.getTerm()) + << "configVersion" << 6 << "configTerm" << 0 << "replicaSetId" + << metadata.getReplicaSetId() << "primaryIndex" << 12 + << "syncSourceIndex" << -1 << "isPrimary" << false))); BSONObj serializedObj = builder.obj(); ASSERT_BSONOBJ_EQ(expectedObj, serializedObj); @@ -80,6 +81,7 @@ TEST(ReplResponseMetadataTest, Roundtrip) { ASSERT_EQ(opTime2, clonedMetadata.getLastOpVisible()); ASSERT_EQ(committedWallTime, clonedMetadata.getLastOpCommitted().wallTime); ASSERT_EQ(metadata.getConfigVersion(), clonedMetadata.getConfigVersion()); + ASSERT_EQ(metadata.getConfigTerm(), clonedMetadata.getConfigTerm()); ASSERT_EQ(metadata.getReplicaSetId(), clonedMetadata.getReplicaSetId()); BSONObjBuilder clonedBuilder; @@ -90,22 +92,24 @@ TEST(ReplResponseMetadataTest, Roundtrip) { } TEST(ReplResponseMetadataTest, MetadataCanBeConstructedWhenMissingOplogQueryMetadataFields) { - BSONObj obj(BSON(kReplSetMetadataFieldName - << BSON("term" << 3 << "configVersion" << 6 << "replicaSetId" - << metadata.getReplicaSetId() << "lastCommittedWall" - << committedWallTime << "isPrimary" << false))); + BSONObj obj(BSON(kReplSetMetadataFieldName << BSON( + "term" << 3 << "configVersion" << 6 << "configTerm" << 2 << "replicaSetId" + << metadata.getReplicaSetId() << "lastCommittedWall" + << committedWallTime << "isPrimary" << false))); auto status = ReplSetMetadata::readFromMetadata(obj); ASSERT_OK(status.getStatus()); const auto& metadata = status.getValue(); ASSERT_EQ(metadata.getConfigVersion(), 6); + ASSERT_EQ(metadata.getConfigTerm(), 2); ASSERT_EQ(metadata.getReplicaSetId(), metadata.getReplicaSetId()); ASSERT_EQ(metadata.getTerm(), 3); } -TEST(ReplResponseMetadataTest, MetadataCanBeConstructedWhenMissingIsPrimary) { - // TODO(SERVER-47125): delete this test in 4.6 when we can rely on the isPrimary field. +TEST(ReplResponseMetadataTest, MetadataCanBeConstructedFrom42) { + // TODO(SERVER-47125): delete this test in 4.6 when we can rely on the isPrimary and configTerm + // fields. BSONObj obj( BSON(kReplSetMetadataFieldName << BSON("term" << 3 << "lastOpCommitted" @@ -120,6 +124,7 @@ TEST(ReplResponseMetadataTest, MetadataCanBeConstructedWhenMissingIsPrimary) { const auto& metadata = status.getValue(); ASSERT_FALSE(metadata.getIsPrimary().is_initialized()); + ASSERT_EQUALS(metadata.getConfigTerm(), -1); } } // unnamed namespace diff --git a/src/mongo/s/catalog/sharding_catalog_test.cpp b/src/mongo/s/catalog/sharding_catalog_test.cpp index 6905cfa1e2f..7d5a9ace101 100644 --- a/src/mongo/s/catalog/sharding_catalog_test.cpp +++ b/src/mongo/s/catalog/sharding_catalog_test.cpp @@ -121,6 +121,7 @@ TEST_F(ShardingCatalogClientTest, GetCollectionExisting) { {newOpTime, Date_t() + Seconds(newOpTime.getSecs())}, newOpTime, 100, + 0, OID(), 30, -1, @@ -195,6 +196,7 @@ TEST_F(ShardingCatalogClientTest, GetDatabaseExisting) { {newOpTime, Date_t() + Seconds(newOpTime.getSecs())}, newOpTime, 100, + 0, OID(), 30, -1, @@ -423,6 +425,7 @@ TEST_F(ShardingCatalogClientTest, GetChunksForNSWithSortAndLimit) { {newOpTime, Date_t() + Seconds(newOpTime.getSecs())}, newOpTime, 100, + 0, OID(), 30, -1, @@ -825,6 +828,7 @@ TEST_F(ShardingCatalogClientTest, GetCollectionsValidResultsNoDb) { {newOpTime, Date_t() + Seconds(newOpTime.getSecs())}, newOpTime, 100, + 0, OID(), 30, -1, |