Skip to main content

reinsert_batch

Function reinsert_batch 

Source
pub fn reinsert_batch(
    db: &Database,
    collection: &str,
    batch: &[(RawFact, Vec<f32>)],
) -> Result<BatchReinsertion, MemoryError>
Expand description

Put a whole batch back, in one write.

The reason a batch exists at all is throughput — a per-fact write costs an fsync each, which is what made a rebuild of a real store look impossible before #1797. The reason it is dangerous is that batching is exactly where an id, a reserved key or an expiry gets dropped without anyone noticing, since nothing fails.

Occupied ids are collected FIRST and excluded from the write, so a batch containing one collision still lands the rest and still overwrites nothing.

§Errors

Returns crate::MemoryError if the collection is absent, a payload is unreadable, or the write fails.