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:
parent
1fe79ff934
commit
4903c83f28
6 changed files with 214 additions and 16 deletions
|
|
@ -70,6 +70,7 @@ controller_unit_test_src = [
|
|||
'testsuite/controller_test.c',
|
||||
'testsuite/test_persist_types.c',
|
||||
'testsuite/test_persist_wal.c',
|
||||
'testsuite/test_persist_schema.c',
|
||||
'persist.c',
|
||||
]
|
||||
|
||||
|
|
@ -79,6 +80,7 @@ controller_unit_test_deps = [
|
|||
tinylog_dep,
|
||||
thread_dep,
|
||||
zlib_dep,
|
||||
c_capnproto_dep,
|
||||
]
|
||||
|
||||
controller_unit_test = executable('controller_unit_test',
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
extern void test_persist_types(void);
|
||||
extern void test_persist_wal(void);
|
||||
extern void test_persist_schema(void);
|
||||
|
||||
void setUp(void) { return; }
|
||||
|
||||
|
|
@ -83,6 +84,7 @@ int main(int argc, char* argv[])
|
|||
UNITY_BEGIN();
|
||||
TEST(test_persist_types);
|
||||
TEST(test_persist_wal);
|
||||
TEST(test_persist_schema);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
|
|
|
|||
110
src/controller/testsuite/test_persist_schema.c
Normal file
110
src/controller/testsuite/test_persist_schema.c
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/* Test that generated Cap'n Proto types for persistence exist and have correct
|
||||
* fields. This is a compile-time / linkage test — the real assertion is that
|
||||
* ninja succeeds with the new schema additions. */
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <unity/unity.h>
|
||||
|
||||
#include "controller.capnp.h"
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* PersistConfig */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
static void test_persist_config_schema_fields(void)
|
||||
{
|
||||
/* Verify struct is defined and has the expected word/byte counts.
|
||||
* c-capnproto generates <Struct>_struct_bytes_count constants. */
|
||||
(void)PersistConfig_struct_bytes_count;
|
||||
printf("test_persist_config_schema_fields: PASS\n");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* SnapshotHeader */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
static void test_snapshot_header_schema_fields(void)
|
||||
{
|
||||
(void)SnapshotHeader_struct_bytes_count;
|
||||
printf("test_snapshot_header_schema_fields: PASS\n");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* WALEntry */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
static void test_wal_entry_schema_fields(void)
|
||||
{
|
||||
/* Schema struct is named ReplEnvelope to avoid collision with the
|
||||
* on-disk wal_entry_hdr_t C type and the WALEntry_ generator symbol. */
|
||||
(void)ReplEnvelope_struct_bytes_count;
|
||||
printf("test_wal_entry_schema_fields: PASS\n");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Replication opcodes */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
static void test_repl_opcodes_exist(void)
|
||||
{
|
||||
/* These enum values must be present in the generated header. */
|
||||
int repl_entry = OPCode_replEntry;
|
||||
int repl_ack = OPCode_replAck;
|
||||
int redirect_op = OPCode_redirect;
|
||||
int heartbeat_op = OPCode_heartbeat;
|
||||
int stepping = OPCode_steppingDown;
|
||||
int repl_snap = OPCode_replSnapshot;
|
||||
int catchup_done = OPCode_replCatchUpDone;
|
||||
|
||||
/* All values must be > 21 (highest existing opcode clrpreason=21). */
|
||||
TEST_ASSERT_TRUE(repl_entry > 21);
|
||||
TEST_ASSERT_TRUE(repl_ack > 21);
|
||||
TEST_ASSERT_TRUE(redirect_op > 21);
|
||||
TEST_ASSERT_TRUE(heartbeat_op > 21);
|
||||
TEST_ASSERT_TRUE(stepping > 21);
|
||||
TEST_ASSERT_TRUE(repl_snap > 21);
|
||||
TEST_ASSERT_TRUE(catchup_done > 21);
|
||||
|
||||
printf("test_repl_opcodes_exist: PASS\n");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Job.transientSince and Worker.deadSince fields */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
static void test_job_transient_since_field(void)
|
||||
{
|
||||
/* c-capnproto preserves camelCase field names from the schema directly. */
|
||||
struct Job j;
|
||||
memset(&j, 0, sizeof(j));
|
||||
j.transientSince = 12345ULL;
|
||||
TEST_ASSERT_EQUAL_UINT64(12345ULL, j.transientSince);
|
||||
printf("test_job_transient_since_field: PASS\n");
|
||||
}
|
||||
|
||||
static void test_worker_dead_since_field(void)
|
||||
{
|
||||
struct Worker w;
|
||||
memset(&w, 0, sizeof(w));
|
||||
w.deadSince = 99999ULL;
|
||||
TEST_ASSERT_EQUAL_UINT64(99999ULL, w.deadSince);
|
||||
printf("test_worker_dead_since_field: PASS\n");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Suite entry point (called from controller_test.c) */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
void test_persist_schema(void)
|
||||
{
|
||||
printf("\n>> persist Cap'n Proto schema test\n\n");
|
||||
|
||||
RUN_TEST(test_persist_config_schema_fields);
|
||||
RUN_TEST(test_snapshot_header_schema_fields);
|
||||
RUN_TEST(test_wal_entry_schema_fields);
|
||||
RUN_TEST(test_repl_opcodes_exist);
|
||||
RUN_TEST(test_job_transient_since_field);
|
||||
RUN_TEST(test_worker_dead_since_field);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue