From a0699b2efb7d250eee4960659f5e00f07b4223c0 Mon Sep 17 00:00:00 2001 From: Kould <2435992353@qq.com> Date: Thu, 14 Mar 2024 05:11:51 +0800 Subject: [PATCH] fix: `Bound::Excluded` may cause the read data to be empty --- Cargo.toml | 2 +- src/kernel/lsm/mvcc.rs | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 95058dc..05ab438 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kip_db" -version = "0.1.2-alpha.25.fix1" +version = "0.1.2-alpha.25.fix2" edition = "2021" authors = ["Kould "] description = "轻量级、异步 基于LSM Leveled Compaction K-V数据库" diff --git a/src/kernel/lsm/mvcc.rs b/src/kernel/lsm/mvcc.rs index bae5ffe..ff99051 100644 --- a/src/kernel/lsm/mvcc.rs +++ b/src/kernel/lsm/mvcc.rs @@ -214,14 +214,22 @@ impl<'a> Iter<'a> for TransactionIter<'a> { let mut item = self.inner.try_next()?; if !self.is_inited { - item = match &self.min { - Bound::Included(key) => item.and_then(|data| (data.0 >= key).then_some(data)), - Bound::Excluded(key) => item.and_then(|data| (data.0 > key).then_some(data)), - Bound::Unbounded => item, - }; + loop { + if match &self.min { + Bound::Included(key) => { + !matches!(item.as_ref().map(|data| data.0 < key), Some(true)) + } + Bound::Excluded(key) => { + !matches!(item.as_ref().map(|data| data.0 <= key), Some(true)) + } + Bound::Unbounded => true, + } { + break; + } + item = self.inner.try_next()?; + } self.is_inited = true } - let option = match &self.max { Bound::Included(key) => item.and_then(|data| (data.0 <= key).then_some(data)), Bound::Excluded(key) => item.and_then(|data| (data.0 < key).then_some(data)),