From 96581eb6569aba13875812e55143a4b327b55d67 Mon Sep 17 00:00:00 2001 From: Croxx Date: Thu, 10 Oct 2024 17:58:14 +0800 Subject: [PATCH] fix: don't scale in shards when capacity is not enough, just warn (#769) Signed-off-by: MrCroxx --- foyer-memory/src/cache.rs | 11 ++--------- foyer-memory/src/generic.rs | 2 -- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/foyer-memory/src/cache.rs b/foyer-memory/src/cache.rs index c44818d5..47faf6be 100644 --- a/foyer-memory/src/cache.rs +++ b/foyer-memory/src/cache.rs @@ -401,14 +401,13 @@ where } /// Build in-memory cache with the given configuration. - pub fn build(mut self) -> Cache { + pub fn build(self) -> Cache { if self.capacity < self.shards { tracing::warn!( - "The in-memory cache capacity({}) < shards({})", + "The in-memory cache capacity({}) < shards({}).", self.capacity, self.shards ); - self.shards = 1; } match self.eviction_config { @@ -889,12 +888,6 @@ mod tests { const OPS: usize = 10000; const CONCURRENCY: usize = 8; - #[test] - fn test_not_enough_capacity() { - let cache: Cache = CacheBuilder::new(4).with_shards(64).build(); - assert_eq!(cache.shards(), 1); - } - fn fifo() -> Cache { CacheBuilder::new(CAPACITY) .with_shards(SHARDS) diff --git a/foyer-memory/src/generic.rs b/foyer-memory/src/generic.rs index d2625836..21fdef60 100644 --- a/foyer-memory/src/generic.rs +++ b/foyer-memory/src/generic.rs @@ -497,8 +497,6 @@ where S: HashBuilder, { pub fn new(config: GenericCacheConfig) -> Self { - assert!(config.capacity >= config.shards); - let metrics = Arc::new(Metrics::new(&config.name)); let usages = (0..config.shards).map(|_| Arc::new(AtomicUsize::new(0))).collect_vec();