feat(controller-peers-env-fallback): route the controller's two identity loops through the shared lookup (task 2.1)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
241ed3a142
commit
7a90af089c
3 changed files with 145 additions and 22 deletions
|
|
@ -1780,16 +1780,9 @@ int cluster_init_phase1(cluster_t* c)
|
|||
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++) {
|
||||
const char* key = pcfg->candidates[i].name[0]
|
||||
? pcfg->candidates[i].name
|
||||
: pcfg->candidates[i].hostname;
|
||||
if (strncmp(key, c->myconf->name, XCE_MAXNAME_LEN - 1) == 0) {
|
||||
my_priority = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* No match: last index = lowest priority. */
|
||||
int idx = xce_peers_find_identity(pcfg, c->myconf->name);
|
||||
my_priority = idx >= 0 ? idx : pcfg->candidates_count - 1;
|
||||
INFO("HA peers: %d candidates, my_priority=%d (name=%s)",
|
||||
pcfg->candidates_count, my_priority, c->myconf->name);
|
||||
}
|
||||
|
|
@ -1873,7 +1866,8 @@ int cluster_open_listener(cluster_t* c)
|
|||
return 0;
|
||||
|
||||
/* Determine listen port:
|
||||
* 1. Search --peers candidates for the local name.
|
||||
* 1. Look up the local name among the --peers candidates
|
||||
* (xce_peers_find_identity()).
|
||||
* - Matched with a nonzero port: bind to it (unchanged happy
|
||||
* path; also how a single-node operator gets a custom port,
|
||||
* via a single self-referencing --peers entry).
|
||||
|
|
@ -1889,16 +1883,9 @@ int cluster_open_listener(cluster_t* c)
|
|||
bool matched = false;
|
||||
{
|
||||
const xce_cluster_config_t* pcfg = &c->myconf->peers_cfg;
|
||||
for (int j = 0; j < pcfg->candidates_count; j++) {
|
||||
const char* key = pcfg->candidates[j].name[0]
|
||||
? pcfg->candidates[j].name
|
||||
: pcfg->candidates[j].hostname;
|
||||
if (strncmp(key, c->myconf->name, XCE_MAXNAME_LEN - 1) == 0) {
|
||||
my_port = pcfg->candidates[j].port;
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int idx = xce_peers_find_identity(pcfg, c->myconf->name);
|
||||
matched = idx >= 0;
|
||||
my_port = matched ? (uint32_t)pcfg->candidates[idx].port : 0;
|
||||
|
||||
if (!matched && pcfg->candidates_count > 0) {
|
||||
ERROR("cluster_open_listener: local name '%s' not found in "
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue