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 checkpoint_dirty(&self) -> CheckpointDirty;
22 fn all_node_ids_at(&self, ts: u64) -> Vec<NodeId>;
23 fn all_rel_ids_at(&self, ts: u64) -> Vec<RelId>;
24 fn node_at(&self, id: NodeId, ts: u64) -> Option<Node>;
25 fn rel_at(&self, id: RelId, ts: u64) -> Option<Relationship>;
26 fn node_checkpoint_bytes(&self, id: NodeId, ts: u64) -> Result<Option<u64>>;
27 fn rel_checkpoint_bytes(&self, id: RelId, ts: u64) -> Result<Option<u64>>;
28 fn named_indexes(&self) -> Vec<IndexDef>;
29 fn named_constraints(&self) -> Vec<ConstraintDef>;
30 fn checkpoint_theater_for_write(&self) -> Result<CheckpointTheater>;
31 fn graph_type_spec(&self) -> Result<Option<String>>;
32 fn catalog_ddl(&self) -> Vec<String>;
34}
35
36pub trait CheckpointDirtyMarks: GraphExport {
42 fn take_checkpoint_dirty(&self) -> CheckpointDirty;
45 fn merge_checkpoint_dirty(&self, dirty: &CheckpointDirty);
47}
48
49#[derive(Clone, Default)]
52pub struct CheckpointDirty {
53 pub nodes: HashSet<NodeId>,
54 pub rels: HashSet<RelId>,
55}
56
57pub trait GraphImport: GraphExport + Sync {
62 fn set_next_node_id(&self, id: i64);
63 fn set_next_rel_id(&self, id: i64);
64 fn set_commit_ts(&self, ts: u64);
65 fn install_named_index(&self, index: IndexDef) -> Result<()>;
66 fn install_named_constraint(&self, constraint: ConstraintDef) -> Result<()>;
67 fn restore_checkpoint_theater(&self, theater: CheckpointTheater) -> Result<()>;
68 fn mark_legacy_unenforced(&self);
69 fn finish_restore(&self);
70 fn load_checkpoint_nodes(&self, nodes: &[Node]) -> Result<()>;
75 fn load_checkpoint_rels(&self, rels: &[Relationship]) -> Result<()>;
78 fn load_checkpoint_node(&self, node: Node) -> Result<()> {
81 self.load_checkpoint_nodes(std::slice::from_ref(&node))
82 }
83 fn load_checkpoint_rel(&self, rel: Relationship) -> Result<()> {
86 self.load_checkpoint_rels(std::slice::from_ref(&rel))
87 }
88 fn apply_replayed_redo(&self, ops: Vec<RedoOp>, commit_ts: u64) -> Result<()>;
89 fn rebuild_indexes(&self);
90 fn restore_graph_type_spec(&self, spec: Option<&str>) -> Result<()>;
91 fn restore_legacy_enforced_constraints(&self, constraints: Vec<Constraint>) -> Result<()>;
92}
93
94pub trait SnapshotGraph: GraphImport + Default {}
97
98impl<T: GraphImport + Default> SnapshotGraph for T {}