diff options
author | Siyuan Zhou <visualzhou@gmail.com> | 2020-05-18 15:25:38 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-05-18 20:01:40 +0000 |
commit | f5f77b5f38efa5c7254593d89e43ac23cd4fac0f (patch) | |
tree | 12a31e9c541488d85b886197f093baff38ead8aa /src | |
parent | a89ac1a2a5496fc6b9e510babbb75f85655f6fc9 (diff) | |
download | mongo-f5f77b5f38efa5c7254593d89e43ac23cd4fac0f.tar.gz |
SERVER-48257 Backport handleHeartbeatResponse_forTest to 4.4
The test helper is introduced in SERVER-46381 and updated by SERVER-48115.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl.h | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp | 24 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_impl.h b/src/mongo/db/repl/replication_coordinator_impl.h index 66b22ba22eb..8bbb4df7400 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.h +++ b/src/mongo/db/repl/replication_coordinator_impl.h @@ -439,6 +439,10 @@ public: void cleanupStableOpTimeCandidates_forTest(std::set<OpTimeAndWallTime>* candidates, OpTimeAndWallTime stableOpTime); std::set<OpTimeAndWallTime> getStableOpTimeCandidates_forTest(); + void handleHeartbeatResponse_forTest(BSONObj response, + int targetIndex, + Milliseconds ping = Milliseconds(100)); + /** * Non-blocking version of updateTerm. diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp index 1f274f54a11..c042ab138ad 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp @@ -140,6 +140,30 @@ void ReplicationCoordinatorImpl::_scheduleHeartbeatToTarget_inlock(const HostAnd })); } +void ReplicationCoordinatorImpl::handleHeartbeatResponse_forTest(BSONObj response, + int targetIndex, + Milliseconds ping) { + CallbackHandle handle; + RemoteCommandRequest request; + request.target = _rsConfig.getMemberAt(targetIndex).getHostAndPort(); + executor::TaskExecutor::ResponseStatus status(response, ping); + executor::TaskExecutor::RemoteCommandCallbackArgs cbData( + _replExecutor.get(), handle, request, status); + + { + stdx::unique_lock<Latch> lk(_mutex); + + // Simulate preparing a heartbeat request so that the target's ping stats are initialized. + _topCoord->prepareHeartbeatRequestV1( + _replExecutor->now(), _rsConfig.getReplSetName(), request.target); + + // Pretend we sent a request so that _untrackHeartbeatHandle_inlock succeeds. + _trackHeartbeatHandle_inlock(handle); + } + + _handleHeartbeatResponse(cbData, targetIndex); +} + void ReplicationCoordinatorImpl::_handleHeartbeatResponse( const executor::TaskExecutor::RemoteCommandCallbackArgs& cbData, int targetIndex) { stdx::unique_lock<Latch> lk(_mutex); |