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

Method remap_segment

nodedb-columnar/src/pk_index.rs:97–116  ·  view source on GitHub ↗

Remap all entries pointing to `old_segment_id` using a provided function. Used after compaction: old segment IDs are replaced with new ones, and row indices may shift. The `remap_fn` returns `None` to remove the entry (row was deleted during compaction) or `Some(new_location)`.

(
        &mut self,
        old_segment_id: u64,
        remap_fn: impl Fn(u32) -> Option<RowLocation>,
    )

Source from the content-addressed store, hash-verified

95 /// and row indices may shift. The `remap_fn` returns `None` to remove
96 /// the entry (row was deleted during compaction) or `Some(new_location)`.
97 pub fn remap_segment(
98 &mut self,
99 old_segment_id: u64,
100 remap_fn: impl Fn(u32) -> Option<RowLocation>,
101 ) {
102 let keys_to_remap: Vec<Vec<u8>> = self
103 .inner
104 .iter()
105 .filter(|(_, loc)| loc.segment_id == old_segment_id)
106 .map(|(k, _)| k.clone())
107 .collect();
108
109 for key in keys_to_remap {
110 let old_loc = self.inner.remove(&key).expect("key exists from filter");
111 if let Some(new_loc) = remap_fn(old_loc.row_index) {
112 self.inner.insert(key, new_loc);
113 }
114 // If remap_fn returns None, the entry is dropped (row was deleted).
115 }
116 }
117
118 /// Bulk insert entries for a newly flushed segment.
119 ///

Callers 4

remap_segmentFunction · 0.80
on_memtable_flushedMethod · 0.80

Calls 6

collectMethod · 0.80
iterMethod · 0.45
cloneMethod · 0.45
expectMethod · 0.45
removeMethod · 0.45
insertMethod · 0.45

Tested by 2

remap_segmentFunction · 0.64