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

@ -166,7 +166,7 @@ int load_primary_config(cluster_t *c)
char fname[256] = {0};
int rc = conf_read_current_filename(conf_dir, fname, sizeof(fname));
if (rc != 0) {
FATAL("Primary has no config at '%s/conf/current' (rc=%d) — "
ERROR("Primary has no config at '%s/conf/current' (rc=%d) — "
"provision the config before starting",
conf_dir, rc);
return -ENOENT;
@ -183,7 +183,7 @@ int load_primary_config(cluster_t *c)
size_t blen = 0;
rc = conf_read_raw(myconf->conffile, &bytes, &blen);
if (rc != 0) {
FATAL("Primary config '%s' unreadable: %d", myconf->conffile, rc);
ERROR("Primary config '%s' unreadable: %d", myconf->conffile, rc);
free(myconf->conffile);
myconf->conffile = NULL;
return rc;
@ -205,7 +205,7 @@ int load_primary_config(cluster_t *c)
/* Decode Cap'n Proto directly into myconf->cluster_config */
rc = load_cluster_config_from_file(myconf->conffile, &myconf->cluster_config);
if (rc != 0) {
FATAL("Primary config '%s' failed Cap'n Proto decode: %d",
ERROR("Primary config '%s' failed Cap'n Proto decode: %d",
myconf->conffile, rc);
free(bytes);
free(myconf->conffile);
@ -214,7 +214,7 @@ int load_primary_config(cluster_t *c)
}
if (myconf->cluster_config == NULL) {
FATAL("Primary config '%s' decoded to NULL", myconf->conffile);
ERROR("Primary config '%s' decoded to NULL", myconf->conffile);
free(bytes);
free(myconf->conffile);
myconf->conffile = NULL;
@ -227,7 +227,7 @@ int load_primary_config(cluster_t *c)
/* Check for reserved lost_and_found name */
if (config_contains_reserved_name(myconf->cluster_config)) {
FATAL("Config '%s' contains reserved name 'lost_and_found'",
ERROR("Config '%s' contains reserved name 'lost_and_found'",
myconf->conffile);
free_ClusterConfig(myconf->cluster_config);
free(myconf->cluster_config);
@ -253,6 +253,18 @@ int load_primary_config(cluster_t *c)
return 0;
}
/* ── fetch_config_from_primary ──────────────────── */
int fetch_config_from_primary(cluster_t *c)
{
(void)c;
/* Task 9: full implementation — connect to primary, send OP_replConfig,
* receive blob, verify SHA-256, call conf_save_config(), decode into
* myconf->cluster_config. */
ERROR("fetch_config_from_primary: not yet implemented (Task 9)");
return -ENOSYS;
}
/* ── myconf_fini ────────────────────────────────── */
void myconf_fini(myconf_t *myconf)