From 5a026674617b5e4f5402ff148d261169fe392b24 Mon Sep 17 00:00:00 2001 From: YangKian <1207783292@qq.com> Date: Sat, 8 Jan 2022 03:00:59 +0800 Subject: [PATCH] Fix: defensive_no_dirty_log hangs tests --- openraft/src/defensive.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/openraft/src/defensive.rs b/openraft/src/defensive.rs index 7477c8f07..c4551e7ee 100644 --- a/openraft/src/defensive.rs +++ b/openraft/src/defensive.rs @@ -39,16 +39,17 @@ where let (last_applied, _) = self.inner().last_applied_state().await?; let (_, last) = self.inner().get_log_state().await?; - let last_log_id = last.expect("last_log_id should not be None."); - if last_log_id.index > last_applied.index && last_log_id < last_applied { - return Err( - DefensiveError::new(ErrorSubject::Log(last_log_id), Violation::DirtyLog { - higher_index_log_id: last_log_id, - lower_index_log_id: last_applied, - }) - .into(), - ); + if let Some(last_log_id) = last { + if last_log_id.index > last_applied.index && last_log_id < last_applied { + return Err( + DefensiveError::new(ErrorSubject::Log(last_log_id), Violation::DirtyLog { + higher_index_log_id: last_log_id, + lower_index_log_id: last_applied, + }) + .into(), + ); + } } Ok(())