Skip to main content

relate_engine_api/
export.rs

1//! What a snapshot codec may ask of a query engine, and what recovery may
2//! put back. Codecs never name a concrete graph.
3
4use std::collections::HashSet;
5
6use relate_catalog::{ConstraintDef, IndexDef};
7use relate_core::{Node, NodeId, RelId, Relationship, Result};
8use relate_model::Constraint;
9
10use crate::catalog_image::CheckpointTheater;
11use crate::redo::RedoOp;
12
13pub trait GraphExport {
14    fn commit_ts(&self) -> u64;
15    fn next_node_id(&self) -> i64;
16    fn next_rel_id(&self) -> i64;
17    fn live_node_count(&self) -> usize;
18    fn dirty_node_ids(&self) -> HashSet<NodeId>;
19    fn dirty_rel_ids(&self) -> HashSet<RelId>;
20    fn all_node_ids_at(&self, ts: u64) -> Vec<NodeId>;
21    fn all_rel_ids_at(&self, ts: u64) -> Vec<RelId>;
22    fn node_at(&self, id: NodeId, ts: u64) -> Option<Node>;
23    fn rel_at(&self, id: RelId, ts: u64) -> Option<Relationship>;
24    fn node_checkpoint_bytes(&self, id: NodeId, ts: u64) -> Result<Option<u64>>;
25    fn rel_checkpoint_bytes(&self, id: RelId, ts: u64) -> Result<Option<u64>>;
26    fn named_indexes(&self) -> Vec<IndexDef>;
27    fn named_constraints(&self) -> Vec<ConstraintDef>;
28    fn checkpoint_theater_for_write(&self) -> Result<CheckpointTheater>;
29    fn graph_type_spec(&self) -> Result<Option<String>>;
30    fn clear_checkpoint_dirty(&self);
31    /// SHOW-style catalog DDL the schema mirror writes beside a checkpoint.
32    fn catalog_ddl(&self) -> Vec<String>;
33}
34
35pub trait GraphImport: GraphExport {
36    fn set_next_node_id(&self, id: i64);
37    fn set_next_rel_id(&self, id: i64);
38    fn set_commit_ts(&self, ts: u64);
39    fn install_named_index(&self, index: IndexDef) -> Result<()>;
40    fn install_named_constraint(&self, constraint: ConstraintDef) -> Result<()>;
41    fn restore_checkpoint_theater(&self, theater: CheckpointTheater) -> Result<()>;
42    fn mark_legacy_unenforced(&self);
43    fn finish_restore(&self);
44    fn load_checkpoint_node(&self, node: Node) -> Result<()>;
45    fn load_checkpoint_rel(&self, rel: Relationship) -> Result<()>;
46    fn apply_replayed_redo(&self, ops: Vec<RedoOp>, commit_ts: u64) -> Result<()>;
47    fn rebuild_indexes(&self);
48    fn restore_graph_type_spec(&self, spec: Option<&str>) -> Result<()>;
49    fn restore_legacy_enforced_constraints(&self, constraints: Vec<Constraint>) -> Result<()>;
50}
51
52/// A graph a codec can both read and fill. `Default` builds the empty
53/// engine recovery starts from.
54pub trait SnapshotGraph: GraphImport + Default {}
55
56impl<T: GraphImport + Default> SnapshotGraph for T {}