feat: support name=host:port format in controller --peers
- xce_candidate_t gains name[] field for logical peer identity - parse_peers stores name prefix before '=' (empty when omitted) - cluster_init matches own identity by name first, hostname as fallback enabling multiple controllers on the same dev host via --peers ctrl-1=10.0.1.1:7000,ctrl-2=10.0.1.2:7001
This commit is contained in:
parent
59597e105e
commit
a05c9bd344
3 changed files with 23 additions and 8 deletions
|
|
@ -650,9 +650,13 @@ int cluster_init(cluster_t* c)
|
||||||
if (pcfg->candidates_count > 0) {
|
if (pcfg->candidates_count > 0) {
|
||||||
my_priority = pcfg->candidates_count - 1; /* default: last = lowest */
|
my_priority = pcfg->candidates_count - 1; /* default: last = lowest */
|
||||||
for (int i = 0; i < pcfg->candidates_count; i++) {
|
for (int i = 0; i < pcfg->candidates_count; i++) {
|
||||||
if (strncmp(pcfg->candidates[i].hostname,
|
/* Match by logical name first (supports multiple controllers
|
||||||
c->myconf->name,
|
* on the same dev host via name=host:port syntax). Fall back
|
||||||
XCE_MAXHOSTNAME_LEN - 1) == 0) {
|
* to hostname match when no name was specified. */
|
||||||
|
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;
|
my_priority = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,10 +60,17 @@ static int parse_peers(const char* peers_str, xce_cluster_config_t* cfg)
|
||||||
if (!colon)
|
if (!colon)
|
||||||
return -1;
|
return -1;
|
||||||
*colon = '\0';
|
*colon = '\0';
|
||||||
strncpy(cfg->candidates[cfg->candidates_count].hostname, addr,
|
xce_candidate_t* cand = &cfg->candidates[cfg->candidates_count];
|
||||||
XCE_MAXHOSTNAME_LEN - 1);
|
if (eq) {
|
||||||
cfg->candidates[cfg->candidates_count].hostname[XCE_MAXHOSTNAME_LEN - 1] = '\0';
|
*eq = '\0';
|
||||||
cfg->candidates[cfg->candidates_count].port = atoi(colon + 1);
|
strncpy(cand->name, tok, XCE_MAXNAME_LEN - 1);
|
||||||
|
cand->name[XCE_MAXNAME_LEN - 1] = '\0';
|
||||||
|
} else {
|
||||||
|
cand->name[0] = '\0';
|
||||||
|
}
|
||||||
|
strncpy(cand->hostname, addr, XCE_MAXHOSTNAME_LEN - 1);
|
||||||
|
cand->hostname[XCE_MAXHOSTNAME_LEN - 1] = '\0';
|
||||||
|
cand->port = atoi(colon + 1);
|
||||||
cfg->candidates_count++;
|
cfg->candidates_count++;
|
||||||
tok = strtok_r(NULL, ",", &saveptr);
|
tok = strtok_r(NULL, ",", &saveptr);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,13 @@
|
||||||
#include "config.h" /* MAX_HA_CANDIDATES, XCE_MAXHOSTNAME_LEN */
|
#include "config.h" /* MAX_HA_CANDIDATES, XCE_MAXHOSTNAME_LEN */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A single controller candidate (host + port).
|
* A single controller candidate.
|
||||||
|
* name: logical name from "name=host:port" syntax (empty if omitted).
|
||||||
|
* Matching against myconf->name allows multiple controllers on the same
|
||||||
|
* dev host to distinguish themselves by name rather than IP address.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
char name[XCE_MAXNAME_LEN];
|
||||||
char hostname[XCE_MAXHOSTNAME_LEN];
|
char hostname[XCE_MAXHOSTNAME_LEN];
|
||||||
int port;
|
int port;
|
||||||
} xce_candidate_t;
|
} xce_candidate_t;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue