From e56a0256595ac8ca0357d350121ea9b7cfebdf7a Mon Sep 17 00:00:00 2001 From: Kryesh Date: Tue, 3 Dec 2024 12:25:38 +1100 Subject: [PATCH] Add "has_merging_threads" function to check if a writer has pending merges --- src/indexer/index_writer.rs | 6 ++++++ src/indexer/segment_updater.rs | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/indexer/index_writer.rs b/src/indexer/index_writer.rs index 6719afe9f9..fdef1f5835 100644 --- a/src/indexer/index_writer.rs +++ b/src/indexer/index_writer.rs @@ -328,6 +328,12 @@ impl IndexWriter { &self.index } + /// Check if there are any merging threads + /// Does not block + pub fn has_merging_threads(&self) -> bool { + self.segment_updater.has_merging_threads() + } + /// If there are some merging threads, blocks until they all finish their work and /// then drop the `IndexWriter`. pub fn wait_merging_threads(mut self) -> crate::Result<()> { diff --git a/src/indexer/segment_updater.rs b/src/indexer/segment_updater.rs index ba987c18da..7245d8ca2b 100644 --- a/src/indexer/segment_updater.rs +++ b/src/indexer/segment_updater.rs @@ -645,6 +645,11 @@ impl SegmentUpdater { Ok(after_merge_segment_meta) } + /// Check if there are still pending merges without blocking + pub fn has_merging_threads(&self) -> bool { + self.merge_operations.len() > 0 + } + /// Wait for current merging threads. /// /// Upon termination of the current merging threads,