From f65f11330837e7c5b5524be8024f1ec93fea02b4 Mon Sep 17 00:00:00 2001 From: ilya Date: Wed, 1 Dec 2021 13:16:33 +0000 Subject: [PATCH] Protecting against cases where leader is told its behind after it has already advanced to a further term --- Cargo.lock | 2 +- little_raft/Cargo.toml | 2 +- little_raft/src/replica.rs | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 806abba..dcc9a59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -118,7 +118,7 @@ checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" [[package]] name = "little_raft" -version = "0.1.3" +version = "0.1.5" dependencies = [ "crossbeam", "crossbeam-channel", diff --git a/little_raft/Cargo.toml b/little_raft/Cargo.toml index ad44d83..e9db923 100644 --- a/little_raft/Cargo.toml +++ b/little_raft/Cargo.toml @@ -1,7 +1,7 @@ [package] description = "The lightest distributed consensus library. Run your own replicated state machine!" name = "little_raft" -version = "0.1.4" +version = "0.1.5" authors = ["Ilya Andreev "] edition = "2018" license = "MIT" diff --git a/little_raft/src/replica.rs b/little_raft/src/replica.rs index 1397328..ce7e40c 100644 --- a/little_raft/src/replica.rs +++ b/little_raft/src/replica.rs @@ -413,10 +413,11 @@ where // to the Raft paper's guidance on decreasing next_index by // one at a time, but is more performant in cases when we // can cut straight to the follower's last_index+1. - let mismatch_index = mismatch_index.unwrap(); - if mismatch_index < self.next_index[&from_id] { - let next_index = cmp::min(mismatch_index, last_index + 1); - self.next_index.insert(from_id, next_index); + if let Some(mismatch_index) = mismatch_index { + if mismatch_index < self.next_index[&from_id] { + let next_index = cmp::min(mismatch_index, last_index + 1); + self.next_index.insert(from_id, next_index); + } } } }