Skip to content

Commit

Permalink
Wait for all heartbeats to be processed
Browse files Browse the repository at this point in the history
  • Loading branch information
akiradeveloper committed May 24, 2024
1 parent 9a49b71 commit 8a79e0e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lolraft/src/raft_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,19 @@ impl raft::raft_server::Raft for RaftService {
) -> std::result::Result<tonic::Response<()>, tonic::Status> {
let req = request.into_inner();
let leader_id: NodeId = req.leader_id.parse().unwrap();

let mut futs = vec![];
for (lane_id, leader_state) in req.leader_commit_states {
let req = request::Heartbeat {
leader_term: leader_state.leader_term,
leader_commit_index: leader_state.leader_commit_index,
};
if let Some(process) = self.node.get_process(lane_id) {
let leader_id = leader_id.clone();
tokio::spawn(async move { process.receive_heartbeat(leader_id, req).await.ok() });
futs.push(async move { process.receive_heartbeat(leader_id, req).await });
}
}
futures::future::try_join_all(futs).await.unwrap();
Ok(tonic::Response::new(()))
}

Expand Down

0 comments on commit 8a79e0e

Please sign in to comment.