Skip to content

Commit

Permalink
Merge pull request #4848 from systeminit/disk_cache_write_on_read
Browse files Browse the repository at this point in the history
fix: disable disk cache cleanup
  • Loading branch information
sprutton1 authored Oct 22, 2024
2 parents e413cfd + 03fff5c commit 5ff71ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
22 changes: 11 additions & 11 deletions lib/si-layer-cache/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,17 @@ where
compute_executor.clone(),
)?;

Self::spawn_cleanup_tasks(
&[
cas_cache.disk_cache(),
encrypted_secret_cache.disk_cache(),
func_run_cache.disk_cache(),
func_run_log_cache.disk_cache(),
rebase_batch_cache.disk_cache(),
snapshot_cache.disk_cache(),
],
token.clone(),
);
// Self::spawn_cleanup_tasks(
// &[
// cas_cache.disk_cache(),
// encrypted_secret_cache.disk_cache(),
// func_run_cache.disk_cache(),
// func_run_log_cache.disk_cache(),
// rebase_batch_cache.disk_cache(),
// snapshot_cache.disk_cache(),
// ],
// token.clone(),
// );

let cache_updates_task = CacheUpdatesTask::create(
instance_id,
Expand Down
15 changes: 3 additions & 12 deletions lib/si-layer-cache/src/disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ impl DiskCache {
}

pub async fn get(&self, key: Arc<str>) -> LayerDbResult<Vec<u8>> {
let data = cacache::read(self.write_path.as_ref(), key.clone()).await?;

// we need to ensure that recently-accessed items have up to date metadata so the TTL does
// not clean them up inappropriately
self.update_cache_entry(key.clone(), data.clone());

Ok(data)
Ok(cacache::read(self.write_path.as_ref(), key.clone()).await?)
}

pub async fn contains_key(&self, key: Arc<str>) -> LayerDbResult<bool> {
Expand Down Expand Up @@ -80,6 +74,7 @@ impl DiskCache {
Ok(())
}

#[instrument(name = "layer_db.disk_cache.cleanup", level = "info", skip_all)]
async fn cleanup(&self) {
let mut would_remove = 0;
let mut removed = 0;
Expand All @@ -88,6 +83,7 @@ impl DiskCache {
.expect("unable to get the current time, what does this mean? How could this happen?")
.as_millis();

info!("Disk cache cleanup starting...");
for md in cacache::list_sync(self.write_path.as_ref()).flatten() {
tokio::task::yield_now().await;
if now - md.time > self.ttl.as_millis() {
Expand Down Expand Up @@ -133,11 +129,6 @@ impl DiskCache {
}
});
}

fn update_cache_entry(&self, key: Arc<str>, value: Vec<u8>) {
let me = self.clone();
tokio::spawn(async move { me.insert(key, value).await });
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down

0 comments on commit 5ff71ff

Please sign in to comment.