Skip to content

Commit

Permalink
fix andreev-io#13, Add Abandoned type to TransitionState enum
Browse files Browse the repository at this point in the history
  • Loading branch information
suzaku committed Dec 17, 2021
1 parent 2ee9455 commit 003283a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion little_raft/src/replica.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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));
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions little_raft/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 003283a

Please sign in to comment.