Bump dependency on lru to from version 0.7.5 to version 0.9.0. (#1755)

This commit is contained in:
Adam Reichold
2023-01-10 05:35:37 +01:00
committed by GitHub
parent 3090d49615
commit 82a183bc2d
2 changed files with 23 additions and 10 deletions

View File

@@ -48,7 +48,7 @@ murmurhash32 = "0.2.0"
time = { version = "0.3.10", features = ["serde-well-known"] }
smallvec = "1.8.0"
rayon = "1.5.2"
lru = "0.7.5"
lru = "0.9.0"
fastdivide = "0.4.0"
itertools = "0.10.3"
measure_time = "0.8.2"

View File

@@ -1,5 +1,6 @@
use std::io;
use std::iter::Sum;
use std::num::NonZeroUsize;
use std::ops::{AddAssign, Range};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
@@ -33,23 +34,29 @@ pub struct StoreReader {
/// The cache for decompressed blocks.
struct BlockCache {
cache: Mutex<LruCache<usize, Block>>,
cache_hits: Arc<AtomicUsize>,
cache_misses: Arc<AtomicUsize>,
cache: Option<Mutex<LruCache<usize, Block>>>,
cache_hits: AtomicUsize,
cache_misses: AtomicUsize,
}
impl BlockCache {
fn get_from_cache(&self, pos: usize) -> Option<Block> {
if let Some(block) = self.cache.lock().unwrap().get(&pos) {
if let Some(block) = self
.cache
.as_ref()
.and_then(|cache| cache.lock().unwrap().get(&pos).cloned())
{
self.cache_hits.fetch_add(1, Ordering::SeqCst);
return Some(block.clone());
return Some(block);
}
self.cache_misses.fetch_add(1, Ordering::SeqCst);
None
}
fn put_into_cache(&self, pos: usize, data: Block) {
self.cache.lock().unwrap().put(pos, data);
if let Some(cache) = self.cache.as_ref() {
cache.lock().unwrap().put(pos, data);
}
}
fn stats(&self) -> CacheStats {
@@ -59,13 +66,18 @@ impl BlockCache {
num_entries: self.len(),
}
}
fn len(&self) -> usize {
self.cache.lock().unwrap().len()
self.cache
.as_ref()
.map_or(0, |cache| cache.lock().unwrap().len())
}
#[cfg(test)]
fn peek_lru(&self) -> Option<usize> {
self.cache.lock().unwrap().peek_lru().map(|(&k, _)| k)
self.cache
.as_ref()
.and_then(|cache| cache.lock().unwrap().peek_lru().map(|(&k, _)| k))
}
}
@@ -113,7 +125,8 @@ impl StoreReader {
decompressor: footer.decompressor,
data: data_file,
cache: BlockCache {
cache: Mutex::new(LruCache::new(cache_size)),
cache: NonZeroUsize::new(cache_size)
.map(|cache_size| Mutex::new(LruCache::new(cache_size))),
cache_hits: Default::default(),
cache_misses: Default::default(),
},