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:
parent
ec3cab40c3
commit
6b06aa02d9
6 changed files with 307 additions and 92 deletions
|
|
@ -23,17 +23,51 @@ int myapp_run(myconf_t* myconf)
|
|||
int rc;
|
||||
|
||||
memset(&c, 0x0, sizeof(c));
|
||||
|
||||
c.myconf = myconf;
|
||||
|
||||
rc = cluster_init(&c);
|
||||
/* Phase 1: pre-config init (hooks, HA priority, standby_endpoints, cbuf) */
|
||||
rc = cluster_init_phase1(&c);
|
||||
if (rc < 0) {
|
||||
SET_ERROR(-rc);
|
||||
|
||||
ERROR("cluster_init: %s", strerror(-rc));
|
||||
|
||||
ERROR("cluster_init_phase1: %s", strerror(-rc));
|
||||
cluster_fini(&c);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* SSL context — created after Phase 1, used by election probing and Phase 2 */
|
||||
initialize_openssl();
|
||||
SSL_CTX* ssl_ctx = create_ssl_context(myconf->certfile, myconf->keyfile);
|
||||
if (!ssl_ctx) {
|
||||
ERROR("create_ssl_context failed");
|
||||
cluster_fini(&c);
|
||||
return -EINVAL;
|
||||
}
|
||||
c.ha.ssl_ctx = ssl_ctx;
|
||||
|
||||
/* Election: determine role before loading config */
|
||||
if (am_i_primary(&c)) {
|
||||
/* Primary: load config from conf/current (FATAL if missing) */
|
||||
rc = load_primary_config(&c);
|
||||
if (rc != 0) {
|
||||
cluster_fini(&c);
|
||||
myconf_fini(myconf);
|
||||
return rc;
|
||||
}
|
||||
} else {
|
||||
/* Standby: fetch config from primary before Phase 2 */
|
||||
rc = fetch_config_from_primary(&c);
|
||||
if (rc != 0) {
|
||||
cluster_fini(&c);
|
||||
myconf_fini(myconf);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
/* Phase 2: full init (requires cluster_config) */
|
||||
rc = cluster_init_phase2(&c);
|
||||
if (rc < 0) {
|
||||
ERROR("cluster_init_phase2: %s", strerror(-rc));
|
||||
cluster_fini(&c);
|
||||
myconf_fini(myconf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
@ -42,13 +76,13 @@ int myapp_run(myconf_t* myconf)
|
|||
SET_ERROR(-rc);
|
||||
perror("cluster_start");
|
||||
cluster_fini(&c);
|
||||
|
||||
myconf_fini(myconf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = cluster_run(&c);
|
||||
|
||||
cluster_fini(&c);
|
||||
|
||||
myconf_fini(myconf);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue