From 32cb1d22dab2a20659211d5dee38e3c60af4ba28 Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Wed, 21 Dec 2022 16:01:17 +0900 Subject: [PATCH] Removed AsyncIoResult. (#1728) --- bitpacker/src/bitpacker.rs | 8 +++---- src/core/inverted_index_reader.rs | 15 ++++-------- src/directory/file_slice.rs | 29 +++++++++-------------- src/error.rs | 22 ----------------- src/lib.rs | 4 ---- src/store/reader.rs | 2 +- src/termdict/sstable_termdict/termdict.rs | 7 +++--- 7 files changed, 22 insertions(+), 65 deletions(-) diff --git a/bitpacker/src/bitpacker.rs b/bitpacker/src/bitpacker.rs index 7378266a7..0a1469b9f 100644 --- a/bitpacker/src/bitpacker.rs +++ b/bitpacker/src/bitpacker.rs @@ -91,15 +91,13 @@ impl BitUnpacker { return 0u64; } let addr_in_bits = idx * self.num_bits as u32; - let addr = addr_in_bits >> 3; + let addr = (addr_in_bits >> 3) as usize; let bit_shift = addr_in_bits & 7; debug_assert!( - addr + 8 <= data.len() as u32, + addr + 8 <= data.len(), "The fast field field should have been padded with 7 bytes." ); - let bytes: [u8; 8] = (&data[(addr as usize)..(addr as usize) + 8]) - .try_into() - .unwrap(); + let bytes: [u8; 8] = (&data[addr..addr + 8]).try_into().unwrap(); let val_unshifted_unmasked: u64 = u64::from_le_bytes(bytes); let val_shifted = val_unshifted_unmasked >> bit_shift; val_shifted & self.mask diff --git a/src/core/inverted_index_reader.rs b/src/core/inverted_index_reader.rs index ee144d68a..e51421a16 100644 --- a/src/core/inverted_index_reader.rs +++ b/src/core/inverted_index_reader.rs @@ -200,10 +200,7 @@ impl InvertedIndexReader { #[cfg(feature = "quickwit")] impl InvertedIndexReader { - pub(crate) async fn get_term_info_async( - &self, - term: &Term, - ) -> crate::AsyncIoResult> { + pub(crate) async fn get_term_info_async(&self, term: &Term) -> io::Result> { self.termdict.get_async(term.value_bytes()).await } @@ -211,11 +208,7 @@ impl InvertedIndexReader { /// This method is for an advanced usage only. /// /// Most users should prefer using [`Self::read_postings()`] instead. - pub async fn warm_postings( - &self, - term: &Term, - with_positions: bool, - ) -> crate::AsyncIoResult<()> { + pub async fn warm_postings(&self, term: &Term, with_positions: bool) -> io::Result<()> { let term_info_opt = self.get_term_info_async(term).await?; if let Some(term_info) = term_info_opt { self.postings_file_slice @@ -234,7 +227,7 @@ impl InvertedIndexReader { /// This method is for an advanced usage only. /// /// If you know which terms to pre-load, prefer using [`Self::warm_postings`] instead. - pub async fn warm_postings_full(&self, with_positions: bool) -> crate::AsyncIoResult<()> { + pub async fn warm_postings_full(&self, with_positions: bool) -> io::Result<()> { self.postings_file_slice.read_bytes_async().await?; if with_positions { self.positions_file_slice.read_bytes_async().await?; @@ -243,7 +236,7 @@ impl InvertedIndexReader { } /// Returns the number of documents containing the term asynchronously. - pub async fn doc_freq_async(&self, term: &Term) -> crate::AsyncIoResult { + pub async fn doc_freq_async(&self, term: &Term) -> io::Result { Ok(self .get_term_info_async(term) .await? diff --git a/src/directory/file_slice.rs b/src/directory/file_slice.rs index 1d0cd6915..3ec28e9d7 100644 --- a/src/directory/file_slice.rs +++ b/src/directory/file_slice.rs @@ -24,13 +24,12 @@ pub trait FileHandle: 'static + Send + Sync + HasLen + fmt::Debug { /// This method may panic if the range requested is invalid. fn read_bytes(&self, range: Range) -> io::Result; - #[cfg(feature = "quickwit")] #[doc(hidden)] - async fn read_bytes_async( - &self, - _byte_range: Range, - ) -> crate::AsyncIoResult { - Err(crate::error::AsyncIoError::AsyncUnsupported) + async fn read_bytes_async(&self, _byte_range: Range) -> io::Result { + Err(io::Error::new( + io::ErrorKind::Unsupported, + "Async read is not supported.", + )) } } @@ -41,8 +40,7 @@ impl FileHandle for &'static [u8] { Ok(OwnedBytes::new(bytes)) } - #[cfg(feature = "quickwit")] - async fn read_bytes_async(&self, byte_range: Range) -> crate::AsyncIoResult { + async fn read_bytes_async(&self, byte_range: Range) -> io::Result { Ok(self.read_bytes(byte_range)?) } } @@ -117,9 +115,8 @@ impl FileSlice { self.data.read_bytes(self.range.clone()) } - #[cfg(feature = "quickwit")] #[doc(hidden)] - pub async fn read_bytes_async(&self) -> crate::AsyncIoResult { + pub async fn read_bytes_async(&self) -> io::Result { self.data.read_bytes_async(self.range.clone()).await } @@ -139,10 +136,7 @@ impl FileSlice { #[cfg(feature = "quickwit")] #[doc(hidden)] - pub async fn read_bytes_slice_async( - &self, - byte_range: Range, - ) -> crate::AsyncIoResult { + pub async fn read_bytes_slice_async(&self, byte_range: Range) -> io::Result { assert!( self.range.start + byte_range.end <= self.range.end, "`to` exceeds the fileslice length" @@ -205,7 +199,7 @@ impl FileHandle for FileSlice { } #[cfg(feature = "quickwit")] - async fn read_bytes_async(&self, byte_range: Range) -> crate::AsyncIoResult { + async fn read_bytes_async(&self, byte_range: Range) -> io::Result { self.read_bytes_slice_async(byte_range).await } } @@ -223,9 +217,8 @@ impl FileHandle for OwnedBytes { } #[cfg(feature = "quickwit")] - async fn read_bytes_async(&self, range: Range) -> crate::AsyncIoResult { - let bytes = self.read_bytes(range)?; - Ok(bytes) + async fn read_bytes_async(&self, range: Range) -> io::Result { + self.read_bytes(range) } } diff --git a/src/error.rs b/src/error.rs index e8136cdef..ec3ceb87f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -104,28 +104,6 @@ pub enum TantivyError { InternalError(String), } -#[cfg(feature = "quickwit")] -#[derive(Error, Debug)] -#[doc(hidden)] -pub enum AsyncIoError { - #[error("io::Error `{0}`")] - Io(#[from] io::Error), - #[error("Asynchronous API is unsupported by this directory")] - AsyncUnsupported, -} - -#[cfg(feature = "quickwit")] -impl From for TantivyError { - fn from(async_io_err: AsyncIoError) -> Self { - match async_io_err { - AsyncIoError::Io(io_err) => TantivyError::from(io_err), - AsyncIoError::AsyncUnsupported => { - TantivyError::SystemError(format!("{:?}", async_io_err)) - } - } - } -} - impl From for TantivyError { fn from(io_err: io::Error) -> TantivyError { TantivyError::IoError(Arc::new(io_err)) diff --git a/src/lib.rs b/src/lib.rs index 53ddde564..79fe68987 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -259,10 +259,6 @@ pub use crate::future_result::FutureResult; /// and instead, refer to this as `crate::Result`. pub type Result = std::result::Result; -/// Result for an Async io operation. -#[cfg(feature = "quickwit")] -pub type AsyncIoResult = std::result::Result; - mod core; mod indexer; diff --git a/src/store/reader.rs b/src/store/reader.rs index c103c37d2..b0a3b9259 100644 --- a/src/store/reader.rs +++ b/src/store/reader.rs @@ -319,7 +319,7 @@ impl StoreReader { /// In most cases use [`get_async`](Self::get_async) /// /// Loads and decompresses a block asynchronously. - async fn read_block_async(&self, checkpoint: &Checkpoint) -> crate::AsyncIoResult { + async fn read_block_async(&self, checkpoint: &Checkpoint) -> io::Result { let cache_key = checkpoint.byte_range.start; if let Some(block) = self.cache.get_from_cache(checkpoint.byte_range.start) { return Ok(block); diff --git a/src/termdict/sstable_termdict/termdict.rs b/src/termdict/sstable_termdict/termdict.rs index c618d7ecf..b1a5d4c4b 100644 --- a/src/termdict/sstable_termdict/termdict.rs +++ b/src/termdict/sstable_termdict/termdict.rs @@ -13,7 +13,6 @@ use crate::termdict::sstable_termdict::{ TermInfoReader, TermInfoWriter, TermSSTable, TermStreamer, TermStreamerBuilder, }; use crate::termdict::TermOrdinal; -use crate::AsyncIoResult; pub struct TermInfoSSTable; impl SSTable for TermInfoSSTable { @@ -108,7 +107,7 @@ impl TermDictionary { pub(crate) async fn sstable_reader_block_async( &self, block_addr: BlockAddr, - ) -> AsyncIoResult> { + ) -> io::Result> { let data = self .sstable_slice .read_bytes_slice_async(block_addr.byte_range) @@ -216,7 +215,7 @@ impl TermDictionary { } /// Lookups the value corresponding to the key. - pub async fn get_async>(&self, key: K) -> AsyncIoResult> { + pub async fn get_async>(&self, key: K) -> io::Result> { if let Some(block_addr) = self.sstable_index.search(key.as_ref()) { let mut sstable_reader = self.sstable_reader_block_async(block_addr).await?; let key_bytes = key.as_ref(); @@ -249,7 +248,7 @@ impl TermDictionary { } #[doc(hidden)] - pub async fn warm_up_dictionary(&self) -> AsyncIoResult<()> { + pub async fn warm_up_dictionary(&self) -> io::Result<()> { self.sstable_slice.read_bytes_async().await?; Ok(()) }