Expand description
Server KV store (docs/design/kv.md): opcodes, record codecs, and the client-side mirror reducer. Server KV store wire protocol (docs/design/kv.md).
A host-local key→value store with CAS writes and prefix-watch
subscriptions. Keys are raw UTF-8 (≤ [KV_MAX_KEY] bytes, no NUL,
non-empty); values are opaque bytes, LZ4 on the wire. CAS is
BLAKE3-128 over value bytes with the zero-hash absent sentinel,
[docs/design/fs-write.md]’s conflict model verbatim.
All integers little-endian, tightly packed, as everywhere in the protocol.
Structs§
- KvEntry
- One mirrored entry.
- KvMirror
- The complete watcher obligation: apply updates, read
live. - KvPut
- A CAS put or delete (
C2S_KV_PUT). - KvRecord
Iter - Iterate records in an uncompressed
KV_UPDATEpayload. Unknown kinds are skipped viarecord_len; a malformed record ends iteration (forward-compatible with future record extensions, the fs rule).
Enums§
- KvRecord
- One decoded record from a
KV_UPDATEpayload.
Constants§
- C2S_
KV_ ACK - Cumulative acknowledgement: [0x72][kv_id:2][update_id:4]
- C2S_
KV_ FETCH - Fetch one value: [0x74][nonce:2][key_len:2][key:N]
- C2S_
KV_ OPEN - Subscribe to a prefix: [0x70][nonce:2][flags:1][inline_max:4][prefix_len:2][prefix:N] The prefix is a literal byte prefix (no glob); empty = whole store.
- C2S_
KV_ PUT - CAS put/delete: [0x73][nonce:2][flags:1][base:16][key_len:2][key:N][value:LZ4]
baseis the CAS precondition on the current value bytes: non-zero = match-or-CONFLICT, zero = create-exclusive, ignored underKV_PUT_NO_CAS. - C2S_
KV_ STOP - Close a subscription: [0x71][kv_id:2]
- FEATURE_
KV S2C_HELLOfeature bit: server supports theKV_*family (docs/design/kv.md).BLIT_KV=0refuses everyKV_*at dispatch withPERMISSIONinstead of un-advertising.- KV_
CLOSED_ RESOURCE_ LIMIT - Queued-unacked bytes exceeded
BLIT_KV_UNACKED_MAX(docs/design/kv.md § Budgets); the subscription was dropped. - KV_
CONTENT_ FULL - KV_
CONTENT_ NONE - KV_
ID_ INVALID kv_idreported by a failedKV_OPENED.- KV_
MAX_ KEY - Maximum key length in bytes (fixed, not an env knob).
- KV_
PUT_ DELETE - Remove the entry (value must be empty). A delete is a put of absence;
basezero with DELETE is INVALID (delete-iff-absent is meaningless). - KV_
PUT_ DURABLE - fsync the store before replying; default trades durability for latency.
- KV_
PUT_ NO_ CAS - Ignore
base; unconditional put/delete. - KV_
RECORD_ DELETE - KV_
RECORD_ UPSERT - KV_
STATUS_ BUDGET - KV_
STATUS_ CONFLICT - A CAS precondition failed (mismatch, or create-exclusive on an existing
key).
KV_DONE.hashcarries the current value hash. - KV_
STATUS_ INVALID - KV_
STATUS_ NOT_ FOUND - KV_
STATUS_ OK - KV_
STATUS_ OTHER - KV_
STATUS_ PERMISSION - KV_
STATUS_ TOO_ LARGE - KV_
UPDATE_ SNAPSHOT_ END - This batch completes the initial snapshot; subsequent updates are live.
- S2C_
KV_ CLOSED - Subscription ended server-side: [0x74][kv_id:2][reason:1]
After it the
kv_idis dead; a client that still wants the prefix re-opens withKV_OPENand receives a fresh snapshot — lossless, because updates carry state, not events (docs/design/kv.md § Watch). - S2C_
KV_ DONE - Put result: [0x72][nonce:2][status:1][hash:16][mtime_ns:8] — one per
KV_PUT. On successhashis the new value hash (zero for a delete); onCONFLICTit carries the current hash so the client rebases without a round trip. - S2C_
KV_ OPENED - Subscription accepted or refused: [0x70][nonce:2][kv_id:2][status:1][detail_len:2][detail:N]
- S2C_
KV_ UPDATE - Snapshot/live records: [0x71][kv_id:2][update_id:4][flags:1][records:LZ4]
- S2C_
KV_ VALUE - Fetch result: [0x73][nonce:2][status:1][hash:16][data:LZ4]
Functions§
- append_
kv_ record - Append one record to an uncompressed
KV_UPDATErecords buffer. - kv_
key_ valid - Wire-key validity: non-empty UTF-8 (guaranteed by
&str), ≤KV_MAX_KEYbytes, no NUL. - kv_
put_ declared_ value_ len - Parse a
C2S_KV_PUT.None= malformed, a non-UTF-8 key, or a value whose declared decompressed size exceeds the protocol cap. The decompressed size aC2S_KV_PUTclaims for its value, read without inflating it. - kv_
records - kv_
status_ text - Human-readable name for a
KV_*status code. - msg_
kv_ ack - msg_
kv_ closed - msg_
kv_ done - Build an
S2C_KV_DONE. On successhashis the new value hash (zero for a delete); onCONFLICTthe current hash. - msg_
kv_ fetch - msg_
kv_ open - msg_
kv_ opened - msg_
kv_ put - msg_
kv_ stop - msg_
kv_ update - Build a
KV_UPDATEfrom an uncompressed records buffer. - msg_
kv_ value - parse_
kv_ ack - Parse a
C2S_KV_ACK→(kv_id, update_id). - parse_
kv_ closed - Parse an
S2C_KV_CLOSED→(kv_id, reason). - parse_
kv_ done - Parse an
S2C_KV_DONE→(nonce, status, hash, mtime_ns). - parse_
kv_ fetch - Parse a
C2S_KV_FETCH→(nonce, key). - parse_
kv_ open - Parse a
C2S_KV_OPEN→(nonce, flags, inline_max, prefix). - parse_
kv_ opened - Parse an
S2C_KV_OPENED→(nonce, kv_id, status, detail). - parse_
kv_ put - parse_
kv_ stop - Parse a
C2S_KV_STOP→kv_id. - parse_
kv_ value - Parse an
S2C_KV_VALUE→(nonce, status, hash, data).