Skip to content

Commit

Permalink
fix #34, record abandoned reason for conflicting entry logs
Browse files Browse the repository at this point in the history
  • Loading branch information
suzaku authored and andreev-io committed Dec 21, 2021
1 parent 08dbd38 commit 9afadd9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions little_raft/src/replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,16 @@ where
return;
}

let mut state_machine = self.state_machine.lock().unwrap();
for entry in entries {
// Drop local inconsistent logs.
if entry.index < self.log.len() && entry.term != self.log[entry.index].term {
for i in entry.index..self.log.len() {
state_machine.register_transition_state(
self.log[i].transition.get_id(),
TransitionState::Abandoned(TransitionAbandonedReason::ConflictingEntry)
);
}
self.log.truncate(entry.index);
}

Expand Down
4 changes: 4 additions & 0 deletions little_raft/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ pub enum TransitionAbandonedReason {
// NotLeader transitions have been abandoned because the replica is not
// the cluster leader.
NotLeader,

// ConflictingEntry entry logs in followers that are inconsistent with the
// leader's.
ConflictingEntry,
}

/// StateMachineTransition describes a user-defined transition that can be
Expand Down

0 comments on commit 9afadd9

Please sign in to comment.