feat: add --peers to controller for HA peer list and priority election
- myconf_t gains peers_cfg (xce_cluster_config_t) populated from --peers - controller/main.c: parse --peers host:port,... via argp; ca_cert_path auto-derived from workdir/certs/xce.crt (no --ca-cert flag needed) - cluster_init: derive my_priority from position in peers list (index 0 = primary); fall back to 0 when --peers not given (single-node mode)
This commit is contained in:
parent
d61f91b99c
commit
59597e105e
10 changed files with 8046 additions and 325 deletions
|
|
@ -640,8 +640,28 @@ int cluster_init(cluster_t* c)
|
|||
.probe_connect_timeout_ms = HA_DEFAULT_PROBE_CONNECT_TIMEOUT_MS,
|
||||
.max_promotion_retries = HA_DEFAULT_MAX_PROMOTION_RETRIES,
|
||||
};
|
||||
/* my_priority: single-node P1 always uses 0 (highest priority) */
|
||||
rc = ha_init(&c->ha, &ha_cfg, 0);
|
||||
|
||||
/* Derive priority from position in --peers list.
|
||||
* Index 0 = highest priority (becomes primary on startup).
|
||||
* If the controller's name is not found in the list, fall back to
|
||||
* the last index (lowest priority = standby). */
|
||||
int my_priority = 0;
|
||||
const xce_cluster_config_t* pcfg = &c->myconf->peers_cfg;
|
||||
if (pcfg->candidates_count > 0) {
|
||||
my_priority = pcfg->candidates_count - 1; /* default: last = lowest */
|
||||
for (int i = 0; i < pcfg->candidates_count; i++) {
|
||||
if (strncmp(pcfg->candidates[i].hostname,
|
||||
c->myconf->name,
|
||||
XCE_MAXHOSTNAME_LEN - 1) == 0) {
|
||||
my_priority = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
INFO("HA peers: %d candidates, my_priority=%d (name=%s)",
|
||||
pcfg->candidates_count, my_priority, c->myconf->name);
|
||||
}
|
||||
|
||||
rc = ha_init(&c->ha, &ha_cfg, my_priority);
|
||||
if (rc != 0) {
|
||||
ERROR("ha_init failed: %d", rc);
|
||||
persist_fini(&c->persist);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue