Skip to main content

Module primary

Module primary 

Source
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 acknowledged append() 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§

LogicalWalSpool
Durable append-only logical WAL spool kept beside the main .rdb file.
PrimaryReplication
Primary replication manager.
ReplicaState
State of a connected replica. PLAN.md Phase 11.4 fields: last_seen_at_unix_ms updates on every interaction (pull or ack); last_sent_lsn updates when the primary serves a pull_wal_records batch; last_durable_lsn updates when the replica reports its WAL is durably written via ack_replica_lsn.
WalBuffer
In-memory WAL buffer for replication. Primary appends records here; replicas consume from it.