Expand description
Primary-side replication: WAL record production and snapshot serving.
§Logical WAL spool wire format
§Version 2 (current — PLAN.md Phase 2 / W2)
[magic 4 bytes = b"RDLW"]
[version 1 byte = 0x02]
[lsn 8 bytes little-endian u64]
[timestamp 8 bytes little-endian u64 — wall-clock millis since UNIX epoch]
[payload_len 4 bytes little-endian u32]
[payload payload_len bytes]
[crc32 4 bytes little-endian u32 — crc32fast of (version || lsn ||
timestamp || payload_len || payload)]sync_all()is called after every append so an acknowledgedappend()survives a power-loss event.- Recovery accepts the longest valid prefix and silently truncates at the first torn header, short payload/crc, or checksum mismatch (warning logged). No partial record is ever returned to the replication subsystem.
§Version 1 (legacy, read-only)
[magic 4][version 1=0x01][lsn 8][payload_len 8][payload]No checksum, no timestamp. Read for backward compatibility on
existing spools; never written. A v1 record found in a spool will
be returned to consumers but flagged via LogicalWalEntry::v1.
Structs§
- Logical
WalSpool - Durable append-only logical WAL spool kept beside the main
.rdbfile. - Primary
Replication - Primary replication manager.
- Replica
State - State of a connected replica. PLAN.md Phase 11.4 fields:
last_seen_at_unix_msupdates on every interaction (pull or ack);last_sent_lsnupdates when the primary serves apull_wal_recordsbatch;last_durable_lsnupdates when the replica reports its WAL is durably written viaack_replica_lsn. - WalBuffer
- In-memory WAL buffer for replication. Primary appends records here; replicas consume from it.