From af02bc7aafd951ef48f0f5b191c4fa966bbf152d Mon Sep 17 00:00:00 2001 From: grapebaba <281165273@qq.com> Date: Wed, 5 Jan 2022 12:00:34 +0800 Subject: [PATCH] Make first_known_log_id default impl Signed-off-by: grapebaba <281165273@qq.com> --- memstore/src/lib.rs | 11 ----------- openraft/src/storage.rs | 11 ++++++++++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/memstore/src/lib.rs b/memstore/src/lib.rs index 861ff441f..cb766da7a 100644 --- a/memstore/src/lib.rs +++ b/memstore/src/lib.rs @@ -302,17 +302,6 @@ impl RaftStorage for MemStore { Ok(first) } - async fn first_known_log_id(&self) -> Result { - let first = self.first_id_in_log().await?; - let (last_applied, _) = self.last_applied_state().await?; - - if let Some(x) = first { - return Ok(std::cmp::min(x, last_applied)); - } - - Ok(last_applied) - } - async fn last_id_in_log(&self) -> Result { let log = self.log.read().await; let last = log.iter().last().map(|(_, ent)| ent.log_id).unwrap_or_default(); diff --git a/openraft/src/storage.rs b/openraft/src/storage.rs index 79ca96bd3..7deb5cb9c 100644 --- a/openraft/src/storage.rs +++ b/openraft/src/storage.rs @@ -172,7 +172,16 @@ where /// The impl should not consider the applied log id in state machine. async fn first_id_in_log(&self) -> Result, StorageError>; - async fn first_known_log_id(&self) -> Result; + async fn first_known_log_id(&self) -> Result { + let first = self.first_id_in_log().await?; + let (last_applied, _) = self.last_applied_state().await?; + + if let Some(x) = first { + return Ok(std::cmp::min(x, last_applied)); + } + + Ok(last_applied) + } /// Returns the last log id in log. ///