Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions quickwit/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions quickwit/quickwit-directories/src/caching_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::sync::Arc;
use std::{fmt, io};

use async_trait::async_trait;
use quickwit_storage::ByteRangeCache;
use quickwit_storage::{ByteRangeCache, FileByteRangeCache};
use tantivy::directory::error::OpenReadError;
use tantivy::directory::{FileHandle, OwnedBytes};
use tantivy::{Directory, HasLen};
Expand Down Expand Up @@ -58,7 +58,7 @@ impl fmt::Debug for CachingDirectory {

struct CachingFileHandle {
path: PathBuf,
cache: ByteRangeCache,
cache: FileByteRangeCache,
underlying_filehandle: Arc<dyn FileHandle>,
}

Expand All @@ -76,25 +76,23 @@ impl fmt::Debug for CachingFileHandle {
#[async_trait]
impl FileHandle for CachingFileHandle {
fn read_bytes(&self, byte_range: Range<usize>) -> io::Result<OwnedBytes> {
if let Some(bytes) = self.cache.get_slice(&self.path, byte_range.clone()) {
if let Some(bytes) = self.cache.get_slice(byte_range.clone()) {
return Ok(bytes);
}
let owned_bytes = self.underlying_filehandle.read_bytes(byte_range.clone())?;
self.cache
.put_slice(self.path.clone(), byte_range, owned_bytes.clone());
self.cache.put_slice(byte_range, owned_bytes.clone());
Ok(owned_bytes)
}

async fn read_bytes_async(&self, byte_range: Range<usize>) -> io::Result<OwnedBytes> {
if let Some(owned_bytes) = self.cache.get_slice(&self.path, byte_range.clone()) {
if let Some(owned_bytes) = self.cache.get_slice(byte_range.clone()) {
return Ok(owned_bytes);
}
let read_bytes = self
.underlying_filehandle
.read_bytes_async(byte_range.clone())
.await?;
self.cache
.put_slice(self.path.clone(), byte_range, read_bytes.clone());
self.cache.put_slice(byte_range, read_bytes.clone());
Ok(read_bytes)
}
}
Expand All @@ -117,7 +115,7 @@ impl Directory for CachingDirectory {
let underlying_filehandle = self.underlying.get_file_handle(path)?;
let caching_file_handle = CachingFileHandle {
path: path.to_path_buf(),
cache: self.cache.clone(),
cache: self.cache.get_file_cache(path),
underlying_filehandle,
};
Ok(Arc::new(caching_file_handle))
Expand Down
1 change: 1 addition & 0 deletions quickwit/quickwit-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mockall = { workspace = true, optional = true }
pin-project = { workspace = true }
quick_cache = { workspace = true }
regex = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
stable_deref_trait = { workspace = true }
Expand Down
Loading
Loading