diff --git a/cas/store/memory_store.rs b/cas/store/memory_store.rs index 63c5167a1..410da84cf 100644 --- a/cas/store/memory_store.rs +++ b/cas/store/memory_store.rs @@ -15,7 +15,7 @@ use evicting_map::EvictingMap; use traits::{ResultFuture, StoreTrait, UploadSizeInfo}; pub struct MemoryStore { - map: Mutex>, + map: Mutex, Instant>>, } impl MemoryStore { @@ -38,7 +38,7 @@ impl StoreTrait for MemoryStore { fn has<'a>(self: std::pin::Pin<&'a Self>, digest: DigestInfo) -> ResultFuture<'a, Option> { Box::pin(async move { let mut map = self.map.lock().await; - Ok(map.size_for_key(&digest)) + Ok(map.size_for_key(&digest).map(|v| v as usize)) }) } diff --git a/util/evicting_map.rs b/util/evicting_map.rs index e9347decc..a1201e65b 100644 --- a/util/evicting_map.rs +++ b/util/evicting_map.rs @@ -21,21 +21,31 @@ impl InstantWrapper for Instant { } } -struct EvictionItem { +struct EvictionItem { seconds_since_anchor: u32, - data: Arc>, + data: Arc, } -pub struct EvictingMap { - lru: LruCache, - anchor_time: T, +pub trait LenEntry { + fn len(&self) -> usize; +} + +impl LenEntry for Vec { + fn len(&self) -> usize { + >::len(self) + } +} + +pub struct EvictingMap { + lru: LruCache>, + anchor_time: I, sum_store_size: usize, max_bytes: usize, max_seconds: u32, } -impl EvictingMap { - pub fn new(config: &EvictionPolicy, anchor_time: T) -> Self { +impl EvictingMap { + pub fn new(config: &EvictionPolicy, anchor_time: I) -> Self { let mut lru = LruCache::unbounded(); if config.max_count != 0 { lru = LruCache::new(config.max_count.try_into().expect("Could not convert max_count to u64")); @@ -81,7 +91,7 @@ impl EvictingMap { None } - pub fn get<'a>(&'a mut self, hash: &DigestInfo) -> Option<&'a Arc>> { + pub fn get<'a>(&'a mut self, hash: &DigestInfo) -> Option<&'a Arc> { if let Some(mut entry) = self.lru.get_mut(hash) { entry.seconds_since_anchor = self.anchor_time.elapsed().as_secs() as u32; return Some(&entry.data); @@ -89,7 +99,7 @@ impl EvictingMap { None } - pub fn insert(&mut self, hash: DigestInfo, data: Arc>) { + pub fn insert(&mut self, hash: DigestInfo, data: Arc) { let new_item_size = data.len(); let eviction_item = EvictionItem { seconds_since_anchor: self.anchor_time.elapsed().as_secs() as u32, diff --git a/util/tests/evicting_map_test.rs b/util/tests/evicting_map_test.rs index 3d79851a6..a136cfd46 100644 --- a/util/tests/evicting_map_test.rs +++ b/util/tests/evicting_map_test.rs @@ -31,7 +31,7 @@ mod evicting_map_tests { #[tokio::test] async fn insert_purges_at_max_count() -> Result<(), Error> { - let mut evicting_map = EvictingMap::new( + let mut evicting_map = EvictingMap::, Instant>::new( &EvictionPolicy { max_count: 3, max_seconds: 0, @@ -70,7 +70,7 @@ mod evicting_map_tests { #[tokio::test] async fn insert_purges_at_max_bytes() -> Result<(), Error> { - let mut evicting_map = EvictingMap::new( + let mut evicting_map = EvictingMap::, Instant>::new( &EvictionPolicy { max_count: 0, max_seconds: 0, @@ -110,7 +110,7 @@ mod evicting_map_tests { #[tokio::test] async fn insert_purges_at_max_seconds() -> Result<(), Error> { - let mut evicting_map = EvictingMap::new( + let mut evicting_map = EvictingMap::, MockInstantWrapped>::new( &EvictionPolicy { max_count: 0, max_seconds: 5, @@ -154,7 +154,7 @@ mod evicting_map_tests { #[tokio::test] async fn get_refreshes_time() -> Result<(), Error> { - let mut evicting_map = EvictingMap::new( + let mut evicting_map = EvictingMap::, MockInstantWrapped>::new( &EvictionPolicy { max_count: 0, max_seconds: 3, @@ -193,7 +193,7 @@ mod evicting_map_tests { #[tokio::test] async fn contains_key_refreshes_time() -> Result<(), Error> { - let mut evicting_map = EvictingMap::new( + let mut evicting_map = EvictingMap::, MockInstantWrapped>::new( &EvictionPolicy { max_count: 0, max_seconds: 3, @@ -232,7 +232,7 @@ mod evicting_map_tests { #[tokio::test] async fn hashes_equal_sizes_different_doesnt_override() -> Result<(), Error> { - let mut evicting_map = EvictingMap::new( + let mut evicting_map = EvictingMap::, Instant>::new( &EvictionPolicy { max_count: 0, max_seconds: 0,