mova-pack
Prepare-then-zstd storage for Mova's big stores. Level 1 prepares the data: JSON lines become template lines against a template dictionary; CoNLL-like token files (.tok, .conllu) become typed streams (comment values per key, token columns apart, typical-value tables, predictions). Level 2 compresses each block with zstd-9 and a zstd dictionary trained on the prepared sample. Every container is cut into blocks of whole records that decode alone, and a separate offset index (<name>.idx.zst) maps record keys to (block, offset), so one document is read by decoding one block. Store files are replaced only after a verified round trip. How it works and what it measured: Compression: prepare, then a fast zstd.
Commands
mova-pack pack IN OUT.mpk [--kind auto|tok|json|lines|bytes] [--id [NAME=]SPEC]... [--prep auto|on|off]
[--level 9] [--block 1048576] [--threads 4] [--sample BYTES] [--split doc|sent]
[--zdict FILE] [--no-zdict] [--dicts DIR] [--min-free GB] [--format 1]
mova-pack cat IN.mpk [--threads 4] the original, byte for byte, to stdout
mova-pack get IN.mpk RECORD one record by its number
mova-pack get IN.mpk --id KEY | --key NAME=KEY the records of a key, through IN.idx.zst
mova-pack unpack IN.mpk OUT
mova-pack verify IN.mpk... full read against the stored sha256, index opened
mova-pack info IN.mpk the header
mova-pack repack FILE... [pack options] [--source PATH]
mova-pack gc ROOT... [--dicts DIR]... [--grace-days 7] [--apply]
mova-pack dict --kind json|lines --out DIR [--sample BYTES] [--zdict-size BYTES] INPUT...
mova-pack timeget IN.mpk N diagnostic: N reads by key, p50/p95
mova-pack bench pmc|json|openalex|textparquet SAMPLE OUTDIR [--quick] [--current-bytes N] [--domain KEY|p31]
mova-pack templates IN [N] diagnostic: the template dictionary of a JSON input
Inputs that are gzip, zstd or .mpk (recognized by their magic bytes) are decoded first, as a stream; the original is their content.
- pack streams the input into a format-2 container (bounded memory, any size), reads it back in full and checks the content's sha256 before the container and its index are renamed into place.
--format 1is the older in-memory container (no tok kind, no index). - Keys (
--id, repeatable; a key withoutNAME=is namedid):tok:doc(the# docvalue; the default for tok files),tok:sent(the first# sent_id),json:KEY(a top-level key),json:/pointer(a JSON pointer),tsv:N(a column),prefix:TEXT(a line starting with TEXT opens the key for the records after it).nonewrites no index. - cat decodes blocks on several threads and writes them in order; it fails at the end when the sha256 of what it wrote differs from the stored one. A reader that used
zstdcat FILE.tok.zstusesmova-pack cat FILE.tok.mpk. - dict trains a shared dictionary from the supplied inputs. The zstd dictionary capacity defaults to 112,640 bytes and can be set with
--zdict-sizeup to 64 MiB. The trainer may produce a smaller dictionary. Raising the capacity above the default requires a sample budget of at least four times the capacity. Input files are loaded into memory before sampling. - repack converts a store file in place: the new container and index go to temporary names beside it, the container is read back in full (sha256 against the hash taken while reading the original) and the index is checked (every 1/64th record found by each key), then the original moves to
.pack-aside/<name>.<unix time>, the new files are renamed to<name without .gz/.zst/.mpk>.mpkand.idx.zst, and.pack-aside/journal.tsvgets a line.--min-free GBrefuses to start without room for the new container above the floor and stops (removing its own unfinished file) when free space falls below it.--source PATHreads the content from an original already moved elsewhere (for example to another filesystem, to keep room) and journals that path as the aside copy. A failed check leaves the original where it was and keeps the candidate as.pack-aside/<target>.failed-<time>. - gc prints what it would remove: temporary files older than a day, failed candidates and moved-aside originals older than the grace period (an original only when its replacement's header still carries the journaled sha256), and dictionaries in
--dictsdirectories that no container under the roots references. Nothing is removed without--apply. - bench measures one representative unit of a store (the samples of docs/compression.md);
openalexandtextparquetneed--features parquet.
Build and test
cargo build --release -p mova-pack # mova-pack in target/release/
cargo build --release -p mova-pack --features parquet # with the parquet readers for bench
cargo test --release -p mova-pack
Format
Format 2 (.mpk, written by pack and repack): magic MOVAPACK\x02\n, an embedded zstd dictionary (unless it is referenced in a dictionary directory), the blocks (independent zstd frames), then a footer: a zstd frame of the header JSON (kind, preparation, keys, level, block size, the original's size and sha256, record and block counts, dictionaries), a zstd frame of the block table (varints per block: records, raw bytes, compressed bytes) and a 32-byte tail (footer offset, header and table frame lengths, MPK2END\n). Each block decodes alone to its exact original bytes; the original is the concatenation of the blocks.
Format 1 (still read): magic MOVAPACK\x01\n, header length (u32 LE), header JSON with the block list, data area.
The index <name>.idx.zst is a plain zstd stream: zstd -dc prints TSV lines name \t key \t block \t offset \t count, sorted by name and key, in zstd-9 frames of 8192 lines with content checksums; two skippable frames after them hold the chunk table (bound to the container's content sha256, record and block counts) and its sha256. A lookup decodes one frame. The formats are not frozen yet.
Rust callers can use pack::open_text(path) as a streaming reader. It tries the requested path, then appends .mpk and .zst in order if the path is missing. MPK integrity is checked on a complete read to EOF. A malformed preferred archive returns an error. For MPK containers with externally stored dictionaries, use pack::stream::content_reader with the explicit path and dictionary directories.
Limits
Format 1 holds the whole input in memory; format 2 holds the index entries (keys of all records) in memory until the end. One writer per directory; no locking. JSON is kept exactly as written, never normalized. gzip and parquet encodings are not reproduced: a repacked .gz or .zst becomes an .mpk of its content, and readers must change with it. A prefix key's continuation records are checked only through their run, not by their own text.
This page in Markdown https://md.mova.elamur.ai/free/en/docs/pack/