feat: split cluster_init() into phase1/phase2; update myapp_run() for two-phase startup with am_i_primary gating

- cluster_init_phase1(): hooks, HA init (priority from --peers), standby_endpoints zarray, cbuf
- cluster_init_phase2(): SSL ctx from ha.ssl_ctx, cluster_config guard, kvmgr sizing, iomgr, endpoint, persist, role promotion, create_lost_and_found, persist_recover
- cluster_init(): legacy wrapper calling both phases with inline SSL init for backward compat
- myapp_run(): phase1 → SSL init → am_i_primary → load_primary_config/fetch_config_from_primary → phase2 → start → run
- myreq_handler(): add OPCode_replConfig and OPCode_upgradeConfig dispatch
- handle_endpoint_error(): prune standby_endpoints on HostRole_controller disconnect
- cluster_run(): log restart_requested on exit
- config_repl.c: add create_lost_and_found, handle_config_request, handle_upgrade_config stubs
- config_repl.h: add declarations for new stubs; include netio.h + request.h
- cluster.h: declare cluster_init_phase1 and cluster_init_phase2
- myconf.c: fix FATAL → ERROR (FATAL macro undefined); add fetch_config_from_primary stub
This commit is contained in:
Rongsong Shen 2026-05-13 17:06:45 +00:00
parent ec3cab40c3
commit 6b06aa02d9
6 changed files with 307 additions and 92 deletions

View file

@ -7,6 +7,8 @@
#include "myconf.h"
#include "clusterconfig.h"
#include "netio.h"
#include "request.h"
/* Max config blob size — reject before allocating */
#define CONF_MAX_SIZE (1 * 1024 * 1024) /* 1 MiB */
@ -84,6 +86,26 @@ void conf_trim_old_versions(const char *workdir, int keep_n);
*/
int config_contains_reserved_name(cluster_config_t *cfg);
/*
* create_lost_and_found: ensure the synthetic "lost_and_found" queue and
* host exist before persist_recover() runs. Stub for Task 10.
*/
void create_lost_and_found(cluster_t *c);
/*
* handle_config_request: handle an OP_replConfig request from a standby.
* Reads the current versioned config blob and sends it back.
* Stub for Task 8 (full implementation in Task 9).
*/
int handle_config_request(cluster_t *c, endpoint_t *ep, xce_request_t *req);
/*
* handle_upgrade_config: handle an OP_upgradeConfig request from an admin tool.
* Validates, stores, and fans out the new config blob; triggers restart.
* Stub for Task 9. Only callable when CONF_ENABLE_UPGRADE_CONFIG is set.
*/
int handle_upgrade_config(cluster_t *c, endpoint_t *ep, xce_request_t *req);
/*
* sanitise_cn: copy at most maxlen printable ASCII chars from src to a
* static buffer, replacing non-printable/control chars with '?'.