summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/replication_coordinator_impl.h
diff options
context:
space:
mode:
authorXueruiFa <xuerui.fa@mongodb.com>2020-09-15 16:08:23 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-29 15:51:55 +0000
commit379c0116b694d8d88ec096170e703fe3d0119e55 (patch)
treebe2f9d7ed4b499c6f5c4676060266469b8147848 /src/mongo/db/repl/replication_coordinator_impl.h
parent126068ea383471608e9e1e76073048b749471643 (diff)
downloadmongo-379c0116b694d8d88ec096170e703fe3d0119e55.tar.gz
SERVER-50318: Only cancel scheduled heartbeats
Diffstat (limited to 'src/mongo/db/repl/replication_coordinator_impl.h')
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.h38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_impl.h b/src/mongo/db/repl/replication_coordinator_impl.h
index dac623362a5..66556fac3ef 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.h
+++ b/src/mongo/db/repl/replication_coordinator_impl.h
@@ -383,7 +383,7 @@ public:
OnRemoteCmdScheduledFn onRemoteCmdScheduled,
OnRemoteCmdCompleteFn onRemoteCmdComplete) override;
- virtual void restartHeartbeats_forTest() override;
+ virtual void restartScheduledHeartbeats_forTest() override;
// ================== Test support API ===================
@@ -677,7 +677,12 @@ private:
std::multimap<OpTime, SharedWaiterHandle> _waiters;
};
- typedef std::vector<executor::TaskExecutor::CallbackHandle> HeartbeatHandles;
+ enum class HeartbeatState { kScheduled = 0, kSent = 1 };
+ struct HeartbeatHandle {
+ executor::TaskExecutor::CallbackHandle handle;
+ HeartbeatState hbState;
+ HostAndPort target;
+ };
// The state and logic of primary catchup.
//
@@ -1010,22 +1015,21 @@ private:
bool isRollbackAllowed);
/**
- * Schedules a heartbeat to be sent to "target" at "when". "targetIndex" is the index
- * into the replica set config members array that corresponds to the "target", or -1 if
- * "target" is not in _rsConfig.
+ * Schedules a heartbeat to be sent to "target" at "when".
*/
- void _scheduleHeartbeatToTarget_inlock(const HostAndPort& target, int targetIndex, Date_t when);
+ void _scheduleHeartbeatToTarget_inlock(const HostAndPort& target, Date_t when);
/**
* Processes each heartbeat response.
*
* Schedules additional heartbeats, triggers elections and step downs, etc.
*/
- void _handleHeartbeatResponse(const executor::TaskExecutor::RemoteCommandCallbackArgs& cbData,
- int targetIndex);
+ void _handleHeartbeatResponse(const executor::TaskExecutor::RemoteCommandCallbackArgs& cbData);
void _trackHeartbeatHandle_inlock(
- const StatusWith<executor::TaskExecutor::CallbackHandle>& handle);
+ const StatusWith<executor::TaskExecutor::CallbackHandle>& handle,
+ HeartbeatState hbState,
+ const HostAndPort& target);
void _untrackHeartbeatHandle_inlock(const executor::TaskExecutor::CallbackHandle& handle);
@@ -1046,21 +1050,17 @@ private:
void _cancelHeartbeats_inlock();
/**
- * Cancels all heartbeats, then starts a heartbeat for each member in the current config.
- * Called while holding replCoord _mutex.
+ * Cancels all heartbeats that have been scheduled but not yet sent out, then reschedules them
+ * at the current time immediately. Called while holding replCoord _mutex.
*/
- void _restartHeartbeats_inlock();
+ void _restartScheduledHeartbeats_inlock();
/**
- * Asynchronously sends a heartbeat to "target". "targetIndex" is the index
- * into the replica set config members array that corresponds to the "target", or -1 if
- * we don't have a valid replica set config.
+ * Asynchronously sends a heartbeat to "target".
*
* Scheduled by _scheduleHeartbeatToTarget_inlock.
*/
- void _doMemberHeartbeat(executor::TaskExecutor::CallbackArgs cbData,
- const HostAndPort& target,
- int targetIndex);
+ void _doMemberHeartbeat(executor::TaskExecutor::CallbackArgs cbData, const HostAndPort& target);
MemberState _getMemberState_inlock() const;
@@ -1496,7 +1496,7 @@ private:
mutable Mutex _mutex = MONGO_MAKE_LATCH("ReplicationCoordinatorImpl::_mutex"); // (S)
// Handles to actively queued heartbeats.
- HeartbeatHandles _heartbeatHandles; // (M)
+ std::vector<HeartbeatHandle> _heartbeatHandles; // (M)
// When this node does not know itself to be a member of a config, it adds
// every host that sends it a heartbeat request to this set, and also starts