From a16faee0868bf88990bcabc90c7419a52102d82a Mon Sep 17 00:00:00 2001 From: Pascal Seitz Date: Thu, 19 Nov 2026 13:38:50 +0100 Subject: [PATCH] Name streamed ranges and candidate dictionary blocks --- common/src/file_slice.rs | 38 ++++++------------- src/index/inverted_index_reader.rs | 28 +++++++------- .../automaton_bitset_tests.rs | 2 +- src/termdict/mod.rs | 2 +- sstable/src/streamer.rs | 6 +-- 5 files changed, 29 insertions(+), 47 deletions(-) diff --git a/common/src/file_slice.rs b/common/src/file_slice.rs index 6fce5a8b3..a51c2e9d2 100644 --- a/common/src/file_slice.rs +++ b/common/src/file_slice.rs @@ -40,7 +40,7 @@ pub trait FileHandle: 'static + Send + Sync + HasLen + fmt::Debug { /// without buffering an entire merged read. Dropping the stream cancels further reads. /// The default calls `read_bytes_async` for one range at a time. Invalid ranges may panic. #[cfg(feature = "quickwit")] - fn read_bytes_batch_stream( + fn stream_ranges( &self, ranges: Box> + Send>, ) -> BoxStream<'_, io::Result> { @@ -338,16 +338,15 @@ impl FileHandle for FileSlice { } #[cfg(feature = "quickwit")] - fn read_bytes_batch_stream( + fn stream_ranges( &self, ranges: Box> + Send>, ) -> BoxStream<'_, io::Result> { let slice = self.range.clone(); - self.data - .read_bytes_batch_stream(Box::new(ranges.map(move |range| { - assert!(range.start <= range.end && range.end <= slice.len()); - slice.start + range.start..slice.start + range.end - }))) + self.data.stream_ranges(Box::new(ranges.map(move |range| { + assert!(range.start <= range.end && range.end <= slice.len()); + slice.start + range.start..slice.start + range.end + }))) } } @@ -426,7 +425,6 @@ mod tests { use super::*; use crate::OwnedBytes; - use crate::file_slice::WrapFile; #[test] fn nested_slices() { @@ -445,21 +443,21 @@ mod tests { panic!("expected a streaming read"); } - fn read_bytes_batch_stream( + fn stream_ranges( &self, ranges: Box> + Send>, ) -> BoxStream<'_, io::Result> { let ranges: Vec<_> = ranges.collect(); assert_eq!(ranges, [4..6, 2..3]); static BYTES: &[u8] = b"abcdefgh"; - BYTES.read_bytes_batch_stream(Box::new(ranges.into_iter())) + BYTES.stream_ranges(Box::new(ranges.into_iter())) } } async { let inner = FileSlice::new(Arc::new(StreamOnlyHandle)).slice(1..8); let outer = FileSlice::new(Arc::new(inner)).slice(1..6); - let mut stream = outer.read_bytes_batch_stream(Box::new([2..4, 0..1].into_iter())); + let mut stream = outer.stream_ranges(Box::new([2..4, 0..1].into_iter())); assert_eq!(&*stream.try_next().await.unwrap().unwrap(), b"ef"); assert_eq!(&*stream.try_next().await.unwrap().unwrap(), b"c"); assert!(stream.try_next().await.unwrap().is_none()); @@ -477,7 +475,7 @@ mod tests { async { for handle in handles { let ranges = [1..4, 6..6, 1..4]; - let mut stream = handle.read_bytes_batch_stream(Box::new(ranges.into_iter())); + let mut stream = handle.stream_ranges(Box::new(ranges.into_iter())); for expected in [b"bcd".as_slice(), b"", b"bcd"] { assert_eq!(&*stream.try_next().await.unwrap().unwrap(), expected); } @@ -495,27 +493,13 @@ mod tests { for range in [0..4, 4..4, Range { start: 2, end: 1 }] { assert!( catch_unwind(AssertUnwindSafe(|| { - let mut stream = - outer.read_bytes_batch_stream(Box::new(std::iter::once(range))); + let mut stream = outer.stream_ranges(Box::new(std::iter::once(range))); let _ = stream.try_next().now_or_never(); })) .is_err() ); } } - - #[test] - fn default_unsupported() { - let handle = - WrapFile::new(std::fs::File::open(std::env::current_exe().unwrap()).unwrap()) - .unwrap(); - let result = handle - .read_bytes_batch_stream(Box::new(std::iter::once(0..0))) - .try_next() - .now_or_never() - .unwrap(); - assert_eq!(result.err().unwrap().kind(), io::ErrorKind::Unsupported); - } } #[test] diff --git a/src/index/inverted_index_reader.rs b/src/index/inverted_index_reader.rs index 746945111..3918538b1 100644 --- a/src/index/inverted_index_reader.rs +++ b/src/index/inverted_index_reader.rs @@ -521,14 +521,14 @@ impl InvertedIndexReader { A::State: Clone + Send + 'static, { const TARGET_BATCH_BYTES: usize = 1024 * 1024; - let (file, blocks) = self.termdict.matching_blocks(&automaton); + let (file, blocks) = self.termdict.candidate_blocks(&automaton); let (ranges, block_info): (Vec<_>, Vec<_>) = blocks .map(|block| { - let info = (block.byte_range.len(), block.first_ordinal); - (block.byte_range, info) + let len = block.byte_range.len(); + (block.byte_range, (len, block.first_ordinal)) }) .unzip(); - let mut reads = file.read_bytes_batch_stream(Box::new(ranges.into_iter())); + let mut dictionary_blocks = file.stream_ranges(Box::new(ranges.into_iter())); let mut block_info = block_info.into_iter().peekable(); let mut encoded_terminfo = Vec::new(); let mut previous_end = 0; @@ -537,7 +537,7 @@ impl InvertedIndexReader { let mut batch_bytes = 0; let mut batch = Vec::new(); for (len, first_ordinal) in block_info.by_ref() { - let bytes = reads + let bytes = dictionary_blocks .try_next() .await? .ok_or(io::ErrorKind::UnexpectedEof)?; @@ -557,7 +557,7 @@ impl InvertedIndexReader { .termdict .search(automaton) .without_keys() - .into_stream_given_delta_reader(sstable::DeltaReader::from_multiple_blocks(batch))? + .into_stream_from_delta_reader(sstable::DeltaReader::from_multiple_blocks(batch))? .into_owned(); (automaton, encoded_terminfo, previous_end) = executor .spawn_blocking(move || { @@ -574,13 +574,13 @@ impl InvertedIndexReader { .await .map_err(|_| io::Error::other("automaton term enumeration task panicked"))?; } - if reads.try_next().await?.is_some() { + if dictionary_blocks.try_next().await?.is_some() { return Err(io::Error::new( io::ErrorKind::InvalidData, "unexpected dictionary block", )); } - drop(reads); + drop(dictionary_blocks); let mut bitset = BitSet::with_max_value(max_doc); if encoded_terminfo.is_empty() { return Ok(bitset); @@ -599,16 +599,14 @@ impl InvertedIndexReader { Some((start..end, next() as u32)) }); let ranges = terms.clone().map(|(range, _)| range); - let mut postings = self - .postings_file_slice - .read_bytes_batch_stream(Box::new(ranges)); + let mut posting_lists = self.postings_file_slice.stream_ranges(Box::new(ranges)); let mut terms = terms.peekable(); let record_option = self.record_option; while terms.peek().is_some() { let mut batch = Vec::new(); let mut batch_bytes = 0; for (range, doc_freq) in terms.by_ref() { - let bytes = postings + let bytes = posting_lists .try_next() .await? .ok_or(io::ErrorKind::UnexpectedEof)?; @@ -624,7 +622,7 @@ impl InvertedIndexReader { break; } } - let add_batch = move || -> io::Result { + let insert_doc_ids = move || -> io::Result { for (doc_freq, bytes) in batch { let mut postings = BlockSegmentPostings::open_bytes( doc_freq, @@ -642,11 +640,11 @@ impl InvertedIndexReader { Ok(bitset) }; bitset = executor - .spawn_blocking(add_batch) + .spawn_blocking(insert_doc_ids) .await .map_err(|_| io::Error::other("automaton bitset task panicked"))??; } - if postings.try_next().await?.is_some() { + if posting_lists.try_next().await?.is_some() { return Err(io::Error::new( io::ErrorKind::InvalidData, "unexpected posting list", diff --git a/src/index/inverted_index_reader/automaton_bitset_tests.rs b/src/index/inverted_index_reader/automaton_bitset_tests.rs index 60dbd70fe..4c696851b 100644 --- a/src/index/inverted_index_reader/automaton_bitset_tests.rs +++ b/src/index/inverted_index_reader/automaton_bitset_tests.rs @@ -29,7 +29,7 @@ impl FileHandle for StreamingPostings { panic!("postings must be streamed"); } - fn read_bytes_batch_stream( + fn stream_ranges( &self, ranges: Box> + Send>, ) -> BoxStream<'_, io::Result> { diff --git a/src/termdict/mod.rs b/src/termdict/mod.rs index 13ad8693e..aa66914ea 100644 --- a/src/termdict/mod.rs +++ b/src/termdict/mod.rs @@ -158,7 +158,7 @@ impl TermDictionary { } #[cfg(feature = "quickwit")] - pub(crate) fn matching_blocks<'a, 's: 'a>( + pub(crate) fn candidate_blocks<'a, 's: 'a>( &'s self, automaton: &'a impl Automaton, ) -> (&'s FileSlice, impl Iterator + 'a) { diff --git a/sstable/src/streamer.rs b/sstable/src/streamer.rs index aab7411c6..d97bea23f 100644 --- a/sstable/src/streamer.rs +++ b/sstable/src/streamer.rs @@ -167,7 +167,7 @@ where } /// Searches dictionary blocks supplied by the caller instead of reading them from the file. - pub fn into_stream_given_delta_reader( + pub fn into_stream_from_delta_reader( self, delta_reader: DeltaReader<::ValueReader>, ) -> io::Result> { @@ -217,14 +217,14 @@ where merge_holes_under_bytes: usize, ) -> io::Result> { let delta_reader = self.delta_reader_async(merge_holes_under_bytes).await?; - self.into_stream_given_delta_reader(delta_reader) + self.into_stream_from_delta_reader(delta_reader) } /// Creates the stream corresponding to the range /// of terms defined using the `StreamerBuilder`. pub fn into_stream(self) -> io::Result> { let delta_reader = self.delta_reader()?; - self.into_stream_given_delta_reader(delta_reader) + self.into_stream_from_delta_reader(delta_reader) } }