func (s *RaftServer) HeartbeatEventHandler() {
	if s.ServerConf.Info.Role != core.RoleLeader {
		return
	}
	countlog.Info(fmt.Sprintf("%s send heart beat to followers", s))
	for _, node := range s.ServerConf.ClusterAddrList {
		if s.ServerConf.Info.ServerID == node.ServerID {
			continue
		}
		lastTime := s.leaderState.LastRPCTime[node.ServerID]
		if time.Since(lastTime) < time.Duration(s.leaderHeartBeatTimer.DurationInMs)/2*time.Millisecond {
			// Don't send heart beat if we already sent any log recently
			countlog.Info(fmt.Sprintf("No need to send heartbeat to node %s: lastTime = %v", node.String(), lastTime))
			continue
		}
		req := &raftrpc.AppendRPCRequest{}
		req.LogEntries = []*core.LogEntry{}
		req.Term = s.stableInfo.Term
		req.LeaderNode = s.ServerConf.Info
		go func(r *raftrpc.AppendRPCRequest, followerAddr *net.TCPAddr) {
			s.sendHeartbeatToServer(r, followerAddr)
		}(req, node.ServerAddr)
	}
}
// HeartbeatEventHandler is triggered by leaderHeartBeatTicker, leader will send heart beat rpc to followers
// HeartbeatEventHandler sends heart beat rpc to followers
HeartbeatEventHandler is triggered by leaderHeartBeatTicker, leader will send heart beat rpc to followers
HeartbeatEventHandler sends heart beat rpc to followers
// HeartbeatEventHandler is triggered by leaderHeartBeatTicker leader will send heart beat rpc to followers // HeartbeatEventHandler sends heart beat rpc to followers
func (s *RaftServer) HeartbeatEventHandler() {
	if s.ServerConf.Info.Role != core.RoleLeader {
		return
	}
	countlog.Info(fmt.Sprintf("%s send heart beat to followers", s))
	for _, node := range s.ServerConf.ClusterAddrList {
		if s.ServerConf.Info.ServerID == node.ServerID {
			continue
		}
		lastTime := s.leaderState.LastRPCTime[node.ServerID]
		if time.Since(lastTime) < time.Duration(s.leaderHeartBeatTimer.DurationInMs)/2*time.Millisecond {
			countlog.Info(fmt.Sprintf("No need to send heartbeat to node %s: lastTime = %v", node.String(), lastTime))
			continue
		}
		req := &raftrpc.AppendRPCRequest{}
		req.LogEntries = []*core.LogEntry{}
		req.Term = s.stableInfo.Term
		req.LeaderNode = s.ServerConf.Info
		go func(r *raftrpc.AppendRPCRequest, followerAddr *net.TCPAddr) {
			s.sendHeartbeatToServer(r, followerAddr)
		}(req, node.ServerAddr)
	}
}
func ( s * RaftServer ) HeartbeatEventHandler ( ) { if s . ServerConf . Info . Role != core . RoleLeader { return } countlog . Info ( fmt . Sprintf ( " " , s ) ) for _ , node := range s . ServerConf . ClusterAddrList { if s . ServerConf . Info . ServerID == node . ServerID { continue } lastTime := s . leaderState . LastRPCTime [ node . ServerID ] if time . Since ( lastTime ) < time . Duration ( s . leaderHeartBeatTimer . DurationInMs ) / 2 * time . Millisecond { countlog . Info ( fmt . Sprintf ( " " , node . String ( ) , lastTime ) ) continue } req := & raftrpc . AppendRPCRequest { } req . LogEntries = [ ] * core . LogEntry { } req . Term = s . stableInfo . Term req . LeaderNode = s . ServerConf . Info go func ( r * raftrpc . AppendRPCRequest , followerAddr * net . TCPAddr ) { s . sendHeartbeatToServer ( r , followerAddr ) } ( req , node . ServerAddr ) } }
HeartbeatEventHandler is triggered by leaderHeartBeatTicker, leader will send heart beat rpc to followers
HeartbeatEventHandler sends heart beat rpc to followers
HeartbeatEventHandler is triggered by leaderHeartBeatTicker leader will send heart beat rpc to followers HeartbeatEventHandler sends heart beat rpc to followers
// Don't send heart beat if we already sent any log recently