Explorar el Código

Set leader_id when elected.

Jing Yang hace 5 años
padre
commit
599f453c6e
Se han modificado 1 ficheros con 3 adiciones y 0 borrados
  1. 3 0
      src/lib.rs

+ 3 - 0
src/lib.rs

@@ -436,6 +436,7 @@ impl Raft {
 
         let (tx, rx) = futures::channel::oneshot::channel();
         self.thread_pool.spawn(Self::count_vote_util_cancelled(
+            me,
             term,
             self.inner_state.clone(),
             self.election.clone(),
@@ -464,6 +465,7 @@ impl Raft {
     }
 
     async fn count_vote_util_cancelled(
+        me: Peer,
         term: Term,
         rf: Arc<Mutex<RaftState>>,
         election: Arc<ElectionState>,
@@ -509,6 +511,7 @@ impl Raft {
             election.stop_election_timer();
 
             rf.state = State::Leader;
+            rf.leader_id = me;
             let log_len = rf.log.len();
             for item in rf.next_index.iter_mut() {
                 *item = log_len;