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>,
)
| 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 | /// |