From 61045da0ad417e8775b7ce5c4c507c2cf54fc017 Mon Sep 17 00:00:00 2001 From: MrCroxx Date: Tue, 9 Jul 2024 22:46:38 +0800 Subject: [PATCH] refactor: make statistics sharable between engines Signed-off-by: MrCroxx --- foyer-storage/src/large/generic.rs | 15 ++++++++++----- foyer-storage/src/storage/runtime.rs | 2 ++ foyer-storage/src/store.rs | 7 ++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/foyer-storage/src/large/generic.rs b/foyer-storage/src/large/generic.rs index 84c94676..308a5170 100644 --- a/foyer-storage/src/large/generic.rs +++ b/foyer-storage/src/large/generic.rs @@ -83,6 +83,7 @@ where pub admission_picker: Arc>, pub reinsertion_picker: Arc>, pub tombstone_log_config: Option, + pub statistics: Arc, } impl Debug for GenericLargeStorageConfig @@ -109,6 +110,7 @@ where .field("admission_pickers", &self.admission_picker) .field("reinsertion_pickers", &self.reinsertion_picker) .field("tombstone_log_config", &self.tombstone_log_config) + .field("statistics", &self.statistics) .finish() } } @@ -151,7 +153,7 @@ where admission_picker: Arc>, - stats: Arc, + statistics: Arc, flush: bool, @@ -186,7 +188,7 @@ where async fn open(mut config: GenericLargeStorageConfig) -> Result { let runtime = Handle::current(); - let stats = Arc::::default(); + let stats = config.statistics.clone(); let device = config.device.clone(); let metrics = device.metrics().clone(); @@ -271,7 +273,7 @@ where flushers, reclaimers, admission_picker: config.admission_picker, - stats, + statistics: stats, flush: config.flush, sequence, runtime, @@ -293,7 +295,7 @@ where } fn pick(&self, key: &K) -> bool { - self.inner.admission_picker.pick(&self.inner.stats, key) + self.inner.admission_picker.pick(&self.inner.statistics, key) } #[minitrace::trace(name = "foyer::storage::large::generic::enqueue")] @@ -341,7 +343,7 @@ where let device = self.inner.device.clone(); let indexer = self.inner.indexer.clone(); - let stats = self.inner.stats.clone(); + let stats = self.inner.statistics.clone(); let metrics = self.inner.metrics.clone(); async move { @@ -610,6 +612,7 @@ mod tests { reinsertion_picker: Arc::>::default(), tombstone_log_config: None, buffer_threshold: usize::MAX, + statistics: Arc::::default(), }; GenericLargeStorage::open(config).await.unwrap() } @@ -637,6 +640,7 @@ mod tests { reinsertion_picker, tombstone_log_config: None, buffer_threshold: usize::MAX, + statistics: Arc::::default(), }; GenericLargeStorage::open(config).await.unwrap() } @@ -664,6 +668,7 @@ mod tests { reinsertion_picker: Arc::>::default(), tombstone_log_config: Some(TombstoneLogConfigBuilder::new(path).with_flush(true).build()), buffer_threshold: usize::MAX, + statistics: Arc::::default(), }; GenericLargeStorage::open(config).await.unwrap() } diff --git a/foyer-storage/src/storage/runtime.rs b/foyer-storage/src/storage/runtime.rs index b9582418..a19620db 100644 --- a/foyer-storage/src/storage/runtime.rs +++ b/foyer-storage/src/storage/runtime.rs @@ -217,6 +217,7 @@ mod tests { }, picker::utils::{AdmitAllPicker, FifoPicker, RejectAllPicker}, storage::Storage, + Statistics, }; use super::*; @@ -265,6 +266,7 @@ mod tests { reinsertion_picker: Arc::>::default(), tombstone_log_config: None, buffer_threshold: usize::MAX, + statistics: Arc::::default(), } } diff --git a/foyer-storage/src/store.rs b/foyer-storage/src/store.rs index d07c527f..ea98f66b 100644 --- a/foyer-storage/src/store.rs +++ b/foyer-storage/src/store.rs @@ -453,6 +453,7 @@ where let admission_picker = self.admission_picker.clone(); let metrics = Arc::new(Metrics::new(&self.name)); + let statistics = Arc::::default(); let engine = match self.device_config { DeviceConfig::None => { @@ -482,6 +483,7 @@ where reinsertion_picker: self.reinsertion_picker, tombstone_log_config: self.tombstone_log_config, buffer_threshold: self.buffer_threshold, + statistics: statistics.clone(), })) .await? } @@ -504,6 +506,7 @@ where reinsertion_picker: self.reinsertion_picker, tombstone_log_config: self.tombstone_log_config, buffer_threshold: self.buffer_threshold, + statistics: statistics.clone(), }, runtime_config, })) @@ -552,6 +555,7 @@ where reinsertion_picker: self.reinsertion_picker, tombstone_log_config: self.tombstone_log_config, buffer_threshold: self.buffer_threshold, + statistics: statistics.clone(), }, })) .await? @@ -585,6 +589,7 @@ where reinsertion_picker: self.reinsertion_picker, tombstone_log_config: self.tombstone_log_config, buffer_threshold: self.buffer_threshold, + statistics: statistics.clone(), }, }, runtime_config, @@ -598,7 +603,7 @@ where Ok(Store { engine, admission_picker, - statistics: Arc::::default(), + statistics, }) } }