Skip to content

Commit

Permalink
fix: skip snapshot insertion
Browse files Browse the repository at this point in the history
It is possible that the same snapshot is sent from the leader.
In this case, the follower can skip the insertion.

I don't think this is a logical bug because leader can send
a newer snapshot after it creates one.
However, rejecting replication impedes the consensus process of the
cluster which is harmful.
  • Loading branch information
akiradeveloper committed May 23, 2024
1 parent 665edd7 commit 4c8d8c0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lolraft/src/process/command_log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ impl Inner {

let cur_snapshot_index = self.snapshot_pointer.load(Ordering::SeqCst);
let new_snapshot_index = e.this_clock.index;
ensure!(new_snapshot_index > cur_snapshot_index);

// If owned snapshot is newer than the coming snapshot,
// the leader should be able to send the subsequent non-snapshot entries.
ensure!(new_snapshot_index >= cur_snapshot_index);

// If the same snapshot already exists, we can skip the insertion.
if new_snapshot_index == cur_snapshot_index {
return Ok(())
}

self.storage.insert_entry(new_snapshot_index, e).await?;

Expand Down

0 comments on commit 4c8d8c0

Please sign in to comment.