MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / plan

Function plan

nodedb/src/engine/array/purge/plan.rs:57–290  ·  view source on GitHub ↗

Compute the purge plan for an array whose store is `store` and whose bitemporal horizon is `horizon_ms`. `horizon_ms` must already be the absolute system-time cutoff (i.e. `now_ms - audit_retain_ms`). This function does **not** recompute it.

(
    store: &ArrayStore,
    horizon_ms: i64,
    schema: &ArraySchema,
)

Source from the content-addressed store, hash-verified

55/// `horizon_ms` must already be the absolute system-time cutoff (i.e.
56/// `now_ms - audit_retain_ms`). This function does **not** recompute it.
57pub fn plan(
58 store: &ArrayStore,
59 horizon_ms: i64,
60 schema: &ArraySchema,
61) -> Result<PurgePlan, ArrayError> {
62 if store.manifest().segments.is_empty() {
63 return Ok(PurgePlan {
64 segment_actions: Vec::new(),
65 cells_carried_forward: 0,
66 });
67 }
68
69 // ── Step 1: Collect all TileEntries tagged with their owning segment id and
70 // flush_lsn (used to choose the ceiling host). ────────────────────────────
71 struct TaggedEntry {
72 segment_id: String,
73 flush_lsn: u64,
74 tile_id: TileId,
75 }
76
77 let mut all_entries: Vec<TaggedEntry> = Vec::new();
78 for seg_ref in &store.manifest().segments {
79 let handle = match store.segments.get(&seg_ref.id) {
80 Some(h) => h,
81 None => continue, // segment in manifest but not in open handles — skip
82 };
83 let reader = handle.reader();
84 for entry in reader.tiles() {
85 all_entries.push(TaggedEntry {
86 segment_id: seg_ref.id.clone(),
87 flush_lsn: seg_ref.flush_lsn,
88 tile_id: entry.tile_id,
89 });
90 }
91 }
92
93 if all_entries.is_empty() {
94 return Ok(PurgePlan {
95 segment_actions: Vec::new(),
96 cells_carried_forward: 0,
97 });
98 }
99
100 // ── Step 2: Check whether any tile is out-of-horizon. If none, no-op. ──────
101 let any_outside = all_entries
102 .iter()
103 .any(|e| e.tile_id.system_from_ms < horizon_ms);
104 if !any_outside {
105 return Ok(PurgePlan {
106 segment_actions: Vec::new(),
107 cells_carried_forward: 0,
108 });
109 }
110
111 // ── Step 3: Group entries by hilbert_prefix. ─────────────────────────────
112 // For each prefix, build: inside list, outside list (newest→oldest), and
113 // the earliest-flushed segment id for the ceiling host.
114 struct PrefixGroup {

Calls 15

decode_sparse_rowsFunction · 0.85
manifestMethod · 0.80
tilesMethod · 0.80
entryMethod · 0.80
read_tileMethod · 0.80
collectMethod · 0.80
push_rowMethod · 0.80
is_emptyMethod · 0.45
getMethod · 0.45
readerMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45