Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sergepetrenko committed May 31, 2023
1 parent 0ef5e3b commit e989395
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
21 changes: 13 additions & 8 deletions src/box/box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ box_check_instance_uuid(struct tt_uuid *uuid)

/** Fetch an optional node name from the config. */
static int
box_check_node_name(const char *cfg_name, char *out)
box_check_node_name(const char *cfg_name, char *out, bool set_diag)
{
const char *name = cfg_gets(cfg_name);
if (name == NULL) {
Expand All @@ -1335,8 +1335,10 @@ box_check_node_name(const char *cfg_name, char *out)
}
/* Nil name is allowed as Lua box.NULL or nil. Not as "". */
if (!node_name_is_valid(name)) {
diag_set(ClientError, ER_CFG, cfg_name,
"expected a valid name");
if (set_diag) {
diag_set(ClientError, ER_CFG, cfg_name,
"expected a valid name");
}
return -1;
}
strlcpy(out, name, NODE_NAME_SIZE_MAX);
Expand All @@ -1346,7 +1348,7 @@ box_check_node_name(const char *cfg_name, char *out)
static int
box_check_instance_name(char *out)
{
return box_check_node_name("instance_name", out);
return box_check_node_name("instance_name", out, true);
}

static int
Expand Down Expand Up @@ -1383,21 +1385,23 @@ box_check_bootstrap_leader(struct uri *uri, struct tt_uuid *uuid)
/* Not a uri. Try uuid then. */
if (box_check_uuid(uuid, "bootstrap_leader", false) == 0)
return 0;
if (box_check_node_name("bootstrap_leader", name, false) == 0)
return 0;
diag_set(ClientError, ER_CFG, "bootstrap_leader",
"the value must be either a uri or a uuid");
"the value must be either a uri, a uuid or a name");
return -1;
}

static int
box_check_replicaset_name(char *out)
{
return box_check_node_name("replicaset_name", out);
return box_check_node_name("replicaset_name", out, true);
}

static int
box_check_cluster_name(char *out)
{
return box_check_node_name("cluster_name", out);
return box_check_node_name("cluster_name", out, true);
}

static enum wal_mode
Expand Down Expand Up @@ -1878,7 +1882,8 @@ static int
box_set_bootstrap_leader(void)
{
return box_check_bootstrap_leader(&cfg_bootstrap_leader_uri,
&cfg_bootstrap_leader_uuid);
&cfg_bootstrap_leader_uuid,
cfg_bootstrap_leader_name);
}

/** Persist this instance as the bootstrap leader in _schema space. */
Expand Down
10 changes: 8 additions & 2 deletions src/box/replication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ int replication_threads = 1;
bool cfg_replication_anon = true;
struct tt_uuid cfg_bootstrap_leader_uuid;
struct uri cfg_bootstrap_leader_uri;
char cfg_bootstrap_leader_name[NODE_NAME_SIZE_MAX];
char cfg_instance_name[NODE_NAME_SIZE_MAX];

struct replicaset replicaset;
Expand Down Expand Up @@ -956,6 +957,10 @@ applier_is_bootstrap_leader(const struct applier *applier)
return uri_addr_is_equal(&applier->uri,
&cfg_bootstrap_leader_uri);
}
if (*cfg_bootstrap_leader_name != '\0') {
return strcmp(applier->ballot.instance_name,
cfg_bootstrap_leader_name);
}
} else if (bootstrap_strategy == BOOTSTRAP_STRATEGY_SUPERVISED) {
return tt_uuid_is_equal(&applier->ballot.bootstrap_leader_uuid,
&applier->uuid);
Expand Down Expand Up @@ -1448,8 +1453,9 @@ replicaset_find_join_master_cfg(void)
if (applier_is_bootstrap_leader(applier))
leader = replica;
}
if (leader == NULL && !tt_uuid_is_equal(&cfg_bootstrap_leader_uuid,
&INSTANCE_UUID)) {
if (leader == NULL &&
strcmp(cfg_bootstrap_leader_name, INSTANCE_NAME) != 0 &&
!tt_uuid_is_equal(&cfg_bootstrap_leader_uuid, &INSTANCE_UUID)) {
tnt_raise(ClientError, ER_CFG, "bootstrap_leader",
"failed to connect to the bootstrap leader");
}
Expand Down
6 changes: 6 additions & 0 deletions src/box/replication.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ extern struct tt_uuid cfg_bootstrap_leader_uuid;
*/
extern struct uri cfg_bootstrap_leader_uri;

/**
* The name of the bootstrap leader configured via the bootstrap_leader
* configuration option.
*/
extern char cfg_botstrap_leader_name[];

/**
* Configured name of this instance. Might be different from the actual name if
* the configuration is not fully applied yet.
Expand Down

0 comments on commit e989395

Please sign in to comment.