feat(controller-peers-env-fallback): fall back to XCE_CONTROLLER_PEERS in the scheduler (task 3.1)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
9018980b08
commit
55193fcb4b
3 changed files with 187 additions and 14 deletions
|
|
@ -85,7 +85,12 @@ struct arguments {
|
|||
static struct argp_option options[] = {
|
||||
{ "logfile", 'l', "FILE", 0, "The full path of log file" },
|
||||
{ "verbose", 'v', 0, 0, "Produce verbose log" },
|
||||
{ "peers", 'P', "LIST", 0, "HA candidate list: [name=]host:port,..." },
|
||||
{ "peers", 'P', "LIST", 0,
|
||||
"HA candidate list: [name=]host:port,... When omitted, the "
|
||||
"XCE_CONTROLLER_PEERS environment variable (same format) is used "
|
||||
"instead; with that variable unset or empty the scheduler takes the "
|
||||
"single-controller path, so unset or empty it for one invocation to "
|
||||
"opt out (e.g. XCE_CONTROLLER_PEERS= xce_scheduler ...)." },
|
||||
/* Req 5 AC 9 "Mode selection" / Req 5 AC 13 "Simulation mode startup"
|
||||
* (scheduler-core spec, tasks 5.2/11.1): --sim FILE selects the
|
||||
* simulation driver; the flags below configure it. */
|
||||
|
|
@ -407,32 +412,52 @@ int main(int argc, char* argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* P2.5-6: populate and validate xce_cluster_config_t when --peers given */
|
||||
if (arguments.peers) {
|
||||
if (xce_parse_peers(arguments.peers, &cluster_cfg) != 0) {
|
||||
/* P2.5-6: populate and validate xce_cluster_config_t when a candidate
|
||||
* list is given. controller-peers-env-fallback Req 1.1-1.3, 1.7: an
|
||||
* explicit --peers wins; otherwise a non-empty XCE_CONTROLLER_PEERS
|
||||
* supplies the list (unset or empty = single-controller path).
|
||||
* peers_src names where the list came from in every message about it
|
||||
* (Req 1.4). */
|
||||
const char* peers_str = arguments.peers;
|
||||
int peers_from_env = 0;
|
||||
if (peers_str == NULL) {
|
||||
peers_str = xce_controller_peers_env();
|
||||
peers_from_env = (peers_str != NULL);
|
||||
}
|
||||
const char* peers_src = peers_from_env ? "XCE_CONTROLLER_PEERS" : "--peers";
|
||||
|
||||
if (peers_str) {
|
||||
if (xce_parse_peers(peers_str, &cluster_cfg) != 0) {
|
||||
fprintf(stderr,
|
||||
"xce_scheduler: --peers parse error: expected "
|
||||
"xce_scheduler: %s parse error: expected "
|
||||
"\"[name=]host:port,...\" got \"%s\"\n",
|
||||
arguments.peers);
|
||||
peers_src, peers_str);
|
||||
return 1;
|
||||
}
|
||||
strncpy(cluster_cfg.identity, "xce_scheduler",
|
||||
sizeof(cluster_cfg.identity) - 1);
|
||||
if (xce_cluster_config_validate(&cluster_cfg) != 0) {
|
||||
fprintf(stderr, "xce_scheduler: invalid cluster config (missing "
|
||||
"identity?).\n");
|
||||
fprintf(stderr,
|
||||
"xce_scheduler: %s: invalid cluster config (empty host "
|
||||
"or port 0?) in \"%s\"\n",
|
||||
peers_src, peers_str);
|
||||
return 1;
|
||||
}
|
||||
if (cluster_cfg.candidates_count > N_MAX_MASTERS) {
|
||||
WARN("xce_scheduler: --peers has %d candidates; "
|
||||
WARN("xce_scheduler: %s has %d candidates; "
|
||||
"only <=%d validated for HA",
|
||||
cluster_cfg.candidates_count, N_MAX_MASTERS);
|
||||
peers_src, cluster_cfg.candidates_count, N_MAX_MASTERS);
|
||||
}
|
||||
INFO("HA cluster config: %d candidate(s), identity=%s, version %s",
|
||||
cluster_cfg.candidates_count, cluster_cfg.identity, version_buf);
|
||||
/* The version stays last on the line: the version-consistency
|
||||
* scripts read everything after its prefix as the build time. */
|
||||
INFO("HA cluster config: %d candidate(s), identity=%s%s, version %s",
|
||||
cluster_cfg.candidates_count, cluster_cfg.identity,
|
||||
peers_from_env ? " (from XCE_CONTROLLER_PEERS)" : "",
|
||||
version_buf);
|
||||
cluster_cfg_ptr = &cluster_cfg;
|
||||
} else {
|
||||
INFO("No --peers flag; using single-controller path, version %s",
|
||||
INFO("No --peers flag and XCE_CONTROLLER_PEERS unset or empty; "
|
||||
"using single-controller path, version %s",
|
||||
version_buf);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue