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

Cleanup caches in random order #1252

Merged
merged 2 commits into from
Jul 14, 2023
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/symbolicator-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ minidump-unwind = "0.17.0"
moka = { version = "0.11.0", features = ["future"] }
once_cell = "1.17.1"
parking_lot = "0.12.0"
rand = "0.8.5"
regex = "1.5.5"
reqwest = { version = "0.11.0", features = ["gzip", "brotli", "deflate", "json", "stream", "trust-dns"] }
sentry = { version = "0.31.4", features = ["tracing"] }
Expand Down
37 changes: 25 additions & 12 deletions crates/symbolicator-service/src/caching/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::io;
use std::path::Path;

use anyhow::{anyhow, Result};
use rand::seq::SliceRandom;
use rand::thread_rng;

use crate::config::Config;

Expand Down Expand Up @@ -46,20 +48,31 @@ impl Caches {
diagnostics,
} = &self;

// We want to clean up the caches in a random order. Ideally, this should not matter at all,
// but we have seen some cleanup jobs getting stuck or dying reproducibly on certain types
// of caches. A random shuffle increases the chance that the cleanup will make progress on
// other caches.
// The cleanup job dying on specific caches is a very bad thing and should definitely be
// fixed, but in the meantime a random shuffle should provide more head room for a proper
// fix in this case.
let mut caches = vec![
objects,
object_meta,
auxdifs,
il2cpp,
symcaches,
cficaches,
ppdb_caches,
sourcemap_caches,
sourcefiles,
diagnostics,
];
let mut rng = thread_rng();
caches.as_mut_slice().shuffle(&mut rng);

// Collect results so we can fail the entire function. But we do not want to early
// return since we should at least attempt to clean up all caches.
let results = vec![
objects.cleanup(),
object_meta.cleanup(),
symcaches.cleanup(),
cficaches.cleanup(),
diagnostics.cleanup(),
auxdifs.cleanup(),
il2cpp.cleanup(),
ppdb_caches.cleanup(),
sourcemap_caches.cleanup(),
sourcefiles.cleanup(),
];
let results: Vec<_> = caches.into_iter().map(|c| c.cleanup()).collect();

let mut first_error = None;
for result in results {
Expand Down
Loading