Skip to main content

compact

Function compact 

Source
pub fn compact(
    root: &Path,
    signal: &str,
    node: u32,
    cutoff_ns: i64,
) -> Result<usize>
Expand description

Rewrite aged blocks ZSTD-compressed, in place.

Measured by cargo run --release -p miradb-core --example tier over section 11’s corpus: 0.113 of the plain size for logs, 0.126 for traces, at 634 MiB/s on one core. Warm, reading a compacted block back costs 1.11× the plain read — the inflate is real and it is small. Cold, which is the only state a block old enough to be compacted is in, 8.4× fewer pages to fault and 8.4× fewer bytes to CRC more than pays for it. So the tier costs the read path the zero-copy property and a tenth of a warm read, and only for data nothing is scanning any more.

Crash safety is the trick publish already uses: write beside the target, then rename. A crash leaves a directory with some tables compressed and some not, which reads correctly — the codec is per-batch IPC metadata, not a property of the directory — and the absent marker makes the next sweep finish the job.