feat: add PersistConfig, SnapshotHeader, ReplEnvelope Cap'n Proto schemas (P0-9)

Extends src/schema/controller.capnp with persistence structures needed
for WAL replication and snapshots:

- PersistConfig (8 fields, @0-@7): capnp-serialisable copy of the
  persistence configuration; mapped to capnp_persist_cfg_t to avoid
  collision with the plain-C persist_config_t in persist.h
- SnapshotHeader (9 fields, @0-@8): snapshot manifest with LSN, term,
  timestamp, record counts and checksums; mapped to capnp_snap_hdr_t
- ReplEnvelope (6 fields, @0-@5): replication wire envelope (NOT the
  on-disk format); named to avoid collision with wal_entry_hdr_t and
  the WALEntry_ internal symbol c-capnproto generates; mapped to
  capnp_repl_envelope_t

Also extends existing structs:
- Job.transientSince @11 (UInt64=0, mapname transient_since): set when
  job enters JOB_STAT_TRANSIENT; also adds uint64_t transient_since to
  xce_job_t in types.h
- Worker.deadSince @6 (UInt64=0, mapname dead_since): mirrors existing
  time_t dead_since field in xce_worker_t

OPCode enum extended with 7 replication opcodes @22-@28:
  replEntry, replAck, redirect, heartbeat, steppingDown,
  replSnapshot, replCatchUpDone

New C typedefs (capnp_persist_cfg_t, capnp_snap_hdr_t,
capnp_repl_envelope_t) added to typemap.h for the encode/decode shims.

TDD: test_persist_schema.c added (6 tests, all GREEN). Controller test
suite remains 1/1 PASS.
This commit is contained in:
Rongsong Shen 2026-05-07 10:19:33 +00:00
parent 1fe79ff934
commit 4903c83f28
6 changed files with 214 additions and 16 deletions

View file

@ -200,4 +200,40 @@ typedef struct {
} body;
} xce_request_t;
/* ── Persistence Cap'n Proto mapped types (P0-9) ─────────────────────
* These are the C-side counterparts for the capnp encode/decode shims.
* Named with capnp_ prefix to avoid collision with the plain-C structs
* in persist.h (persist_config_t) and the on-disk binary formats. */
typedef struct {
uint32_t walSyncMs;
uint32_t snapIntervalS;
uint32_t snapWalSizeMb;
uint32_t finishedRetainS;
uint32_t workerRetainS;
uint32_t syncTimeoutMs;
uint32_t snapKeepN;
uint32_t transientJobTimeoutS;
} capnp_persist_cfg_t;
typedef struct {
uint64_t lsn;
uint64_t term;
uint64_t timestamp;
uint32_t version;
uint32_t nJobs;
uint32_t nQueues;
uint32_t nWorkers;
uint32_t checksum;
uint32_t headerChecksum;
} capnp_snap_hdr_t;
typedef struct {
uint64_t term;
uint64_t lsn;
uint32_t entryType;
xce_data_t* payload; /* owned; decoded via decode_Data_ptr */
uint32_t crc;
uint32_t prevCrc;
} capnp_repl_envelope_t;
#endif

View file

@ -472,6 +472,7 @@ typedef struct {
char* ckptinfo;
int64_t pending_ctrl;
xce_job_preason_t* pend_reasons;
uint64_t transient_since; /* epoch seconds; set when job enters JOB_STAT_TRANSIENT */
} xce_job_t;
typedef struct {