Roll back in-memory inserts to `row_count_before`. Undoes the effect of one or more inserts that appended rows starting at `row_count_before`. For each inserted row: - The corresponding PK entry is removed from the PK index. - If the insert displaced a prior row (upsert tombstone), that prior row's PK index entry is restored and its tombstone bit cleared. The memtable is then truncated to `row_c
(
&mut self,
row_count_before: usize,
inserted_pks: &[Vec<u8>],
displaced: &[(Vec<u8>, crate::pk_index::RowLocation)],
)
| 214 | /// The memtable is then truncated to `row_count_before`. Used exclusively |
| 215 | /// by the transaction undo log; never called on the normal write path. |
| 216 | pub fn rollback_memtable_inserts( |
| 217 | &mut self, |
| 218 | row_count_before: usize, |
| 219 | inserted_pks: &[Vec<u8>], |
| 220 | displaced: &[(Vec<u8>, crate::pk_index::RowLocation)], |
| 221 | ) { |
| 222 | // 1. Remove newly inserted PK entries. |
| 223 | for pk in inserted_pks { |
| 224 | self.pk_index.remove(pk); |
| 225 | } |
| 226 | // 2. Restore displaced prior-row PK entries and clear tombstones. |
| 227 | for (pk, prior_location) in displaced { |
| 228 | self.pk_index.upsert(pk.clone(), *prior_location); |
| 229 | // Clear the tombstone bit that the insert set on the prior row. |
| 230 | if let Some(bm) = self.delete_bitmaps.get_mut(&prior_location.segment_id) { |
| 231 | bm.unmark_deleted(prior_location.row_index); |
| 232 | } |
| 233 | } |
| 234 | // 3. Truncate memtable and surrogate list. |
| 235 | self.memtable.truncate_to(row_count_before); |
| 236 | self.memtable_surrogates.truncate(row_count_before); |
| 237 | self.memtable_row_counter = row_count_before as u32; |
| 238 | } |
| 239 | |
| 240 | /// The segment ID that will be assigned to the next flushed segment. |
| 241 | /// |
no test coverage detected