uqa_storage/catalog/cache_revisions.rs
1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Transaction-visible invalidation generations, without loading catalog payloads.
8
9use std::collections::BTreeMap;
10
11/// Lightweight generations read from the same storage snapshot as catalog and
12/// row data. Providers must advance them atomically with the corresponding
13/// mutation, including direct storage writes, and restore them on rollback.
14/// Missing support is distinct from an empty, unchanged database.
15/// Generations are opaque equality tokens, not clocks or counts. A logical
16/// provider may use the domain at or above [`Self::PRIVATE_GENERATION_BASE`]
17/// for transaction-private changes; rollback restores the prior tokens and
18/// commit replaces them with durable generations.
19#[derive(Clone, Debug, Default, PartialEq, Eq)]
20pub struct CatalogCacheRevisions {
21 pub table_catalog: u64,
22 pub registries: u64,
23 /// Per-graph generations, separate from SQL registries. `None` preserves
24 /// conservative restoration for providers without graph-scoped tracking.
25 pub graphs: Option<BTreeMap<String, u64>>,
26 pub table_data: BTreeMap<String, u64>,
27 pub column_statistics: BTreeMap<String, u64>,
28 pub statistics_maintenance: BTreeMap<String, u64>,
29 /// Physical schema changes also invalidate bindings, even when a caller
30 /// changed the storage schema without an ordinary catalog operation.
31 pub storage_schema: u64,
32}
33
34impl CatalogCacheRevisions {
35 /// The first generation of the domain reserved for changes private to the reading transaction. Durable generations stay below it.
36 pub const PRIVATE_GENERATION_BASE: u64 = 1 << 63;
37
38 /// Whether `generation` identifies a change private to the reading transaction instead of a committed generation.
39 pub fn is_private_generation(generation: u64) -> bool {
40 generation >= Self::PRIVATE_GENERATION_BASE
41 }
42}