mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-04 00:02:55 +00:00
Allow cheaply cloning a StoreReader to enable user control over block cache usage.
This commit is contained in:
@@ -40,6 +40,15 @@ struct BlockCache {
|
||||
}
|
||||
|
||||
impl BlockCache {
|
||||
fn new(cache_num_blocks: usize) -> Self {
|
||||
Self {
|
||||
cache: NonZeroUsize::new(cache_num_blocks)
|
||||
.map(|cache_num_blocks| Mutex::new(LruCache::new(cache_num_blocks))),
|
||||
cache_hits: Default::default(),
|
||||
cache_misses: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_from_cache(&self, pos: usize) -> Option<Block> {
|
||||
if let Some(block) = self
|
||||
.cache
|
||||
@@ -128,17 +137,23 @@ impl StoreReader {
|
||||
Ok(StoreReader {
|
||||
decompressor: footer.decompressor,
|
||||
data: data_file,
|
||||
cache: BlockCache {
|
||||
cache: NonZeroUsize::new(cache_num_blocks)
|
||||
.map(|cache_num_blocks| Mutex::new(LruCache::new(cache_num_blocks))),
|
||||
cache_hits: Default::default(),
|
||||
cache_misses: Default::default(),
|
||||
},
|
||||
cache: BlockCache::new(cache_num_blocks),
|
||||
skip_index: Arc::new(skip_index),
|
||||
space_usage,
|
||||
})
|
||||
}
|
||||
|
||||
/// Clones the given store reader with an independent block cache of the given size.
|
||||
pub fn fork_cache(&self, cache_num_blocks: usize) -> Self {
|
||||
Self {
|
||||
decompressor: self.decompressor,
|
||||
data: self.data.clone(),
|
||||
cache: BlockCache::new(cache_num_blocks),
|
||||
skip_index: Arc::clone(&self.skip_index),
|
||||
space_usage: self.space_usage.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn block_checkpoints(&self) -> impl Iterator<Item = Checkpoint> + '_ {
|
||||
self.skip_index.checkpoints()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user