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<(RowId, TxId)>,
11 pub commit_lsn: Option<u64>,
12 pub propagation_in_progress: bool,
13}
14
15impl WriteSet {
16 pub fn new() -> Self {
17 Self::default()
18 }
19
20 pub fn is_empty(&self) -> bool {
21 self.relational_inserts.is_empty()
22 && self.relational_deletes.is_empty()
23 && self.adj_inserts.is_empty()
24 && self.adj_deletes.is_empty()
25 && self.vector_inserts.is_empty()
26 && self.vector_deletes.is_empty()
27 }
28
29 pub fn stamp_lsn(&mut self, lsn: u64) {
30 self.commit_lsn = Some(lsn);
31
32 for (_, row) in &mut self.relational_inserts {
33 row.lsn = lsn;
34 }
35
36 for entry in &mut self.adj_inserts {
37 entry.lsn = lsn;
38 }
39
40 for entry in &mut self.vector_inserts {
41 entry.lsn = lsn;
42 }
43 }
44}
45
46pub trait WriteSetApplicator: Send + Sync {
47 fn apply(&self, ws: WriteSet) -> Result<()>;
48 fn new_row_id(&self) -> RowId;
49}
50
51impl WriteSetApplicator for Box<dyn WriteSetApplicator> {
52 fn apply(&self, ws: WriteSet) -> Result<()> {
53 (**self).apply(ws)
54 }
55
56 fn new_row_id(&self) -> RowId {
57 (**self).new_row_id()
58 }
59}