Expand description
Transparent block-storage compression for WombatKV.
Real product feature: KV blocks emitted by inference engines are
highly compressible, large stretches of near-zero values dominate
later attention layers, so transparent zstd shrinks S3 storage cost
~3-4× on typical bench artifacts without changing the C ABI or the
BlockMeta schema.
§Wire format
Compressed blobs carry a 10-byte header:
0 4 5 6 10
+-------+-------+-------+--------------+--------------------+
| "WBZ1"| algo | level | u32 raw_len | compressed payload |
+-------+-------+-------+--------------+--------------------+
| magic | u8 | u8 | LE | |
+-------+-------+-------+--------------+--------------------+- Magic
b"WBZ1"(WombatKVblob zstd v1) is the only signature a decoder needs to detect compression. Anything else is treated as raw uncompressed bytes, old buckets stay readable verbatim. - algo = 1 for zstd. Reserved 2 = lz4 (future). 0 = none (header only ever used by tests; production never writes a “compressed with none” blob).
- level = the zstd level the producer used. Stored for observability; not consulted on decode.
raw_len= uncompressed size (u32). Caps a single block at 4 GiB, which is far above any realistic KV block.
§Layering
Compression is applied at the object-store boundary inside
put_kv / get_kv. The in-memory flat-file and foyer tiers keep
uncompressed bytes, they are warm-read caches, decoding once on the
cold-from-S3 path is cheap, and skipping it on every cache hit keeps
the warm TTFT story intact.
§Compatibility
Mixed-state buckets are first-class: every read calls
decode_if_compressed, which inspects the magic and falls through
to a no-copy Cow::Borrowed when the header is absent or corrupt.
Structs§
- Block
Compression Config - Compression policy resolved at handle construction time.
Enums§
- Compress
Algo - Compression algorithm tag. Stored as a
u8in the wire header. - Compression
Error - Compression pipeline failures.
Constants§
- COMPRESS_
HEADER_ SIZE - Total header size: 4 (magic) + 1 (algo) + 1 (level) + 4 (
raw_len) = 10. - COMPRESS_
MAGIC - Magic prefix for a compressed
WombatKVblock. ASCII so logs are human-readable.
Functions§
- decode_
if_ compressed - Inspect
bytes. If the magic header is present and decodes cleanly, return the decompressed payload asCow::Owned. Otherwise returnCow::Borrowed(bytes)so the no-compression hot path stays allocation-free. - encode_
with_ header - Encode
payloadwith the configured codec, prepending the 10-byte header. Returns the raw payload (no header) whencfg.algoisNoneso callers can blindly call this and get back-compat bytes for free. - has_
magic - Quick magic check used by the put-path metrics emitter. Cheap enough to call on every blob.