Expand description
Replication Module
Implements single-primary, multi-replica replication via WAL streaming.
§Architecture
- Primary: accepts writes and streams WAL records to replicas
- Replica: read-only, connects to primary for WAL streaming
- Initial sync via snapshot transfer, then incremental WAL
§Usage
ⓘ
// Primary
let options = RedDBOptions::persistent("./primary-data")
.with_replication(ReplicationConfig::primary());
// Replica
let options = RedDBOptions::persistent("./replica-data")
.with_replication(ReplicationConfig::replica("http://primary:50051"));Modules§
- cdc
- Change Data Capture (CDC) — stream of database change events.
- commit_
policy - Primary commit policies (PLAN.md Phase 11.4).
- commit_
waiter - Synchronous commit waiter (PLAN.md Phase 11.4 —
ack_n). - lease
- Serverless writer lease (PLAN.md Phase 5 / W6).
- logical
- Logical replication helpers shared by replica apply and point-in-time restore.
- primary
- Primary-side replication: WAL record production and snapshot serving.
- quorum
- Quorum-based commit coordination (Phase 2.6 multi-region PG parity).
- replica
- Replica-side replication: connects to primary, consumes WAL records.
- scheduler
- Backup Scheduler — automatic periodic snapshots with optional remote upload.
- topology_
advertiser - Server-side
TopologyAdvertiser(issue #167).
Structs§
- Commit
Waiter - LagConfig
- Knobs for the lag/health computation. Kept as a small struct so
the call sites (gRPC
topologyRPC, RedWire HelloAck builder) thread the same defaults without each one redeclaring constants. - Lease
Store - Wraps an
AtomicRemoteBackendwith lease primitives. The lease object is stored under a deterministic key derived fromdatabase_key; the store reads/writes that one key. - Quorum
Config - Quorum configuration stored alongside
ReplicationConfig. - Quorum
Coordinator - Tracks per-replica region bindings and pairs them with the primary’s
ack map.
PrimaryReplicationowns the WAL buffer +ReplicaStatelist; this coordinator adds the region dimension and the wait-for- quorum logic without duplicating the ack table. - Replication
Config - Configuration for replication.
- Topology
Advertiser - Server-side advertiser. Zero-sized — all state is threaded
through
advertise()’s arguments so callers control the snapshot semantics. - Topology
Auth Gate - Predicate over the caller’s auth context — answers “does this
principal have
cluster:topology:read?”. - Writer
Lease - One snapshot of who owns the writer lease for a database key.
Enums§
- Await
Outcome - Commit
Policy - Lease
Error - Quorum
Error - Errors raised by the quorum coordinator. The write itself succeeded on the primary WAL — these errors signal that replica acknowledgement did not reach quorum and the caller must decide whether to surface the failure or continue anyway.
- Replication
Role - Role of this RedDB instance in a replication cluster.
Constants§
- DEFAULT_
REPLICA_ TIMEOUT_ MS - Default replica heartbeat timeout used when an operator hasn’t
configured one explicitly. Matches the order of the
poll_interval_msdefault inReplicationConfig(100 ms) multiplied by a generous fudge factor — five seconds without an ack flips a replica tohealthy: false. Operators tune this viaLagConfig. - TOPOLOGY_
READ_ CAPABILITY - Capability name from ADR 0008 §1.