kevy_replicate/lib.rs
1//! kevy-replicate — primary-to-replica streaming replication.
2//!
3//! One primary streams every applied
4//! mutation to N read replicas over a long-lived TCP connection, using a
5//! RESP3-extended frame format with an offset envelope. New replicas join
6//! via an inline snapshot ship, then catch up from the live frame stream.
7//!
8//! - [`wire`] — RESP-based frame format (see `docs/wire.md`).
9//! - `wire_snapshot` (internal) — snapshot-ship framing for the joining
10//! replica.
11//! - [`source`] — primary-side bounded backlog indexed by offset.
12//! - [`handshake`] — `REPLICATE FROM <offset> ID <id>` parse + `+ACK` format.
13//! - [`slot`] — per-replica state + reconnect-window expiry.
14//! - [`replica`] — replica-side blocking TCP client (handshake +
15//! frame-decoding iterator).
16//!
17//! # Applying replicated frames
18//!
19//! `ReplicaClient` yields decoded `(offset, Argv)` tuples; *applying*
20//! them to a local store is the caller's responsibility — the right
21//! dispatcher depends on where the replica's data lives. The wire
22//! format intentionally carries the exact RESP argv the primary
23//! applied, so any dispatcher that hands `Argv` through Redis-verb
24//! routing produces a byte-equivalent local store.
25//!
26//! The canonical in-process recipe — drop into a fresh
27//! `kevy::KeyspaceStore` and dispatch through `kevy::KevyCommands`:
28//!
29//! ```ignore
30//! use kevy_replicate::replica::ReplicaClient;
31//! let mut client = ReplicaClient::connect(("primary:16004"), "replica-a", 0)?;
32//! let kevy = kevy::KevyCommands::new();
33//! let mut store = kevy::KeyspaceStore::new();
34//! for result in &mut client {
35//! let frame = result?;
36//! kevy.dispatch(&mut store, &frame.argv);
37//! }
38//! # Ok::<_, kevy_replicate::replica::ReplicaError>(())
39//! ```
40//!
41//! See the `replica_apply_dispatch_mirrors_primary_store` integration
42//! test in `crates/kevy/tests/replication.rs` for the pattern under
43//! the full primary+replica end-to-end harness.
44//!
45//! The kevy binary also ships full **server-as-replica** mode (it
46//! auto-spawns a `ReplicaClient` when `[replication] role = "replica"`,
47//! routing frames into the reactor with re-replication suppression);
48//! the in-process recipe above is for any user that wants to drive
49//! replication themselves.
50#![forbid(unsafe_code)]
51#![warn(missing_docs)]
52
53pub mod feed;
54pub mod handshake;
55pub mod replica;
56mod replica_error;
57mod replica_decode;
58pub mod slot;
59pub mod source;
60pub mod wire;
61mod wire_snapshot;