feat(component-failover-adoption): add candidate-list-to-client-config helper
xce_cluster_config_to_client_config() converts a validated candidate list into a fully-populated xce_client_config_t, copying candidates in order with no special-casing for a single candidate. The truncate-with-warning safety net stays in place as a defensive guard now that N_MAX_MASTERS and MAX_HA_CANDIDATES match. Also removes a WARN check in xce_cluster_config_validate() that became unreachable dead code once task 1.1 reconciled the two candidate-count constants (both checks tested the same field against the same constant with no mutation between them). Task 1.2 of component-failover-adoption (Requirement 1 AC1-AC7).
This commit is contained in:
parent
fe8b4b86bf
commit
210faa2b7a
4 changed files with 190 additions and 5 deletions
|
|
@ -96,10 +96,40 @@ int xce_cluster_config_validate(const xce_cluster_config_t* cfg)
|
|||
}
|
||||
if (cfg->identity[0] == '\0')
|
||||
return -EINVAL;
|
||||
if (cfg->candidates_count > 3)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ── Config conversion ─────────────────────────────────────────── */
|
||||
|
||||
/* Mirrors xce_test's inline masters-array population at
|
||||
* src/controller/testsuite/test.c:360-372, generalized into a reusable
|
||||
* function. out->masters[i] are pointers into cfg->candidates[i].hostname,
|
||||
* not copies -- same non-owning-storage contract xce_test already relies on
|
||||
* (see that file's comment on master_cfg's static lifetime), so the caller
|
||||
* must keep cfg alive at least as long as out is in use. */
|
||||
int xce_cluster_config_to_client_config(const xce_cluster_config_t* cfg,
|
||||
xce_client_config_t* out)
|
||||
{
|
||||
if (!cfg || !out)
|
||||
return -EINVAL;
|
||||
if (cfg->candidates_count < 1)
|
||||
return -EINVAL;
|
||||
|
||||
int count = cfg->candidates_count;
|
||||
if (count > N_MAX_MASTERS) {
|
||||
fprintf(stderr,
|
||||
"WARN: HA cluster has %d candidates; validated for <=3 only\n",
|
||||
cfg->candidates_count);
|
||||
"WARN: HA cluster has %d candidates; using first %d "
|
||||
"(N_MAX_MASTERS)\n",
|
||||
count, N_MAX_MASTERS);
|
||||
count = N_MAX_MASTERS;
|
||||
}
|
||||
|
||||
out->nmasters = count;
|
||||
for (int i = 0; i < count; i++) {
|
||||
out->masters[i] = (char*)cfg->candidates[i].hostname;
|
||||
out->master_ports[i] = cfg->candidates[i].port;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue