From 44e81bd7671970feb86fdb346fc1533ecd4e5dd4 Mon Sep 17 00:00:00 2001 From: discord9 Date: Thu, 11 Dec 2025 11:17:44 +0800 Subject: [PATCH] refactor(sst): extract index version check into method Signed-off-by: discord9 --- src/mito2/src/sst/file.rs | 5 +++++ src/mito2/src/sst/version.rs | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/mito2/src/sst/file.rs b/src/mito2/src/sst/file.rs index 8232f3c611..7ab8ee132b 100644 --- a/src/mito2/src/sst/file.rs +++ b/src/mito2/src/sst/file.rs @@ -306,6 +306,11 @@ impl FileMeta { !self.available_indexes.is_empty() } + /// Whether the index file is up-to-date comparing to another file meta. + pub fn is_index_up_to_date(&self, other: &FileMeta) -> bool { + self.exists_index() && other.exists_index() && self.index_version >= other.index_version + } + /// Returns true if the file has an inverted index pub fn inverted_index_available(&self) -> bool { self.available_indexes.contains(&IndexType::InvertedIndex) diff --git a/src/mito2/src/sst/version.rs b/src/mito2/src/sst/version.rs index f93140ffac..a9e71eb5d9 100644 --- a/src/mito2/src/sst/version.rs +++ b/src/mito2/src/sst/version.rs @@ -63,10 +63,8 @@ impl SstVersion { .files .entry(file.file_id) .and_modify(|f| { - let is_same = *f.meta_ref() == file; - let is_index_up_to_date = f.meta_ref().exists_index() && file.exists_index() && f.index_id().version >= new_index_version; - if is_same || is_index_up_to_date { - // current file handle's index is up-to-date, skip adding + if *f.meta_ref() == file || f.meta_ref().is_index_up_to_date(&file) { + // same file meta or current file handle's index is up-to-date, skip adding if f.index_id().version > new_index_version { // what does it mean for us to see older index version? common_telemetry::warn!(