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

Opt-out of GC protection for log_seq and log_time when GCing blueprints #6534

Merged
merged 3 commits into from
Jun 11, 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
6 changes: 4 additions & 2 deletions crates/re_data_store/benches/data_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ fn gc(c: &mut Criterion) {
target: GarbageCollectionTarget::DropAtLeastFraction(1.0 / 3.0),
protect_latest: 0,
purge_empty_tables: false,
dont_protect: Default::default(),
dont_protect_components: Default::default(),
dont_protect_timelines: Default::default(),
enable_batching: false,
time_budget: std::time::Duration::MAX,
});
Expand All @@ -362,7 +363,8 @@ fn gc(c: &mut Criterion) {
target: GarbageCollectionTarget::DropAtLeastFraction(1.0 / 3.0),
protect_latest: 0,
purge_empty_tables: false,
dont_protect: Default::default(),
dont_protect_components: Default::default(),
dont_protect_timelines: Default::default(),
enable_batching: false,
time_budget: std::time::Duration::MAX,
});
Expand Down
3 changes: 2 additions & 1 deletion crates/re_data_store/benches/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ fn plotting_dashboard(c: &mut Criterion) {
target: GarbageCollectionTarget::DropAtLeastFraction(DROP_AT_LEAST),
protect_latest: 1,
purge_empty_tables: false,
dont_protect: Default::default(),
dont_protect_components: Default::default(),
dont_protect_timelines: Default::default(),
enable_batching: false,
time_budget: std::time::Duration::MAX,
};
Expand Down
25 changes: 18 additions & 7 deletions crates/re_data_store/src/store_gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ pub struct GarbageCollectionOptions {
pub purge_empty_tables: bool,

/// Components which should not be protected from GC when using `protect_latest`
pub dont_protect: HashSet<ComponentName>,
pub dont_protect_components: HashSet<ComponentName>,

/// Timelines which should not be protected from GC when using `protect_latest`
pub dont_protect_timelines: HashSet<Timeline>,

/// Whether to enable batched bucket drops.
///
Expand All @@ -65,7 +68,8 @@ impl GarbageCollectionOptions {
time_budget: std::time::Duration::MAX,
protect_latest: 0,
purge_empty_tables: true,
dont_protect: Default::default(),
dont_protect_components: Default::default(),
dont_protect_timelines: Default::default(),
enable_batching: false,
}
}
Expand Down Expand Up @@ -121,8 +125,11 @@ impl DataStore {

let (initial_num_rows, initial_num_bytes) = stats_before.total_rows_and_bytes();

let protected_rows =
self.find_all_protected_rows(options.protect_latest, &options.dont_protect);
let protected_rows = self.find_all_protected_rows(
options.protect_latest,
&options.dont_protect_components,
&options.dont_protect_timelines,
);

let mut diffs = match options.target {
GarbageCollectionTarget::DropAtLeastFraction(p) => {
Expand Down Expand Up @@ -433,7 +440,8 @@ impl DataStore {
fn find_all_protected_rows(
&mut self,
target_count: usize,
dont_protect: &HashSet<ComponentName>,
dont_protect_components: &HashSet<ComponentName>,
dont_protect_timelines: &HashSet<Timeline>,
) -> HashSet<RowId> {
re_tracing::profile_function!();

Expand All @@ -447,11 +455,14 @@ impl DataStore {
let mut protected_rows: HashSet<RowId> = Default::default();

// Find all protected rows in regular indexed tables
for table in self.tables.values() {
for ((_, timeline), table) in &self.tables {
if dont_protect_timelines.contains(timeline) {
continue;
}
let mut components_to_find: HashMap<ComponentName, usize> = table
.all_components
.iter()
.filter(|c| !dont_protect.contains(*c))
.filter(|c| !dont_protect_components.contains(*c))
.map(|c| (*c, target_count))
.collect();

Expand Down
6 changes: 4 additions & 2 deletions crates/re_data_store/tests/correctness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,15 +439,17 @@ fn gc_metadata_size() -> anyhow::Result<()> {
target: re_data_store::GarbageCollectionTarget::DropAtLeastFraction(1.0),
protect_latest: 1,
purge_empty_tables: false,
dont_protect: Default::default(),
dont_protect_components: Default::default(),
dont_protect_timelines: Default::default(),
enable_batching,
time_budget: std::time::Duration::MAX,
});
_ = store.gc(&GarbageCollectionOptions {
target: re_data_store::GarbageCollectionTarget::DropAtLeastFraction(1.0),
protect_latest: 1,
purge_empty_tables: false,
dont_protect: Default::default(),
dont_protect_components: Default::default(),
dont_protect_timelines: Default::default(),
enable_batching,
time_budget: std::time::Duration::MAX,
});
Expand Down
12 changes: 8 additions & 4 deletions crates/re_data_store/tests/data_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@ fn gc_impl(store: &mut DataStore) {
target: GarbageCollectionTarget::DropAtLeastFraction(1.0 / 3.0),
protect_latest: 0,
purge_empty_tables: false,
dont_protect: Default::default(),
dont_protect_components: Default::default(),
dont_protect_timelines: Default::default(),
enable_batching: false,
time_budget: std::time::Duration::MAX,
});
Expand Down Expand Up @@ -674,7 +675,8 @@ fn protected_gc_impl(store: &mut DataStore) {
target: GarbageCollectionTarget::Everything,
protect_latest: 1,
purge_empty_tables: true,
dont_protect: Default::default(),
dont_protect_components: Default::default(),
dont_protect_timelines: Default::default(),
enable_batching: false,
time_budget: std::time::Duration::MAX,
});
Expand Down Expand Up @@ -771,7 +773,8 @@ fn protected_gc_clear_impl(store: &mut DataStore) {
target: GarbageCollectionTarget::Everything,
protect_latest: 1,
purge_empty_tables: true,
dont_protect: Default::default(),
dont_protect_components: Default::default(),
dont_protect_timelines: Default::default(),
enable_batching: false,
time_budget: std::time::Duration::MAX,
});
Expand Down Expand Up @@ -817,7 +820,8 @@ fn protected_gc_clear_impl(store: &mut DataStore) {
target: GarbageCollectionTarget::Everything,
protect_latest: 1,
purge_empty_tables: true,
dont_protect: Default::default(),
dont_protect_components: Default::default(),
dont_protect_timelines: Default::default(),
enable_batching: false,
time_budget: std::time::Duration::MAX,
});
Expand Down
10 changes: 7 additions & 3 deletions crates/re_entity_db/src/entity_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,19 +574,22 @@ impl EntityDb {
self.set_store_info = Some(store_info);
}

pub fn gc_everything_but_the_latest_row(&mut self) {
pub fn gc_everything_but_the_latest_row_on_non_default_timelines(&mut self) {
re_tracing::profile_function!();

self.gc(&GarbageCollectionOptions {
target: re_data_store::GarbageCollectionTarget::Everything,
protect_latest: 1, // TODO(jleibs): Bump this after we have an undo buffer
purge_empty_tables: true,
dont_protect: [
dont_protect_components: [
re_types_core::components::ClearIsRecursive::name(),
re_types_core::archetypes::Clear::indicator().name(),
]
.into_iter()
.collect(),
dont_protect_timelines: [Timeline::log_tick(), Timeline::log_time()]
.into_iter()
.collect(),
enable_batching: false,
time_budget: DEFAULT_GC_TIME_BUDGET,
});
Expand All @@ -603,7 +606,8 @@ impl EntityDb {
),
protect_latest: 1,
purge_empty_tables: false,
dont_protect: Default::default(),
dont_protect_components: Default::default(),
dont_protect_timelines: Default::default(),
enable_batching: false,
time_budget: DEFAULT_GC_TIME_BUDGET,
});
Expand Down
4 changes: 2 additions & 2 deletions crates/re_entity_db/tests/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ fn clear_and_gc() -> anyhow::Result<()> {

db.add_data_row(row)?;

db.gc_everything_but_the_latest_row();
db.gc_everything_but_the_latest_row_on_non_default_timelines();

let stats = DataStoreStats::from_store(db.store());
assert_eq!(stats.temporal.num_rows, 1);
Expand All @@ -411,7 +411,7 @@ fn clear_and_gc() -> anyhow::Result<()> {

db.add_data_row(clear)?;

db.gc_everything_but_the_latest_row();
db.gc_everything_but_the_latest_row_on_non_default_timelines();

// No rows should remain because the table should have been purged
let stats = DataStoreStats::from_store(db.store());
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer_context/src/store_hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ impl StoreHub {

// TODO(jleibs): Decide a better tuning for this. Would like to save a
// reasonable amount of history, or incremental snapshots.
blueprint.gc_everything_but_the_latest_row();
blueprint.gc_everything_but_the_latest_row_on_non_default_timelines();

self.blueprint_last_gc
.insert(blueprint_id.clone(), blueprint.generation());
Expand Down
Loading