diff --git a/little_raft/src/replica.rs b/little_raft/src/replica.rs index 34e4f28..6f005d4 100644 --- a/little_raft/src/replica.rs +++ b/little_raft/src/replica.rs @@ -1,7 +1,7 @@ use crate::{ cluster::Cluster, message::{LogEntry, Message}, - state_machine::{StateMachine, StateMachineTransition, TransitionState}, + state_machine::{StateMachine, StateMachineTransition, TransitionState, TransitionAbandonedReason}, timer::Timer, }; use crossbeam_channel::{Receiver, Select}; @@ -377,6 +377,11 @@ where let mut state_machine = self.state_machine.lock().unwrap(); state_machine .register_transition_state(transition.get_id(), TransitionState::Queued); + } else { + let mut state_machine = self.state_machine.lock().unwrap(); + state_machine + .register_transition_state( + transition.get_id(), TransitionState::Abandoned(TransitionAbandonedReason::NotLeader)); } } } diff --git a/little_raft/src/state_machine.rs b/little_raft/src/state_machine.rs index fe445ac..8cad75d 100644 --- a/little_raft/src/state_machine.rs +++ b/little_raft/src/state_machine.rs @@ -16,6 +16,15 @@ pub enum TransitionState { /// Applied transitions have been replicated across the cluster and have /// been applied to the local state machine. Applied, + + /// Abandoned transitions have been ignored by the replica. + Abandoned(TransitionAbandonedReason), +} + +#[derive(Clone, Debug, PartialEq)] +pub enum TransitionAbandonedReason { + // NotLeader transitions have been abandoned because the replica is not the cluster leadedr. + NotLeader, } /// StateMachineTransition describes a user-defined transition that can be