contextdb_tx/
write_set.rs1use contextdb_core::*;
2
3#[derive(Debug, Default, Clone)]
4pub struct WriteSet {
5 pub relational_inserts: Vec<(TableName, VersionedRow)>,
6 pub relational_deletes: Vec<(TableName, RowId, TxId)>,
7 pub adj_inserts: Vec<AdjEntry>,
8 pub adj_deletes: Vec<(NodeId, EdgeType, NodeId, TxId)>,
9 pub vector_inserts: Vec<VectorEntry>,
10 pub vector_deletes: Vec<(VectorIndexRef, RowId, TxId)>,
11 pub vector_moves: Vec<(VectorIndexRef, RowId, RowId, TxId)>,
12 pub commit_lsn: Option<Lsn>,
13 pub propagation_in_progress: bool,
14}
15
16impl WriteSet {
17 pub fn new() -> Self {
18 Self::default()
19 }
20
21 pub fn is_empty(&self) -> bool {
22 self.relational_inserts.is_empty()
23 && self.relational_deletes.is_empty()
24 && self.adj_inserts.is_empty()
25 && self.adj_deletes.is_empty()
26 && self.vector_inserts.is_empty()
27 && self.vector_deletes.is_empty()
28 && self.vector_moves.is_empty()
29 }
30
31 pub fn stamp_lsn(&mut self, lsn: Lsn) {
32 self.commit_lsn = Some(lsn);
33
34 for (_, row) in &mut self.relational_inserts {
35 row.lsn = lsn;
36 }
37
38 for entry in &mut self.adj_inserts {
39 entry.lsn = lsn;
40 }
41
42 for entry in &mut self.vector_inserts {
43 entry.lsn = lsn;
44 }
45 }
46}
47
48pub trait WriteSetApplicator: Send + Sync {
49 fn apply(&self, ws: WriteSet) -> Result<()>;
50 fn new_row_id(&self) -> RowId;
51}
52
53impl WriteSetApplicator for Box<dyn WriteSetApplicator> {
54 fn apply(&self, ws: WriteSet) -> Result<()> {
55 (**self).apply(ws)
56 }
57
58 fn new_row_id(&self) -> RowId {
59 (**self).new_row_id()
60 }
61}