Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshotting and log compaction #32

Merged
merged 4 commits into from
Jan 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .github/workflows/clippy_check.yml

This file was deleted.

26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions little_raft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ crossbeam-channel = "0.5.1"
crossbeam = "0.8.0"
timer = "0.1.3"
time = "0.1.39"
bytes = "0.4.7"
11 changes: 6 additions & 5 deletions little_raft/src/cluster.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
use crate::{message::Message, replica::ReplicaID, state_machine::StateMachineTransition};
use crate::{message::Message, replica::ReplicaID, state_machine::{StateMachineTransition}};

/// Cluster is used for the local Raft Replica to communicate with the rest of
/// the Raft cluster. It is up to the user how to abstract that communication.
/// The Cluster trait also contains hooks which the Replica will use to inform
/// the crate user of state changes.
pub trait Cluster<T>
pub trait Cluster<T, D>
where
T: StateMachineTransition,
D: Clone,
{
/// This function is used to deliver messages to target Replicas. The
/// Replica will provide the to_id of the other Replica it's trying to send
/// its message to and provide the message itself. The send_message
/// implementation must not block but is allowed silently fail -- Raft
/// implementation must not block but is allowed to silently fail -- Raft
/// exists to achieve consensus in spite of failures, after all.
fn send_message(&mut self, to_id: usize, message: Message<T>);
fn send_message(&mut self, to_id: usize, message: Message<T, D>);

/// This function is used by the Replica to receive pending messages from
/// the cluster. The receive_messages implementation must not block and must
/// not return the same message more than once. Note that receive_messages
/// is only called when the Replica is notified via the recv_msg channel.
fn receive_messages(&mut self) -> Vec<Message<T>>;
fn receive_messages(&mut self) -> Vec<Message<T, D>>;

/// By returning true from halt you can signal to the Replica that it should
/// stop running.
Expand Down
23 changes: 20 additions & 3 deletions little_raft/src/message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::replica::ReplicaID;
use crate::state_machine::StateMachineTransition;
use crate::state_machine::{StateMachineTransition};

/// LogEntry is a state machine transition along with some metadata needed for
/// Raft.
Expand All @@ -16,14 +16,15 @@ where
/// Message describes messages that the replicas pass between each other to
/// achieve consensus on the distributed state machine.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd)]
pub enum Message<T>
pub enum Message<T, D>
where
T: StateMachineTransition,
D: Clone,
{
/// AppendEntryRequest is used by the Leader to send out logs for other
/// replicas to append to their log. It also has information on what logs
/// are ready to be applied to the state machine. AppendEntryRequest is also
/// used as a heart beat message by the Leader even when no new logs need to
/// used as a heartbeat message by the Leader even when no new logs need to
/// be processed.
AppendEntryRequest {
from_id: ReplicaID,
Expand Down Expand Up @@ -58,4 +59,20 @@ where
term: usize,
vote_granted: bool,
},

InstallSnapshotRequest {
from_id: ReplicaID,
term: usize,
last_included_index: usize,
last_included_term: usize,
offset: usize,
data: D,
done: bool,
},

InstallSnapshotResponse {
from_id: ReplicaID,
term: usize,
last_included_index: usize,
},
}
Loading