Skip to main content

linkrs_storage/edge/csr_with_properties/
visibility.rs

1use super::{CsrWithProperties, RowVisibility};
2use linkrs_core::types::{EdgeId, Timestamp};
3
4/// Row-stamp projection for reclamation probing only.
5///
6/// Query visibility never consults these stamps; every query filters through
7/// the version authority (`EdgeStore::is_visible`). These helpers exist so
8/// garbage collection can probe row liveness without a second authority
9/// lookup.
10impl RowVisibility {
11    pub(crate) fn new(create_ts: Timestamp) -> Self {
12        Self {
13            create_ts,
14            delete_ts: None,
15        }
16    }
17
18    #[cfg(test)]
19    pub(crate) fn is_visible_at(&self, query_ts: Timestamp) -> bool {
20        crate::mvcc_visibility::Visibility::is_visible(query_ts, self.create_ts, self.delete_ts)
21    }
22
23    pub(crate) fn mark_deleted(&mut self, ts: Timestamp) {
24        if self.delete_ts.is_none() {
25            self.delete_ts = Some(ts);
26        }
27    }
28}
29
30impl CsrWithProperties {
31    pub fn mark_deleted(&mut self, edge_id: EdgeId, ts: Timestamp) -> bool {
32        if self.inline {
33            return false;
34        }
35        if let Some(pos) = self.mapped_row(edge_id) {
36            if let Some(vis) = self.visibility.get_mut(pos) {
37                if vis.delete_ts.is_some() {
38                    return false;
39                }
40                vis.mark_deleted(ts);
41                return true;
42            }
43        }
44        false
45    }
46
47    pub(crate) fn is_deleted_at_row(&self, row_idx: usize) -> bool {
48        if let Some(vis) = self.visibility.get(row_idx) {
49            return vis.delete_ts.is_some();
50        }
51        false
52    }
53
54    pub fn revert_deletion_at_row(&mut self, row_idx: usize) -> bool {
55        if let Some(vis) = self.visibility.get_mut(row_idx) {
56            if vis.delete_ts.is_some() {
57                vis.delete_ts = None;
58                return true;
59            }
60        }
61        false
62    }
63
64    pub fn revert_deletion_for_edge(&mut self, edge_id: EdgeId) -> bool {
65        if self.inline {
66            return false;
67        }
68        if let Some(pos) = self.mapped_row(edge_id) {
69            return self.revert_deletion_at_row(pos);
70        }
71        false
72    }
73}