Remove Store::cached(), consolidate on access_local()
- Remove CACHED_STORE, cached(), is_stale(), set_store() - redundant - Convert all Store::cached() callers to use access_local() - Single Store::load() call remains in access() fallback path All store access now goes through hippocampus::access() / access_local(), which handles socket connection or local fallback with caching. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
09b30d64f2
commit
1d88293ccf
6 changed files with 17 additions and 51 deletions
|
|
@ -44,14 +44,9 @@ pub enum StoreAccess {
|
|||
None(String), // Error: couldn't get access
|
||||
}
|
||||
|
||||
/// Set the global store handle. Call once at daemon startup (eager init).
|
||||
pub fn set_store(store: Arc<crate::Mutex<Store>>) {
|
||||
STORE_ACCESS.set(Some(store)).ok();
|
||||
}
|
||||
|
||||
/// Get store access: daemon's store, socket, or local fallback.
|
||||
pub fn access() -> StoreAccess {
|
||||
// Daemon: already set via set_store()
|
||||
// Check if already cached
|
||||
if let Some(Some(store)) = STORE_ACCESS.get() {
|
||||
return StoreAccess::Daemon(store.clone());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,36 +19,8 @@ use std::collections::HashMap;
|
|||
use std::fs;
|
||||
use std::io::{BufReader, Seek};
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Process-global cached store. Reloads only when log files change.
|
||||
static CACHED_STORE: tokio::sync::OnceCell<Arc<crate::Mutex<Store>>> =
|
||||
tokio::sync::OnceCell::const_new();
|
||||
|
||||
impl Store {
|
||||
/// Get or create the process-global cached store.
|
||||
/// Reloads from disk if log files have changed since last load.
|
||||
pub async fn cached() -> Result<Arc<crate::Mutex<Store>>> {
|
||||
let store = CACHED_STORE.get_or_try_init(|| async {
|
||||
let s = Store::load()?;
|
||||
Ok::<_, anyhow::Error>(Arc::new(crate::Mutex::new(s)))
|
||||
}).await?;
|
||||
{
|
||||
let mut guard = store.lock().await;
|
||||
if guard.is_stale() {
|
||||
*guard = Store::load()?;
|
||||
}
|
||||
}
|
||||
Ok(store.clone())
|
||||
}
|
||||
|
||||
/// Check if the on-disk logs have grown since we loaded.
|
||||
pub fn is_stale(&self) -> bool {
|
||||
let nodes_size = fs::metadata(nodes_path()).map(|m| m.len()).unwrap_or(0);
|
||||
let rels_size = fs::metadata(relations_path()).map(|m| m.len()).unwrap_or(0);
|
||||
nodes_size != self.loaded_nodes_size || rels_size != self.loaded_rels_size
|
||||
}
|
||||
|
||||
/// Load store from state.bin cache if fresh, otherwise rebuild from capnp logs.
|
||||
///
|
||||
/// Staleness check uses log file sizes (not mtimes). Since logs are
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue