linkrs_storage/edge/csr_variant/maintenance.rs
1use super::super::{EdgeId, Timestamp};
2use super::CsrVariant;
3
4impl CsrVariant {
5 /// Compact with per-edge removal reporting.
6 ///
7 /// Whole-table timestamp reclaim: the capability query owns the
8 /// exemption list, the match below only serves the supported forms.
9 /// Pure and bundled rows hold no timestamps so they report zero; their
10 /// holes still compact through the per-row entry. Production frozen
11 /// reclaim uses the batched rows entry below instead of one call per row.
12 pub fn compact_with_ts_reporting(
13 &mut self,
14 cutoff: Timestamp,
15 reserve_ratio: f32,
16 on_edge_removed: &mut dyn FnMut(EdgeId, Timestamp),
17 ) -> usize {
18 if !self.supports_timestamp_reclaim() {
19 log::debug!(
20 "timestamp reclaim ignored: variant {:?} holds no timestamps",
21 self.variant_name()
22 );
23 return 0;
24 }
25 match self {
26 CsrVariant::Multiple(csr) => {
27 csr.compact_with_ts_reporting(cutoff, reserve_ratio, on_edge_removed)
28 }
29 CsrVariant::Single(csr) => csr.compact_with_ts_reporting(cutoff, on_edge_removed),
30 CsrVariant::Frozen(csr) => csr.compact_with_cutoff(cutoff, on_edge_removed),
31 _ => 0,
32 }
33 }
34
35 /// Reclaim a listed row set of a frozen group in one linear pass.
36 ///
37 /// Production replacement for repeated per-row frozen compactions: one
38 /// table-proportional pass instead of one trailing memmove per row.
39 /// Only the frozen variant compacts; every other variant reports zero
40 /// so callers keep their existing per-row path for mutable groups.
41 pub fn compact_frozen_rows_batched(
42 &mut self,
43 vids: &[u32],
44 cutoff: Timestamp,
45 on_edge_removed: &mut dyn FnMut(EdgeId, Timestamp),
46 ) -> usize {
47 match self {
48 CsrVariant::Frozen(csr) => csr.compact_rows_batched(vids, cutoff, on_edge_removed),
49 _ => 0,
50 }
51 }
52
53 /// Sort one primary row into key order on the maintenance path.
54 ///
55 /// Same invalidation as the underlying stores: positions go stale and
56 /// the caller relocates through the edge-id key. Frozen, single-slot and
57 /// empty forms are already ordered and report false.
58 pub fn sort_row(&mut self, src_vid: u32) -> bool {
59 match self {
60 CsrVariant::Multiple(csr) => csr.sort_row(src_vid),
61 CsrVariant::Pure(csr) => csr.sort_row(src_vid),
62 CsrVariant::Bundled(csr) => csr.sort_row(src_vid),
63 CsrVariant::Single(_) | CsrVariant::Frozen(_) | CsrVariant::None { .. } => false,
64 }
65 }
66}