Преглед изворни кода

Remove next_index and current_step from RaftState.

Jing Yang пре 3 година
родитељ
комит
56f934ea4f
2 измењених фајлова са 1 додато и 14 уклоњено
  1. 1 10
      src/election.rs
  2. 0 4
      src/raft_state.rs

+ 1 - 10
src/election.rs

@@ -353,16 +353,7 @@ impl<Command: ReplicableCommand> Raft<Command> {
 
             rf.state = State::Leader;
             rf.leader_id = me;
-            let log_len = rf.log.end();
-            for item in rf.next_index.iter_mut() {
-                *item = log_len;
-            }
-            for item in rf.match_index.iter_mut() {
-                *item = 0;
-            }
-            for item in rf.current_step.iter_mut() {
-                *item = 0;
-            }
+            rf.match_index.fill(0);
 
             let sentinel_commit_index;
             if rf.commit_index != rf.log.last_index_term().index {

+ 0 - 4
src/raft_state.rs

@@ -18,9 +18,7 @@ pub(crate) struct RaftState<Command> {
     pub commit_index: Index,
     pub last_applied: Index,
 
-    pub next_index: Vec<Index>,
     pub match_index: Vec<Index>,
-    pub current_step: Vec<i64>,
 
     pub state: State,
 
@@ -35,9 +33,7 @@ impl<Command> RaftState<Command> {
             log: LogArray::create(),
             commit_index: 0,
             last_applied: 0,
-            next_index: vec![1; peer_size],
             match_index: vec![0; peer_size],
-            current_step: vec![0; peer_size],
             state: State::Follower,
             leader_id: me,
         }