Skip to content

Commit

Permalink
User-driven wakeups
Browse files Browse the repository at this point in the history
  • Loading branch information
andreev-io committed Aug 17, 2021
1 parent 0e0d8fb commit 5399867
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 247 deletions.
15 changes: 7 additions & 8 deletions little_raft/src/cluster.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{message::Message, state_machine::StateMachineTransition};
use std::time::Duration;

// Cluster provides the means of communication of a replica with the rest of the
// cluster and the user.
Expand All @@ -9,15 +8,15 @@ where
{
// This function is used to deliver messages to target replicas. The
// algorithm assumes that send can silently fail.
fn send(&self, to_id: usize, message: Message<T>);
// This function is used to received messages for the replicas. This
// function must block until timeout expires or a message is received,
// whichever comes first.
fn receive_timeout(&self, timeout: Duration) -> Option<Message<T>>;
fn send(&mut self, to_id: usize, message: Message<T>);
// This function is used to received messages for the replicas. If there are
// no messages pending, the function should return immediately.
fn receive(&mut self) -> Vec<Message<T>>;
// This function is used to receive actions from the user that the
// distributed state machine needs to replicate and apply. All replicas poll
// this function periodically but only Leaders merit the return value.
// Non-Leaders ignore the return value of get_action.
fn get_pending_transitions(&self) -> Vec<T>;
fn register_leader_change(&mut self, leader_id: Option<usize>);
fn get_pending_transitions(&mut self) -> Vec<T>;

fn halt(&self) -> bool;
}
2 changes: 1 addition & 1 deletion little_raft/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod cluster;
mod heartbeat_timer;
pub mod message;
pub mod replica;
pub mod state_machine;
mod timer;
4 changes: 2 additions & 2 deletions little_raft/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::state_machine::StateMachineTransition;
// Entry describes a user-defined transition of the distributed state machine.
// It has some associated metadata, namely the term when the entry was created
// and its index in the log.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Copy, PartialEq, Eq, PartialOrd)]
pub struct Entry<T>
where
T: StateMachineTransition,
Expand All @@ -16,7 +16,7 @@ where

// Message describes messages that the replicas pass between each other to
// achieve consensus on the distributed state machine.
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd)]
pub enum Message<T>
where
T: StateMachineTransition,
Expand Down
Loading

0 comments on commit 5399867

Please sign in to comment.