Skip to content
You are viewing the corvid 0.3.0 release snapshot — frozen at the 0.3.0 engine release.Current documentation

Compaction

Two distinct compactions exist — don’t confuse them:

  1. Db::compact() — file-level space reclamation (below).
  2. Automatic on-disk vector-index compaction — self-maintained; see index maintenance.
# use corvid::{Db};
# let dir = tempfile::tempdir().unwrap();
# let mut db = Db::open(dir.path().join("app.corvid"))?;
let moved = db.compact()?; // bool: whether any data moved
# let _ = moved;
# Ok::<(), corvid::Error>(())

After heavy deletes, freed pages can remain allocated in the file. compact() rewrites the database to reclaim that space — data unchanged, double-compact tolerated (the second is a no-op).

Offline maintenance: compact takes &mut self — the engine requires exclusive access. In practical terms: close other handles, or compact from a point in your lifecycle where the Db isn’t shared. Through the C ABI, corvid_compact checks exclusivity via the derived-handle counter and fails with the FFI-only CORVID_E_BUSY while collection/query handles are alive — a deterministic answer, never a hang.

  • After deleting a large fraction of a collection (file size doesn’t shrink on delete; compaction makes it shrink).
  • After TTL purges of big batches.
  • Not routinely — it’s O(file) offline work; the automatic vector-index compaction handles index bloat on its own.

Next: bulk loading.