feat: add config_repl Phase 1 — HEAD-file storage, SHA-256, trim, stale check, sanitise_cn

- config_repl.h/.c: atomic versioned file save, pointer file, trim, stale check
- test_config_repl.c: 17 Unity tests covering all Phase 1 storage functions
- typemap.h: add repl/heartbeat types + union members for xce_request_t/xce_reply_t
- clusterconfig.h: add config_generation field to cluster_config_t (capnp schema ref)
- meson.build: add config_repl.c and test_config_repl.c to build targets
- controller_test.c: register test_config_repl dispatch function
This commit is contained in:
Rongsong Shen 2026-05-13 15:45:28 +00:00
parent 1c4a103a66
commit 491c2550c2
7 changed files with 926 additions and 7 deletions

View file

@ -6,6 +6,16 @@
#include "clusterconfig.h"
#include "xce/types.h"
/* Forward declarations for config-replication types used in
* xce_reply_t and xce_request_t unions below. */
typedef struct repl_config_reply_s repl_config_reply_t;
typedef struct repl_config_push_reply_s repl_config_push_reply_t;
typedef struct upgrade_config_reply_s upgrade_config_reply_t;
typedef struct repl_config_req_s repl_config_req_t;
typedef struct repl_config_push_req_s repl_config_push_req_t;
typedef struct upgrade_config_req_s upgrade_config_req_t;
typedef struct heartbeat_msg_s heartbeat_msg_t;
typedef struct {
char* resname;
char* hostname;
@ -166,10 +176,13 @@ typedef struct {
int32_t status;
int data_which;
union {
char* debugmsg;
uint64_t jobid;
xce_data_t* getdata;
xce_clusterconf_t* clusterconf;
char* debugmsg;
uint64_t jobid;
xce_data_t* getdata;
xce_clusterconf_t* clusterconf;
repl_config_reply_t* replconfigreplymsg;
repl_config_push_reply_t* replconfigpushreplymsg;
upgrade_config_reply_t* upgradeconfigreplymsg;
} data;
} xce_reply_t;
@ -194,9 +207,13 @@ typedef struct {
xce_jobctrl_t* jobctrlmsg;
xce_queuectrl_t* queuectrlmsg;
xce_taskrun_t* runtaskmsg;
xce_preason_set_t* preasonmsg;
xce_clear_reason_t* clrpreasonmsg;
xce_hostctrl_t* hostctrlmsg;
xce_preason_set_t* preasonmsg;
xce_clear_reason_t* clrpreasonmsg;
xce_hostctrl_t* hostctrlmsg;
repl_config_req_t* replconfigrequestmsg;
repl_config_push_req_t* replconfigpushrequestmsg;
upgrade_config_req_t* upgradeconfigrequestmsg;
heartbeat_msg_t* heartbeatmsg;
} body;
} xce_request_t;
@ -236,4 +253,46 @@ typedef struct {
uint32_t prevCrc;
} capnp_repl_envelope_t;
/* ── Config replication Cap'n Proto mapped types (Phase 1) ──────────────
* C-side counterparts for the capnp encode/decode shims for config sync.
* Struct tags match the forward declarations near the top of this file. */
struct repl_config_req_s {
uint64_t version_tag; /* local config version tag */
};
struct repl_config_reply_s {
int up_to_date; /* 1 if standby is current */
uint64_t version_tag; /* primary's current version tag */
xce_data_t *sha256; /* 32-byte SHA-256 of config blob (may be NULL) */
xce_data_t *bytes; /* serialised ClusterConfig blob (may be NULL) */
};
struct repl_config_push_req_s {
uint64_t version_tag; /* version tag of the pushed config */
xce_data_t *sha256; /* 32-byte SHA-256 */
xce_data_t *bytes; /* serialised ClusterConfig blob */
};
struct repl_config_push_reply_s {
int accepted; /* 1 if standby accepted the push */
uint64_t version_tag; /* standby's current version tag after decision */
};
struct upgrade_config_req_s {
xce_data_t *sha256; /* 32-byte SHA-256 of proposed config */
xce_data_t *bytes; /* serialised ClusterConfig blob */
};
struct upgrade_config_reply_s {
uint64_t version_tag; /* new version tag after upgrade */
char *error; /* NULL on success; error message on failure */
uint32_t acked_count; /* number of standbys that acknowledged */
};
struct heartbeat_msg_s {
uint32_t sender_priority; /* sender's HA priority */
uint64_t term; /* sender's current term */
};
#endif