relate_engine_api/write.rs
1//! Durable ordering and the commit clock. Apply and publication stay in
2//! the facade, which hands the query engine the redo this trait made durable.
3
4use relate_core::Result;
5
6use crate::commit::CommitRecord;
7use crate::export::{CheckpointDirtyMarks, GraphImport};
8use crate::redo::RedoOp;
9
10/// One group's redo, captured against the snapshot the statement read.
11pub struct CommitGroup {
12 pub ops: Vec<RedoOp>,
13 pub snapshot_ts: u64,
14 /// Timestamp admission assigned. The log rejects zero.
15 pub commit_ts: u64,
16}
17
18/// The clock value the log assigned to one group.
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub struct CommittedSlot {
21 pub lsn: u64,
22 pub commit_ts: u64,
23}
24
25/// What a follower poll returns.
26pub enum FollowBatch {
27 Idle,
28 Records(Vec<CommitRecord>),
29 Gap,
30}
31
32pub trait WriteEngine: Send {
33 /// Make `groups` durable. Each group already carries the commit
34 /// timestamp admission assigned. Returns those timestamps with the
35 /// log sequence number the append gave them.
36 fn commit(&self, groups: &[CommitGroup]) -> Result<Vec<CommittedSlot>>;
37
38 /// Publish a snapshot of `graph` at `snapshot_ts`, covering the log
39 /// through `lsn`.
40 fn checkpoint(
41 &self,
42 graph: &dyn CheckpointDirtyMarks,
43 lsn: u64,
44 snapshot_ts: u64,
45 ) -> Result<()>;
46
47 /// Records with `lsn` greater than `from_lsn`.
48 fn poll_follow(&self, from_lsn: u64) -> Result<FollowBatch>;
49
50 /// The facade installs a reloaded query engine. This reopens the log
51 /// against the snapshot the caller has already loaded into `graph`.
52 fn reload(&self, graph: &mut dyn GraphImport) -> Result<()>;
53}