Skip to content

Commit

Permalink
Rename raft::Event::ReplicateEntries to AppendEntries.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker committed Nov 19, 2023
1 parent 30986a5 commit 491ff9e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/raft/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ pub enum Event {
},
/// Followers may grant votes to candidates.
GrantVote,
/// Leaders replicate a set of log entries to followers.
ReplicateEntries {
/// Leaders replicate log entries to followers by appending it to their log.
AppendEntries {
/// The index of the log entry immediately preceding the submitted commands.
base_index: Index,
/// The term of the log entry immediately preceding the submitted commands.
Expand Down
6 changes: 3 additions & 3 deletions src/raft/node/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl RoleNode<Candidate> {

// If we receive a message for a future term, become a leaderless
// follower in it and step the message. If the message is a Heartbeat or
// ReplicateEntries from the leader, stepping it will follow the leader.
// AppendEntries from the leader, stepping it will follow the leader.
if msg.term > self.term {
return self.become_follower(msg.term, None)?.step(msg);
}
Expand All @@ -95,7 +95,7 @@ impl RoleNode<Candidate> {
// If we receive a heartbeat or replicated entries in this term, we
// lost the election and have a new leader. Follow it and process
// the message.
Event::Heartbeat { .. } | Event::ReplicateEntries { .. } => {
Event::Heartbeat { .. } | Event::AppendEntries { .. } => {
return self.become_follower(msg.term, Some(msg.from.unwrap()))?.step(msg);
}

Expand Down Expand Up @@ -292,7 +292,7 @@ mod tests {
from: Address::Node(1),
to: Address::Node(to),
term: 3,
event: Event::ReplicateEntries {
event: Event::AppendEntries {
base_index: 3,
base_term: 2,
entries: vec![Entry { index: 4, term: 3, command: None }],
Expand Down
46 changes: 23 additions & 23 deletions src/raft/node/follower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl RoleNode<Follower> {

// If we receive a message for a future term, become a leaderless
// follower in it and step the message. If the message is a Heartbeat or
// ReplicateEntries from the leader, stepping it will follow the leader.
// AppendEntries from the leader, stepping it will follow the leader.
if msg.term > self.term {
return self.become_follower(None, msg.term)?.step(msg);
}
Expand Down Expand Up @@ -132,7 +132,7 @@ impl RoleNode<Follower> {

// Replicate entries from the leader. If we don't have a leader in
// this term yet, follow it.
Event::ReplicateEntries { base_index, base_term, entries } => {
Event::AppendEntries { base_index, base_term, entries } => {
// Check that the entries are from our leader.
let from = msg.from.unwrap();
match self.role.leader {
Expand Down Expand Up @@ -554,8 +554,8 @@ pub mod tests {
}

#[test]
// ReplicateEntries accepts some entries at base 0 without changes
fn step_replicateentries_base0() -> Result<()> {
// AppendEntries accepts some entries at base 0 without changes
fn step_appendentries_base0() -> Result<()> {
// TODO: Move this into a setup function.
let (node_tx, mut node_rx) = mpsc::unbounded_channel();
let (state_tx, mut state_rx) = mpsc::unbounded_channel();
Expand All @@ -579,7 +579,7 @@ pub mod tests {
from: Address::Node(2),
to: Address::Node(1),
term: 3,
event: Event::ReplicateEntries {
event: Event::AppendEntries {
base_index: 0,
base_term: 0,
entries: vec![
Expand All @@ -606,14 +606,14 @@ pub mod tests {
}

#[test]
// ReplicateEntries appends entries but does not commit them
fn step_replicateentries_append() -> Result<()> {
// AppendEntries appends entries but does not commit them
fn step_appendentries_append() -> Result<()> {
let (follower, mut node_rx, mut state_rx) = setup()?;
let mut node = follower.step(Message {
from: Address::Node(2),
to: Address::Node(1),
term: 3,
event: Event::ReplicateEntries {
event: Event::AppendEntries {
base_index: 3,
base_term: 2,
entries: vec![
Expand Down Expand Up @@ -643,14 +643,14 @@ pub mod tests {
}

#[test]
// ReplicateEntries accepts partially overlapping entries
fn step_replicateentries_partial_overlap() -> Result<()> {
// AppendEntries accepts partially overlapping entries
fn step_appendentries_partial_overlap() -> Result<()> {
let (follower, mut node_rx, mut state_rx) = setup()?;
let mut node = follower.step(Message {
from: Address::Node(2),
to: Address::Node(1),
term: 3,
event: Event::ReplicateEntries {
event: Event::AppendEntries {
base_index: 1,
base_term: 1,
entries: vec![
Expand Down Expand Up @@ -679,14 +679,14 @@ pub mod tests {
}

#[test]
// ReplicateEntries replaces conflicting entries
fn step_replicateentries_replace() -> Result<()> {
// AppendEntries replaces conflicting entries
fn step_appendentries_replace() -> Result<()> {
let (follower, mut node_rx, mut state_rx) = setup()?;
let mut node = follower.step(Message {
from: Address::Node(2),
to: Address::Node(1),
term: 3,
event: Event::ReplicateEntries {
event: Event::AppendEntries {
base_index: 2,
base_term: 1,
entries: vec![
Expand Down Expand Up @@ -715,14 +715,14 @@ pub mod tests {
}

#[test]
// ReplicateEntries replaces partially conflicting entries
fn step_replicateentries_replace_partial() -> Result<()> {
// AppendEntries replaces partially conflicting entries
fn step_appendentries_replace_partial() -> Result<()> {
let (follower, mut node_rx, mut state_rx) = setup()?;
let mut node = follower.step(Message {
from: Address::Node(2),
to: Address::Node(1),
term: 3,
event: Event::ReplicateEntries {
event: Event::AppendEntries {
base_index: 2,
base_term: 1,
entries: vec![
Expand Down Expand Up @@ -751,14 +751,14 @@ pub mod tests {
}

#[test]
// ReplicateEntries rejects missing base index
fn step_replicateentries_reject_missing_base_index() -> Result<()> {
// AppendEntries rejects missing base index
fn step_appendentries_reject_missing_base_index() -> Result<()> {
let (follower, mut node_rx, mut state_rx) = setup()?;
let mut node = follower.step(Message {
from: Address::Node(2),
to: Address::Node(1),
term: 3,
event: Event::ReplicateEntries {
event: Event::AppendEntries {
base_index: 5,
base_term: 2,
entries: vec![Entry { index: 6, term: 3, command: Some(vec![0x04]) }],
Expand All @@ -783,14 +783,14 @@ pub mod tests {
}

#[test]
// ReplicateEntries rejects conflicting base term
fn step_replicateentries_reject_missing_base_term() -> Result<()> {
// AppendEntries rejects conflicting base term
fn step_appendentries_reject_missing_base_term() -> Result<()> {
let (follower, mut node_rx, mut state_rx) = setup()?;
let mut node = follower.step(Message {
from: Address::Node(2),
to: Address::Node(1),
term: 3,
event: Event::ReplicateEntries {
event: Event::AppendEntries {
base_index: 1,
base_term: 2,
entries: vec![Entry { index: 2, term: 3, command: Some(vec![0x04]) }],
Expand Down
12 changes: 6 additions & 6 deletions src/raft/node/leader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl RoleNode<Leader> {
};
let entries = self.log.scan(peer_next..)?.collect::<Result<Vec<_>>>()?;
debug!("Replicating {} entries at base {} to {}", entries.len(), base_index, peer);
self.send(Address::Node(peer), Event::ReplicateEntries { base_index, base_term, entries })?;
self.send(Address::Node(peer), Event::AppendEntries { base_index, base_term, entries })?;
Ok(())
}

Expand All @@ -113,14 +113,14 @@ impl RoleNode<Leader> {

// If we receive a message for a future term, become a leaderless
// follower in it and step the message. If the message is a Heartbeat or
// ReplicateEntries from the leader, stepping it will follow the leader.
// AppendEntries from the leader, stepping it will follow the leader.
if msg.term > self.term {
return self.become_follower(msg.term)?.step(msg);
}

match msg.event {
// There can't be two leaders in the same term.
Event::Heartbeat { .. } | Event::ReplicateEntries { .. } => {
Event::Heartbeat { .. } | Event::AppendEntries { .. } => {
panic!("Saw other leader {} in term {}", msg.from.unwrap(), msg.term);
}

Expand Down Expand Up @@ -308,7 +308,7 @@ mod tests {
from: Address::Node(1),
to: Address::Node(2),
term: 3,
event: Event::ReplicateEntries { base_index: 5, base_term: 3, entries: vec![] },
event: Event::AppendEntries { base_index: 5, base_term: 3, entries: vec![] },
}],
);
assert_messages(
Expand Down Expand Up @@ -535,7 +535,7 @@ mod tests {
from: Address::Node(1),
to: Address::Node(2),
term: 3,
event: Event::ReplicateEntries {
event: Event::AppendEntries {
base_index: index as Index,
base_term: if index > 0 {
entries.get(index - 1).map(|e| e.term).unwrap()
Expand Down Expand Up @@ -616,7 +616,7 @@ mod tests {
from: Address::Node(1),
to: Address::Node(peer),
term: 3,
event: Event::ReplicateEntries {
event: Event::AppendEntries {
base_index: 5,
base_term: 3,
entries: vec![Entry { index: 6, term: 3, command: Some(vec![0xaf]) },]
Expand Down

0 comments on commit 491ff9e

Please sign in to comment.