- 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
88 lines
2.1 KiB
C
88 lines
2.1 KiB
C
#include <errno.h>
|
|
#include <pthread.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
|
|
#include "cluster.h"
|
|
#include "myconf.h"
|
|
#include "netio.h"
|
|
#include "xce/cluster_def.h"
|
|
|
|
#include "request.h"
|
|
#include "utils.h"
|
|
|
|
time_t last_print_time = 0;
|
|
unsigned long npkts = 0;
|
|
unsigned long npkts_old = 0;
|
|
|
|
int myapp_run(myconf_t* myconf)
|
|
{
|
|
cluster_t c;
|
|
int rc;
|
|
|
|
memset(&c, 0x0, sizeof(c));
|
|
c.myconf = myconf;
|
|
|
|
/* Phase 1: pre-config init (hooks, HA priority, standby_endpoints, cbuf) */
|
|
rc = cluster_init_phase1(&c);
|
|
if (rc < 0) {
|
|
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;
|
|
}
|
|
|
|
rc = cluster_start(&c);
|
|
if (rc < 0) {
|
|
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;
|
|
}
|