diff options
author | Jason Chan <jason.chan@10gen.com> | 2019-08-05 16:14:34 -0400 |
---|---|---|
committer | Jason Chan <jason.chan@10gen.com> | 2019-08-05 16:14:34 -0400 |
commit | 8c083bf34d40ff64449387378d15b36462ef6f6f (patch) | |
tree | 1c39060b5a0132c7a363a53069b7a837e15ad1a4 /src/mongo/db | |
parent | c1d1fda71c310e7d7a04ccbfbaaa2215b63963b6 (diff) | |
download | mongo-8c083bf34d40ff64449387378d15b36462ef6f6f.tar.gz |
SERVER-42485 Make wall clock times in replication structures required after 4.2
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/repl/check_quorum_for_config_change.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/member_data.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_fetcher.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_set_commands.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_set_heartbeat_response.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_set_heartbeat_response.h | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_set_heartbeat_response_test.cpp | 47 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl_test.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_test_fixture.h | 11 | ||||
-rw-r--r-- | src/mongo/db/repl/reporter.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/topology_coordinator_v1_test.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/repl/update_position_args.cpp | 18 | ||||
-rw-r--r-- | src/mongo/db/repl/update_position_args.h | 2 |
14 files changed, 58 insertions, 79 deletions
diff --git a/src/mongo/db/repl/check_quorum_for_config_change.cpp b/src/mongo/db/repl/check_quorum_for_config_change.cpp index 8f2dfc40664..3faf2b20fa5 100644 --- a/src/mongo/db/repl/check_quorum_for_config_change.cpp +++ b/src/mongo/db/repl/check_quorum_for_config_change.cpp @@ -195,7 +195,7 @@ void QuorumChecker::_tabulateHeartbeatResponse(const RemoteCommandRequest& reque BSONObj resBSON = response.data; ReplSetHeartbeatResponse hbResp; - Status hbStatus = hbResp.initialize(resBSON, 0, /*requireWallTime*/ false); + Status hbStatus = hbResp.initialize(resBSON, 0); if (hbStatus.code() == ErrorCodes::InconsistentReplicaSetNames) { std::string message = str::stream() @@ -226,7 +226,7 @@ void QuorumChecker::_tabulateHeartbeatResponse(const RemoteCommandRequest& reque if (_rsConfig->hasReplicaSetId()) { StatusWith<rpc::ReplSetMetadata> replMetadata = - rpc::ReplSetMetadata::readFromMetadata(response.data, /*requireWallTime*/ false); + rpc::ReplSetMetadata::readFromMetadata(response.data); if (replMetadata.isOK() && replMetadata.getValue().getReplicaSetId().isSet() && _rsConfig->getReplicaSetId() != replMetadata.getValue().getReplicaSetId()) { std::string message = str::stream() diff --git a/src/mongo/db/repl/member_data.cpp b/src/mongo/db/repl/member_data.cpp index 247167bc150..571e83d3a1c 100644 --- a/src/mongo/db/repl/member_data.cpp +++ b/src/mongo/db/repl/member_data.cpp @@ -128,6 +128,7 @@ void MemberData::setAuthIssue(Date_t now) { } void MemberData::setLastAppliedOpTimeAndWallTime(OpTimeAndWallTime opTime, Date_t now) { + invariant(opTime.opTime.isNull() || opTime.wallTime > Date_t()); _lastUpdate = now; _lastUpdateStale = false; _lastAppliedOpTime = opTime.opTime; @@ -135,6 +136,7 @@ void MemberData::setLastAppliedOpTimeAndWallTime(OpTimeAndWallTime opTime, Date_ } void MemberData::setLastDurableOpTimeAndWallTime(OpTimeAndWallTime opTime, Date_t now) { + invariant(opTime.opTime.isNull() || opTime.wallTime > Date_t()); _lastUpdate = now; _lastUpdateStale = false; if (_lastAppliedOpTime < opTime.opTime) { @@ -153,6 +155,7 @@ void MemberData::setLastDurableOpTimeAndWallTime(OpTimeAndWallTime opTime, Date_ } bool MemberData::advanceLastAppliedOpTimeAndWallTime(OpTimeAndWallTime opTime, Date_t now) { + invariant(opTime.opTime.isNull() || opTime.wallTime > Date_t()); _lastUpdate = now; _lastUpdateStale = false; if (_lastAppliedOpTime < opTime.opTime) { @@ -163,6 +166,7 @@ bool MemberData::advanceLastAppliedOpTimeAndWallTime(OpTimeAndWallTime opTime, D } bool MemberData::advanceLastDurableOpTimeAndWallTime(OpTimeAndWallTime opTime, Date_t now) { + invariant(opTime.opTime.isNull() || opTime.wallTime > Date_t()); _lastUpdate = now; _lastUpdateStale = false; if (_lastDurableOpTime < opTime.opTime) { diff --git a/src/mongo/db/repl/oplog_fetcher.cpp b/src/mongo/db/repl/oplog_fetcher.cpp index 97c4296a247..659b171ea12 100644 --- a/src/mongo/db/repl/oplog_fetcher.cpp +++ b/src/mongo/db/repl/oplog_fetcher.cpp @@ -227,8 +227,7 @@ StatusWith<boost::optional<rpc::OplogQueryMetadata>> parseOplogQueryMetadata( queryResponse.otherFields.metadata.hasElement(rpc::kOplogQueryMetadataFieldName); if (receivedOplogQueryMetadata) { const auto& metadataObj = queryResponse.otherFields.metadata; - auto metadataResult = - rpc::OplogQueryMetadata::readFromMetadata(metadataObj, true /* requireWallTime */); + auto metadataResult = rpc::OplogQueryMetadata::readFromMetadata(metadataObj); if (!metadataResult.isOK()) { return metadataResult.getStatus(); } @@ -473,8 +472,7 @@ StatusWith<BSONObj> OplogFetcher::_onSuccessfulBatch(const Fetcher::QueryRespons queryResponse.otherFields.metadata.hasElement(rpc::kReplSetMetadataFieldName); if (receivedReplMetadata) { const auto& metadataObj = queryResponse.otherFields.metadata; - auto metadataResult = - rpc::ReplSetMetadata::readFromMetadata(metadataObj, true /* requireWallTime */); + auto metadataResult = rpc::ReplSetMetadata::readFromMetadata(metadataObj); if (!metadataResult.isOK()) { error() << "invalid replication metadata from sync source " << _getSource() << ": " << metadataResult.getStatus() << ": " << metadataObj; diff --git a/src/mongo/db/repl/repl_set_commands.cpp b/src/mongo/db/repl/repl_set_commands.cpp index 60bce5be0ba..aa7bbfd0075 100644 --- a/src/mongo/db/repl/repl_set_commands.cpp +++ b/src/mongo/db/repl/repl_set_commands.cpp @@ -611,8 +611,7 @@ public: if (cmdObj.hasField("handshake")) return true; - auto metadataResult = - rpc::ReplSetMetadata::readFromMetadata(cmdObj, true /* requireWallTime */); + auto metadataResult = rpc::ReplSetMetadata::readFromMetadata(cmdObj); if (metadataResult.isOK()) { // New style update position command has metadata, which may inform the // upstream of a higher term. @@ -626,7 +625,7 @@ public: UpdatePositionArgs args; - status = args.initialize(cmdObj, true /* requireWallTime */); + status = args.initialize(cmdObj); if (status.isOK()) { status = replCoord->processReplSetUpdatePosition(args, &configVersion); diff --git a/src/mongo/db/repl/repl_set_heartbeat_response.cpp b/src/mongo/db/repl/repl_set_heartbeat_response.cpp index b869835e213..c43316acdc0 100644 --- a/src/mongo/db/repl/repl_set_heartbeat_response.cpp +++ b/src/mongo/db/repl/repl_set_heartbeat_response.cpp @@ -109,9 +109,7 @@ BSONObj ReplSetHeartbeatResponse::toBSON() const { return builder.obj(); } -Status ReplSetHeartbeatResponse::initialize(const BSONObj& doc, - long long term, - bool requireWallTime) { +Status ReplSetHeartbeatResponse::initialize(const BSONObj& doc, long long term) { auto status = getStatusFromCommandResult(doc); if (!status.isOK()) { return status; @@ -161,9 +159,7 @@ Status ReplSetHeartbeatResponse::initialize(const BSONObj& doc, if (!status.isOK()) { return status; } - if (status.isOK()) { - _durableWallTime = durableWallTimeElement.Date(); - } + _durableWallTime = durableWallTimeElement.Date(); _durableOpTimeSet = true; @@ -180,9 +176,7 @@ Status ReplSetHeartbeatResponse::initialize(const BSONObj& doc, if (!status.isOK()) { return status; } - if (status.isOK()) { - _appliedWallTime = appliedWallTimeElement.Date(); - } + _appliedWallTime = appliedWallTimeElement.Date(); _appliedOpTimeSet = true; const BSONElement memberStateElement = doc[kMemberStateFieldName]; diff --git a/src/mongo/db/repl/repl_set_heartbeat_response.h b/src/mongo/db/repl/repl_set_heartbeat_response.h index 3b883d4f017..0f18536e7f5 100644 --- a/src/mongo/db/repl/repl_set_heartbeat_response.h +++ b/src/mongo/db/repl/repl_set_heartbeat_response.h @@ -51,10 +51,8 @@ class ReplSetHeartbeatResponse { public: /** * Initializes this ReplSetHeartbeatResponse from the contents of "doc". - * "term" is only used to complete a V0 OpTime (which is really a Timestamp). - * Only processes wall clock time elements if FCV is 4.2 (i.e., requireWallTime is true). */ - Status initialize(const BSONObj& doc, long long term, bool requireWallTime); + Status initialize(const BSONObj& doc, long long term); /** * Appends all non-default values to "builder". diff --git a/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp b/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp index 352456c929d..89d439af86e 100644 --- a/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp +++ b/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp @@ -120,8 +120,7 @@ TEST(ReplSetHeartbeatResponse, DefaultConstructThenSlowlyBuildToFullObj) { ASSERT_EQUALS(2, hbResponseObj["state"].numberLong()); ASSERT_EQUALS("syncTarget:27017", hbResponseObj["syncingTo"].String()); - initializeResult = - hbResponseObjRoundTripChecker.initialize(hbResponseObj, 0, /*requireWallTime*/ true); + initializeResult = hbResponseObjRoundTripChecker.initialize(hbResponseObj, 0); ASSERT_EQUALS(Status::OK(), initializeResult); ASSERT_EQUALS(hbResponseObj.toString(), hbResponseObjRoundTripChecker.toBSON().toString()); } @@ -130,7 +129,7 @@ TEST(ReplSetHeartbeatResponse, InitializeWrongElectionTimeType) { ReplSetHeartbeatResponse hbResponse; BSONObj initializerObj = BSON("ok" << 1.0 << "electionTime" << "hello"); - Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); + Status result = hbResponse.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); ASSERT_EQUALS( "Expected \"electionTime\" field in response to replSetHeartbeat command to " @@ -142,13 +141,13 @@ TEST(ReplSetHeartbeatResponse, InitializeWrongDurableOpTimeType) { ReplSetHeartbeatResponse hbResponse; BSONObj initializerObj = BSON("ok" << 1.0 << "durableOpTime" << "hello"); - Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); + Status result = hbResponse.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); ASSERT_EQUALS("\"durableOpTime\" had the wrong type. Expected object, found string", result.reason()); BSONObj initializerObj2 = BSON("ok" << 1.0 << "durableOpTime" << OpTime().getTimestamp()); - Status result2 = hbResponse.initialize(initializerObj2, 0, /*requireWallTime*/ true); + Status result2 = hbResponse.initialize(initializerObj2, 0); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result2); ASSERT_EQUALS("\"durableOpTime\" had the wrong type. Expected object, found timestamp", result2.reason()); @@ -159,7 +158,7 @@ TEST(ReplSetHeartbeatResponse, InitializeNoDurableWallTime) { BSONObj initializerObj = BSON("ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "opTime" << OpTime(Timestamp(100, 0), 0).toBSON()); - Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); + Status result = hbResponse.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::NoSuchKey, result); ASSERT_EQUALS("Missing expected field \"durableWallTime\"", result.reason()); } @@ -170,14 +169,14 @@ TEST(ReplSetHeartbeatResponse, InitializeWrongAppliedOpTimeType) { BSON("ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "durableWallTime" << Date_t() + Seconds(100) << "opTime" << "hello"); - Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); + Status result = hbResponse.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); ASSERT_EQUALS("\"opTime\" had the wrong type. Expected object, found string", result.reason()); initializerObj = BSON("ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "durableWallTime" << Date_t() + Seconds(100) << "opTime" << OpTime().getTimestamp()); - result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); + result = hbResponse.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); ASSERT_EQUALS("\"opTime\" had the wrong type. Expected object, found timestamp", result.reason()); @@ -188,7 +187,7 @@ TEST(ReplSetHeartbeatResponse, InitializeNoAppliedWallTime) { BSONObj initializerObj = BSON( "ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "durableWallTime" << Date_t() + Seconds(100) << "opTime" << OpTime(Timestamp(100, 0), 0).toBSON()); - Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); + Status result = hbResponse.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::NoSuchKey, result); ASSERT_EQUALS("Missing expected field \"wallTime\"", result.reason()); } @@ -200,7 +199,7 @@ TEST(ReplSetHeartbeatResponse, InitializeMemberStateWrongType) { << Date_t() + Seconds(100) << "opTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "wallTime" << Date_t() + Seconds(100) << "state" << "hello"); - Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); + Status result = hbResponse.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); ASSERT_EQUALS( "Expected \"state\" field in response to replSetHeartbeat command to " @@ -214,7 +213,7 @@ TEST(ReplSetHeartbeatResponse, InitializeMemberStateTooLow) { "ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "durableWallTime" << Date_t() + Seconds(100) << "opTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "wallTime" << Date_t() + Seconds(100) << "state" << -1); - Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); + Status result = hbResponse.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::BadValue, result); ASSERT_EQUALS( "Value for \"state\" in response to replSetHeartbeat is out of range; " @@ -228,7 +227,7 @@ TEST(ReplSetHeartbeatResponse, InitializeMemberStateTooHigh) { "ok" << 1.0 << "durableOpTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "durableWallTime" << Date_t() + Seconds(100) << "opTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "wallTime" << Date_t() + Seconds(100) << "state" << 11); - Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); + Status result = hbResponse.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::BadValue, result); ASSERT_EQUALS( "Value for \"state\" in response to replSetHeartbeat is out of range; " @@ -243,7 +242,7 @@ TEST(ReplSetHeartbeatResponse, InitializeVersionWrongType) { << Date_t() + Seconds(100) << "opTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "wallTime" << Date_t() + Seconds(100) << "v" << "hello"); - Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); + Status result = hbResponse.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); ASSERT_EQUALS( "Expected \"v\" field in response to replSetHeartbeat to " @@ -259,7 +258,7 @@ TEST(ReplSetHeartbeatResponse, InitializeReplSetNameWrongType) { << OpTime(Timestamp(100, 0), 0).toBSON() << "wallTime" << Date_t() + Seconds(100) << "v" << 2 // needs a version to get this far in initialize() << "set" << 4); - Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); + Status result = hbResponse.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); ASSERT_EQUALS( "Expected \"set\" field in response to replSetHeartbeat to " @@ -275,7 +274,7 @@ TEST(ReplSetHeartbeatResponse, InitializeSyncingToWrongType) { << OpTime(Timestamp(100, 0), 0).toBSON() << "wallTime" << Date_t() + Seconds(100) << "v" << 2 // needs a version to get this far in initialize() << "syncingTo" << 4); - Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); + Status result = hbResponse.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); ASSERT_EQUALS( "Expected \"syncingTo\" field in response to replSetHeartbeat to " @@ -291,7 +290,7 @@ TEST(ReplSetHeartbeatResponse, InitializeConfigWrongType) { << OpTime(Timestamp(100, 0), 0).toBSON() << "wallTime" << Date_t() + Seconds(100) << "v" << 2 // needs a version to get this far in initialize() << "config" << 4); - Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); + Status result = hbResponse.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::TypeMismatch, result); ASSERT_EQUALS( "Expected \"config\" in response to replSetHeartbeat to " @@ -307,7 +306,7 @@ TEST(ReplSetHeartbeatResponse, InitializeBadConfig) { << OpTime(Timestamp(100, 0), 0).toBSON() << "wallTime" << Date_t() + Seconds(100) << "v" << 2 // needs a version to get this far in initialize() << "config" << BSON("illegalFieldName" << 2)); - Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); + Status result = hbResponse.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::BadValue, result); ASSERT_EQUALS("Unexpected field illegalFieldName in replica set configuration", result.reason()); @@ -320,7 +319,7 @@ TEST(ReplSetHeartbeatResponse, NoConfigStillInitializing) { BSONObj initializerObj = BSON("ok" << 0.0 << "code" << ErrorCodes::NotYetInitialized << "errmsg" << "Received heartbeat while still initializing replication system."); - Status result = hbResp.initialize(initializerObj, 0, /*requireWallTime*/ true); + Status result = hbResp.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::NotYetInitialized, result.code()); } @@ -331,8 +330,7 @@ TEST(ReplSetHeartbeatResponse, InvalidResponseOpTimeMissesConfigVersion) { << "durableWallTime" << Date_t() + Seconds(100) << "opTime" << OpTime(Timestamp(100, 0), 0).toBSON() << "wallTime" << Date_t() + Seconds(100)), - 0, - /*requireWallTime*/ true); + 0); ASSERT_EQUALS(ErrorCodes::NoSuchKey, result.code()); ASSERT_TRUE(stringContains(result.reason(), "\"v\"")) << result.reason() << " doesn't contain 'v' field required error msg"; @@ -343,7 +341,7 @@ TEST(ReplSetHeartbeatResponse, MismatchedReplicaSetNames) { BSONObj initializerObj = BSON("ok" << 0.0 << "code" << ErrorCodes::InconsistentReplicaSetNames << "errmsg" << "replica set name doesn't match."); - Status result = hbResponse.initialize(initializerObj, 0, /*requireWallTime*/ true); + Status result = hbResponse.initialize(initializerObj, 0); ASSERT_EQUALS(ErrorCodes::InconsistentReplicaSetNames, result.code()); } @@ -351,9 +349,7 @@ TEST(ReplSetHeartbeatResponse, AuthFailure) { ReplSetHeartbeatResponse hbResp; std::string errMsg = "Unauthorized"; Status result = hbResp.initialize( - BSON("ok" << 0.0 << "errmsg" << errMsg << "code" << ErrorCodes::Unauthorized), - 0, - /*requireWallTime*/ true); + BSON("ok" << 0.0 << "errmsg" << errMsg << "code" << ErrorCodes::Unauthorized), 0); ASSERT_EQUALS(ErrorCodes::Unauthorized, result.code()); ASSERT_EQUALS(errMsg, result.reason()); } @@ -361,8 +357,7 @@ TEST(ReplSetHeartbeatResponse, AuthFailure) { TEST(ReplSetHeartbeatResponse, ServerError) { ReplSetHeartbeatResponse hbResp; std::string errMsg = "Random Error"; - Status result = - hbResp.initialize(BSON("ok" << 0.0 << "errmsg" << errMsg), 0, /*requireWallTime*/ true); + Status result = hbResp.initialize(BSON("ok" << 0.0 << "errmsg" << errMsg), 0); ASSERT_EQUALS(ErrorCodes::UnknownError, result.code()); ASSERT_EQUALS(errMsg, result.reason()); } diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp index 6ad77bd3157..3114ec6950a 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp @@ -150,10 +150,9 @@ void ReplicationCoordinatorImpl::_handleHeartbeatResponse( BSONObj resp; if (responseStatus.isOK()) { resp = cbData.response.data; - responseStatus = - hbResponse.initialize(resp, _topCoord->getTerm(), true /* requireWallTime */); - StatusWith<rpc::ReplSetMetadata> replMetadata = rpc::ReplSetMetadata::readFromMetadata( - cbData.response.data, true /* requireWallTime */); + responseStatus = hbResponse.initialize(resp, _topCoord->getTerm()); + StatusWith<rpc::ReplSetMetadata> replMetadata = + rpc::ReplSetMetadata::readFromMetadata(cbData.response.data); LOG_FOR_HEARTBEATS(2) << "Received response to heartbeat (requestId: " << cbData.request.id << ") from " << target << ", " << resp; diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp index c387e99bec6..f575f05bfea 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp @@ -4754,7 +4754,7 @@ TEST_F(ReplCoordTest, PrepareOplogQueryMetadata) { BSONObj metadata = metadataBob.done(); log() << metadata; - auto oqMetadata = rpc::OplogQueryMetadata::readFromMetadata(metadata, /*requireWallTime*/ true); + auto oqMetadata = rpc::OplogQueryMetadata::readFromMetadata(metadata); ASSERT_OK(oqMetadata.getStatus()); ASSERT_EQ(oqMetadata.getValue().getLastOpCommitted().opTime, optime1); ASSERT_EQ(oqMetadata.getValue().getLastOpCommitted().wallTime, wallTime1); @@ -5432,8 +5432,7 @@ TEST_F(ReplCoordTest, UpdatePositionCmdHasMetadata) { ASSERT_EQUALS(metadata.getTerm(), getReplCoord()->getTerm()); ASSERT_EQUALS(metadata.getLastOpVisible(), optime); - auto oqMetadataStatus = - rpc::OplogQueryMetadata::readFromMetadata(cmd, /*requireWallTime*/ true); + auto oqMetadataStatus = rpc::OplogQueryMetadata::readFromMetadata(cmd); ASSERT_EQUALS(oqMetadataStatus.getStatus(), ErrorCodes::NoSuchKey); } @@ -5533,8 +5532,7 @@ TEST_F(ReplCoordTest, StepDownWhenHandleLivenessTimeoutMarksAMajorityOfVotingNod << Date_t() + Seconds(startingOpTime.getSecs()) << UpdatePositionArgs::kDurableOpTimeFieldName << startingOpTime.toBSON() << UpdatePositionArgs::kDurableWallTimeFieldName - << Date_t() + Seconds(startingOpTime.getSecs())))), - /*requireWallTime*/ true)); + << Date_t() + Seconds(startingOpTime.getSecs())))))); const Date_t startDate = getNet()->now(); getNet()->enterNetwork(); getNet()->runUntil(startDate + Milliseconds(100)); diff --git a/src/mongo/db/repl/replication_coordinator_test_fixture.h b/src/mongo/db/repl/replication_coordinator_test_fixture.h index bee8d0af6ca..8acc88e8f15 100644 --- a/src/mongo/db/repl/replication_coordinator_test_fixture.h +++ b/src/mongo/db/repl/replication_coordinator_test_fixture.h @@ -106,15 +106,12 @@ protected: return _repl.get(); } - Status updatePositionArgsInitialize(UpdatePositionArgs& args, - const BSONObj& argsObj, - bool requireWallTime = true) { - return args.initialize(argsObj, requireWallTime); + Status updatePositionArgsInitialize(UpdatePositionArgs& args, const BSONObj& argsObj) { + return args.initialize(argsObj); } - StatusWith<rpc::ReplSetMetadata> replReadFromMetadata(const BSONObj& doc, - bool requireWallTime = true) { - return rpc::ReplSetMetadata::readFromMetadata(doc, requireWallTime); + StatusWith<rpc::ReplSetMetadata> replReadFromMetadata(const BSONObj& doc) { + return rpc::ReplSetMetadata::readFromMetadata(doc); } void replCoordSetMyLastAppliedOpTime(const OpTime& opTime, Date_t wallTime = Date_t()) { diff --git a/src/mongo/db/repl/reporter.cpp b/src/mongo/db/repl/reporter.cpp index 6ad2390d3c0..5e7c852d211 100644 --- a/src/mongo/db/repl/reporter.cpp +++ b/src/mongo/db/repl/reporter.cpp @@ -54,7 +54,7 @@ const char kConfigVersionFieldName[] = "configVersion"; template <typename UpdatePositionArgsType> long long _parseCommandRequestConfigVersion(const BSONObj& commandRequest) { UpdatePositionArgsType args; - if (!args.initialize(commandRequest, /*requireWallTime*/ false).isOK()) { + if (!args.initialize(commandRequest).isOK()) { return -1; } if (args.updatesBegin() == args.updatesEnd()) { diff --git a/src/mongo/db/repl/topology_coordinator_v1_test.cpp b/src/mongo/db/repl/topology_coordinator_v1_test.cpp index 6da911b3aca..e0cc0edbe3b 100644 --- a/src/mongo/db/repl/topology_coordinator_v1_test.cpp +++ b/src/mongo/db/repl/topology_coordinator_v1_test.cpp @@ -3443,9 +3443,7 @@ TEST_F(HeartbeatResponseTestV1, ReconfigNodeRemovedBetweenHeartbeatRequestAndRep 0); ReplSetHeartbeatResponse hb; - hb.initialize(BSON("ok" << 1 << "v" << 1 << "state" << MemberState::RS_PRIMARY), - 0, - /*requireWallTime*/ true) + hb.initialize(BSON("ok" << 1 << "v" << 1 << "state" << MemberState::RS_PRIMARY), 0) .transitional_ignore(); hb.setDurableOpTimeAndWallTime( {lastOpTimeApplied, Date_t() + Seconds(lastOpTimeApplied.getSecs())}); @@ -3495,8 +3493,7 @@ TEST_F(HeartbeatResponseTestV1, ReconfigBetweenHeartbeatRequestAndRepsonse) { << OpTime(Timestamp(100, 0), 0).toBSON() << "wallTime" << Date_t() + Seconds(100) << "v" << 1 << "state" << MemberState::RS_PRIMARY), - 0, - /*requireWallTime*/ true) + 0) .transitional_ignore(); hb.setDurableOpTimeAndWallTime( {lastOpTimeApplied, Date_t() + Seconds(lastOpTimeApplied.getSecs())}); diff --git a/src/mongo/db/repl/update_position_args.cpp b/src/mongo/db/repl/update_position_args.cpp index cb31e270a97..d1128f3c2c0 100644 --- a/src/mongo/db/repl/update_position_args.cpp +++ b/src/mongo/db/repl/update_position_args.cpp @@ -62,7 +62,7 @@ UpdatePositionArgs::UpdateInfo::UpdateInfo(const OpTime& applied, cfgver(aCfgver), memberId(aMemberId) {} -Status UpdatePositionArgs::initialize(const BSONObj& argsObj, bool requireWallTime) { +Status UpdatePositionArgs::initialize(const BSONObj& argsObj) { // grab the array of changes BSONElement updateArray; Status status = bsonExtractTypedField(argsObj, kUpdateArrayFieldName, Array, &updateArray); @@ -76,26 +76,26 @@ Status UpdatePositionArgs::initialize(const BSONObj& argsObj, bool requireWallTi OpTime appliedOpTime; status = bsonExtractOpTimeField(entry, kAppliedOpTimeFieldName, &appliedOpTime); - if (!status.isOK()) + if (!status.isOK()) { return status; - + } Date_t appliedWallTime = Date_t(); BSONElement appliedWallTimeElement; status = bsonExtractTypedField( entry, kAppliedWallTimeFieldName, BSONType::Date, &appliedWallTimeElement); - if (!status.isOK() && (status != ErrorCodes::NoSuchKey || requireWallTime)) + if (!status.isOK()) { return status; - if (status.isOK()) - appliedWallTime = appliedWallTimeElement.Date(); + } + appliedWallTime = appliedWallTimeElement.Date(); Date_t durableWallTime = Date_t(); BSONElement durableWallTimeElement; status = bsonExtractTypedField( entry, kDurableWallTimeFieldName, BSONType::Date, &durableWallTimeElement); - if (!status.isOK() && (status != ErrorCodes::NoSuchKey || requireWallTime)) + if (!status.isOK()) { return status; - if (status.isOK()) - durableWallTime = durableWallTimeElement.Date(); + } + durableWallTime = durableWallTimeElement.Date(); OpTime durableOpTime; status = bsonExtractOpTimeField(entry, kDurableOpTimeFieldName, &durableOpTime); diff --git a/src/mongo/db/repl/update_position_args.h b/src/mongo/db/repl/update_position_args.h index 37c9a536eed..2bad4f83635 100644 --- a/src/mongo/db/repl/update_position_args.h +++ b/src/mongo/db/repl/update_position_args.h @@ -75,7 +75,7 @@ public: /** * Initializes this UpdatePositionArgs from the contents of "argsObj". */ - Status initialize(const BSONObj& argsObj, bool requireWallTime); + Status initialize(const BSONObj& argsObj); /** * Gets a begin iterator over the UpdateInfos stored in this UpdatePositionArgs. |