relate_engine_api/
export.rs1use 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 fn catalog_ddl(&self) -> Vec<String>;
33}
34
35pub trait GraphImport: GraphExport + Sync {
40 fn set_next_node_id(&self, id: i64);
41 fn set_next_rel_id(&self, id: i64);
42 fn set_commit_ts(&self, ts: u64);
43 fn install_named_index(&self, index: IndexDef) -> Result<()>;
44 fn install_named_constraint(&self, constraint: ConstraintDef) -> Result<()>;
45 fn restore_checkpoint_theater(&self, theater: CheckpointTheater) -> Result<()>;
46 fn mark_legacy_unenforced(&self);
47 fn finish_restore(&self);
48 fn load_checkpoint_nodes(&self, nodes: &[Node]) -> Result<()>;
53 fn load_checkpoint_rels(&self, rels: &[Relationship]) -> Result<()>;
56 fn load_checkpoint_node(&self, node: Node) -> Result<()> {
59 self.load_checkpoint_nodes(std::slice::from_ref(&node))
60 }
61 fn load_checkpoint_rel(&self, rel: Relationship) -> Result<()> {
64 self.load_checkpoint_rels(std::slice::from_ref(&rel))
65 }
66 fn apply_replayed_redo(&self, ops: Vec<RedoOp>, commit_ts: u64) -> Result<()>;
67 fn rebuild_indexes(&self);
68 fn restore_graph_type_spec(&self, spec: Option<&str>) -> Result<()>;
69 fn restore_legacy_enforced_constraints(&self, constraints: Vec<Constraint>) -> Result<()>;
70}
71
72pub trait SnapshotGraph: GraphImport + Default {}
75
76impl<T: GraphImport + Default> SnapshotGraph for T {}