Expand description
Wire format for replicated mutations — see docs/wire.md for the
full spec.
Each frame is *2\r\n:<offset>\r\n<RESP2 multi-bulk argv>. The
envelope is itself a valid RESP2 array of 2 elements, so any
RESP-aware debug tool can peek a captured stream. The inner argv
payload is byte-identical to what a client would have sent when
issuing the same command, so feeding it through the existing
parse_command_into reconstructs the same Argv the primary
applied.
Enums§
- Snapshot
Marker - Decoded snapshot marker, returned by
decode_snapshot_marker. - Wire
Error - Wire-layer error. Only
WireError::Truncatedis recoverable by the caller (read more bytes and retry); the other variants signal a corrupt or protocol-violating peer and call for dropping the connection.
Constants§
- SNAPSHOT_
CHUNK_ MAX - Per-chunk cap: a chunk’s
$L\r\nlength must not exceed this. Replica drops the link if a chunk header reports a larger size. 64 KiB matches a typical TCP segment + keeps the per-chunk allocation modest. The primary may pick any chunk size from1up to this. - SNAPSHOT_
LINE_ MAX - Maximum length of a snapshot control line (
+SNAPSHOT_END N\r\n). 256 B is generous — the longest legal line is+SNAPSHOT_END+ 20 digits +\r\n= 38 B.
Functions§
- decode_
frame - Decode the first complete frame at the front of
buf. - decode_
snapshot_ chunk - Decode the next snapshot chunk (
$L\r\n<L bytes>\r\n) at the front ofbuf. Returns: - decode_
snapshot_ marker - Peek the next line at the front of
bufto detect a snapshot marker. Returns: - encode_
frame - Encode one replication frame: outer
*2, offset integer, then the argv as a RESP2 multi-bulk request. Allocates a freshVec<u8>. Generic overArgvViewso the hot path can pass a borrowed argv straight from the dispatcher (no Argv materialisation per write). - encode_
snapshot_ begin - Encode the snapshot-begin marker. Allocates the exact 11 bytes.
- encode_
snapshot_ chunk - Encode one snapshot chunk as a RESP bulk string. Caller is
responsible for chunking — typical strategy is fixed
SNAPSHOT_CHUNK_MAX-sized reads from a snapshot file or in-memory serializer. - encode_
snapshot_ end - Encode the snapshot-end marker carrying the ack offset (the next live frame’s offset will equal this value).