Skip to main content

Module handshake

Module handshake 

Source
Expand description

Replication handshake — the first round-trip a replica makes against the primary’s replication TCP listener.

Wire shape:

  • Replica → primary: a RESP2 multi-bulk command REPLICATE FROM <from-offset> ID <replica-id> (5 args). The <from-offset> is 0 for a fresh replica (full-sync intent) or the last applied offset from a reconnecting replica.
  • Primary → replica: a RESP2 simple string +ACK <current-offset>, where <current-offset> is the primary’s next_offset at the moment of ack. The replica records it and starts consuming live frames; if the primary’s crate::source::ReplicationSource cannot serve from <from-offset> (TooOld), the primary instead begins a snapshot ship (handled by the wiring layer, not here).

This module owns only the parse + format primitives. Socket I/O, retry, and “did the primary choose snapshot vs live stream” logic live in the future replication source/replica modules.

Structs§

HandshakeReq
Parsed REPLICATE FROM <from-offset> ID <replica-id> request.

Enums§

HandshakeError
Why a parse_replicate_from call rejected its input.

Functions§

encode_ack
Encode the primary’s +ACK <current-offset>\r\n response.
parse_replicate_from
Parse a REPLICATE FROM <offset> ID <id> command from an already-decoded Argv (the caller has run the bytes through kevy_resp::parse_command_into first).