Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make statistics sharable between engines #606

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions foyer-storage/src/large/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ where
pub admission_picker: Arc<dyn AdmissionPicker<Key = K>>,
pub reinsertion_picker: Arc<dyn ReinsertionPicker<Key = K>>,
pub tombstone_log_config: Option<TombstoneLogConfig>,
pub statistics: Arc<Statistics>,
}

impl<K, V, S> Debug for GenericLargeStorageConfig<K, V, S>
Expand All @@ -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()
}
}
Expand Down Expand Up @@ -151,7 +153,7 @@ where

admission_picker: Arc<dyn AdmissionPicker<Key = K>>,

stats: Arc<Statistics>,
statistics: Arc<Statistics>,

flush: bool,

Expand Down Expand Up @@ -186,7 +188,7 @@ where
async fn open(mut config: GenericLargeStorageConfig<K, V, S>) -> Result<Self> {
let runtime = Handle::current();

let stats = Arc::<Statistics>::default();
let stats = config.statistics.clone();

let device = config.device.clone();
let metrics = device.metrics().clone();
Expand Down Expand Up @@ -271,7 +273,7 @@ where
flushers,
reclaimers,
admission_picker: config.admission_picker,
stats,
statistics: stats,
flush: config.flush,
sequence,
runtime,
Expand All @@ -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")]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -610,6 +612,7 @@ mod tests {
reinsertion_picker: Arc::<RejectAllPicker<u64>>::default(),
tombstone_log_config: None,
buffer_threshold: usize::MAX,
statistics: Arc::<Statistics>::default(),
};
GenericLargeStorage::open(config).await.unwrap()
}
Expand Down Expand Up @@ -637,6 +640,7 @@ mod tests {
reinsertion_picker,
tombstone_log_config: None,
buffer_threshold: usize::MAX,
statistics: Arc::<Statistics>::default(),
};
GenericLargeStorage::open(config).await.unwrap()
}
Expand Down Expand Up @@ -664,6 +668,7 @@ mod tests {
reinsertion_picker: Arc::<RejectAllPicker<u64>>::default(),
tombstone_log_config: Some(TombstoneLogConfigBuilder::new(path).with_flush(true).build()),
buffer_threshold: usize::MAX,
statistics: Arc::<Statistics>::default(),
};
GenericLargeStorage::open(config).await.unwrap()
}
Expand Down
2 changes: 2 additions & 0 deletions foyer-storage/src/storage/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ mod tests {
},
picker::utils::{AdmitAllPicker, FifoPicker, RejectAllPicker},
storage::Storage,
Statistics,
};

use super::*;
Expand Down Expand Up @@ -265,6 +266,7 @@ mod tests {
reinsertion_picker: Arc::<RejectAllPicker<u64>>::default(),
tombstone_log_config: None,
buffer_threshold: usize::MAX,
statistics: Arc::<Statistics>::default(),
}
}

Expand Down
7 changes: 6 additions & 1 deletion foyer-storage/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ where

let admission_picker = self.admission_picker.clone();
let metrics = Arc::new(Metrics::new(&self.name));
let statistics = Arc::<Statistics>::default();

let engine = match self.device_config {
DeviceConfig::None => {
Expand Down Expand Up @@ -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?
}
Expand All @@ -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,
}))
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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,
Expand All @@ -598,7 +603,7 @@ where
Ok(Store {
engine,
admission_picker,
statistics: Arc::<Statistics>::default(),
statistics,
})
}
}
Loading