Remove segments from the manifest and drop their handles. The underlying file is deleted only after the manifest is persisted (caller's responsibility — see [`ArrayStore::unlink_segment`]).
(
&mut self,
removed: &[String],
added: Vec<SegmentRef>,
)
| 159 | /// underlying file is deleted only after the manifest is persisted |
| 160 | /// (caller's responsibility — see [`ArrayStore::unlink_segment`]). |
| 161 | pub fn replace_segments( |
| 162 | &mut self, |
| 163 | removed: &[String], |
| 164 | added: Vec<SegmentRef>, |
| 165 | ) -> Result<(), ArrayStoreError> { |
| 166 | let mut new_handles = Vec::with_capacity(added.len()); |
| 167 | for seg in &added { |
| 168 | let h = SegmentHandle::open( |
| 169 | &segment_path(&self.root, &seg.id), |
| 170 | seg.id.clone(), |
| 171 | self.schema_hash, |
| 172 | self.kek.as_ref(), |
| 173 | )?; |
| 174 | new_handles.push(h); |
| 175 | } |
| 176 | self.manifest.replace(removed, added); |
| 177 | for id in removed { |
| 178 | self.segments.remove(id); |
| 179 | } |
| 180 | for h in new_handles { |
| 181 | self.segments.insert(h.id().to_string(), h); |
| 182 | } |
| 183 | Ok(()) |
| 184 | } |
| 185 | |
| 186 | pub fn persist_manifest(&self) -> Result<(), ArrayStoreError> { |
| 187 | self.manifest.persist(&self.root)?; |