private void recordHeartbeat ( RaftMemberContext member , long timestamp ) { raft . checkThread ( ) ; // Update the member's heartbeat time. This will be used when calculating the quorum heartbeat time. member . setHeartbeatTime ( timestamp ) ; member . setResponseTime ( System . currentTimeMillis ( ) ) ; // Compute the quorum heartbeat time. long heartbeatTime = computeHeartbeatTime ( ) ; long currentTimestamp = System . currentTimeMillis ( ) ; // Iterate through pending timestamped heartbeat futures and complete all futures where the timestamp // is greater than the last timestamp a quorum of the cluster was contacted. Iterator < TimestampedFuture < Long > > iterator = heartbeatFutures . iterator ( ) ; while ( iterator . hasNext ( ) ) { TimestampedFuture < Long > future = iterator . next ( ) ; // If the future is timestamped prior to the last heartbeat to a majority of the cluster, complete the future. if ( future . timestamp < heartbeatTime ) { future . complete ( null ) ; iterator . remove ( ) ; } // If the future is more than an election timeout old, fail it with a protocol exception. else if ( currentTimestamp - future . timestamp > electionTimeout ) { future . completeExceptionally ( new RaftException . ProtocolException ( "Failed to reach consensus" ) ) ; iterator . remove ( ) ; } // Otherwise, we've reached recent heartbeat futures. Break out of the loop. else { break ; } } // If heartbeat futures are still pending, attempt to send heartbeats. if ( ! heartbeatFutures . isEmpty ( ) ) { sendHeartbeats ( ) ; } }
Records a completed heartbeat to the given member .