Skip to content

Commit 013b202

Browse files
Views: snapshot to skip ephermeral tables (#3720)
# Description of Changes. fixes #3715 The patch makes snapshots to skip ephemeral tables. # API and ABI breaking changes NA # Expected complexity level and risk 1 # Testing <!-- Describe any testing you've done, and any testing you'd like your reviewers to do, so that you're confident that all the changes work as expected! --> - [ ] <!-- maybe a test you want to do --> - [ ] <!-- maybe a test you want a reviewer to do, so they can check it off when they're satisfied. --> --------- Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
1 parent 3e7ab2c commit 013b202

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

crates/core/src/db/relational_db.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2591,7 +2591,40 @@ mod tests {
25912591
}
25922592

25932593
#[test]
2594-
fn test_view_tables_are_ephemeral() -> ResultTest<()> {
2594+
fn test_view_tables_are_ephemeral_in_commitlog() -> ResultTest<()> {
2595+
let stdb = TestDB::durable_without_snapshot_repo()?;
2596+
2597+
let (view_id, table_id, _, _) = setup_view(&stdb)?;
2598+
2599+
// Write some rows (reusing the same helper)
2600+
insert_view_row(&stdb, view_id, table_id, Identity::ONE, 10)?;
2601+
insert_view_row(&stdb, view_id, table_id, Identity::ZERO, 20)?;
2602+
2603+
assert!(
2604+
!project_views(&stdb, table_id, Identity::ZERO).is_empty(),
2605+
"View table should NOT be empty after insert"
2606+
);
2607+
2608+
// Reopen the database — view tables must not persist
2609+
let stdb = stdb.reopen()?;
2610+
2611+
// Validate that the view's backing table has been removed
2612+
assert!(
2613+
project_views(&stdb, table_id, Identity::ZERO).is_empty(),
2614+
"View table should be empty after reopening the database"
2615+
);
2616+
2617+
let tx = begin_mut_tx(&stdb);
2618+
let subs_rows = tx.lookup_st_view_subs(view_id)?;
2619+
assert!(
2620+
subs_rows.is_empty(),
2621+
"st_view_subs should be empty after reopening the database"
2622+
);
2623+
Ok(())
2624+
}
2625+
2626+
#[test]
2627+
fn test_view_tables_are_ephemeral_with_snapshot() -> ResultTest<()> {
25952628
let stdb = TestDB::durable()?;
25962629

25972630
let (view_id, table_id, _, _) = setup_view(&stdb)?;
@@ -2605,6 +2638,10 @@ mod tests {
26052638
"View table should NOT be empty after insert"
26062639
);
26072640

2641+
let root = stdb.path().snapshots();
2642+
let (_, repo) = make_snapshot(root.clone(), Identity::ZERO, 0, CompressType::None, false);
2643+
stdb.take_snapshot(&repo)?.expect("snapshot should succeed");
2644+
26082645
// Reopen the database — view tables must not persist
26092646
let stdb = stdb.reopen()?;
26102647

crates/datastore/src/locking_tx_datastore/committed_state.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,17 @@ impl CommittedState {
10171017
(table, blob_store, pool)
10181018
}
10191019

1020+
/// Returns an iterator over all persistent tables (i.e., non-ephemeral tables)
1021+
pub(super) fn persistent_tables_and_blob_store(&mut self) -> (impl Iterator<Item = &mut Table>, &HashMapBlobStore) {
1022+
(
1023+
self.tables
1024+
.iter_mut()
1025+
.filter(|(table_id, _)| !self.ephemeral_tables.contains(*table_id))
1026+
.map(|(_, table)| table),
1027+
&self.blob_store,
1028+
)
1029+
}
1030+
10201031
pub fn report_data_size(&self, database_identity: Identity) {
10211032
use crate::db_metrics::data_size::DATA_SIZE_METRICS;
10221033

crates/datastore/src/locking_tx_datastore/datastore.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,8 @@ impl Locking {
282282
tx_offset,
283283
);
284284

285-
let CommittedState {
286-
ref mut tables,
287-
ref blob_store,
288-
..
289-
} = *committed_state;
290-
let snapshot_dir = repo.create_snapshot(tables.values_mut(), blob_store, tx_offset)?;
285+
let (tables, blob_store) = committed_state.persistent_tables_and_blob_store();
286+
let snapshot_dir = repo.create_snapshot(tables, blob_store, tx_offset)?;
291287

292288
Ok(Some((tx_offset, snapshot_dir)))
293289
}

0 commit comments

Comments
 (0)