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

Purge the query cache to prevent GC livelocks #7370

Merged
merged 3 commits into from
Sep 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: 12 additions & 3 deletions crates/store/re_entity_db/src/entity_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,21 @@ impl EntityDb {
re_tracing::profile_function!();

assert!((0.0..=1.0).contains(&fraction_to_purge));
self.gc(&GarbageCollectionOptions {
if !self.gc(&GarbageCollectionOptions {
target: GarbageCollectionTarget::DropAtLeastFraction(fraction_to_purge as _),
protect_latest: 1,
time_budget: DEFAULT_GC_TIME_BUDGET,
});
}) {
// If we weren't able to collect any data, then we need to GC the cache itself in order
// to regain some space.
// See <https://github.com/rerun-io/rerun/issues/7369#issuecomment-2335164098> for the
// complete rationale.
self.query_caches.purge_fraction_of_ram(fraction_to_purge);
}
}

pub fn gc(&mut self, gc_options: &GarbageCollectionOptions) {
/// Returns `true` if anything at all was actually GC'd.
pub fn gc(&mut self, gc_options: &GarbageCollectionOptions) -> bool {
re_tracing::profile_function!();

let (store_events, stats_diff) = self.data_store.gc(gc_options);
Expand All @@ -405,6 +412,8 @@ impl EntityDb {
);

self.on_store_deletions(&store_events);

!store_events.is_empty()
}

/// Unconditionally drops all the data for a given [`EntityPath`] .
Expand Down
22 changes: 22 additions & 0 deletions crates/store/re_query/src/latest_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,28 @@ impl Caches {

results
}

/// Free up some RAM by forgetting the older parts of all timelines.
pub fn purge_fraction_of_ram(&mut self, fraction_to_purge: f32) {
re_tracing::profile_function!();

let mut caches = self.latest_at_per_cache_key.write();
for (_key, cache) in caches.iter_mut() {
let mut cache = cache.write();

let split_point =
(cache.per_query_time.len().saturating_sub(1) as f32 * fraction_to_purge) as usize;

if let Some(split_time) = cache.per_query_time.keys().nth(split_point).copied() {
// NOTE: By not clearing the pending invalidations set, we risk invalidating a
// future result that need not be invalidated.
// That is a much better outcome that the opposite though: not invalidating a
// future result that in fact should have been.
// See `handle_pending_invalidation` for more information.
cache.per_query_time = cache.per_query_time.split_off(&split_time);
}
}
}
}

// --- Results ---
Expand Down
Loading