Skip to content

Commit

Permalink
replication: broadcast instance name in the ballot
Browse files Browse the repository at this point in the history
Node's ballot contains all the information necessary to choose it a
bootstrap leader. Since the bootstrap_leader configuration option will
allow specifying bootstrap leader's name, we have to broadcast the name
in node's ballot.

Prerequisite tarantool#8539

NO_CHANGELOG=not user-visible

@TarantoolBot document
Title: new field in node's BALLOT: IPROTO_BALLOT_INSTANCE_NAME

The node's ballot (IPROTO_BALLOT) receives a new field:
the name of the node (the same as in box.cfg.instance_name or
box.info.name):
Key: IPROTO_BALLOT_INSTANCE_NAME = 0x0a
Value: MP_STR, representing the instance name.
  • Loading branch information
sergepetrenko committed Jun 2, 2023
1 parent 606e50c commit d1bb24e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/box/box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4426,6 +4426,15 @@ box_process_vote(struct ballot *ballot)
vclock_copy(&ballot->vclock, &replicaset.vclock);
vclock_copy(&ballot->gc_vclock, &gc.vclock);
ballot->bootstrap_leader_uuid = bootstrap_leader_uuid;
if (*INSTANCE_NAME != '\0') {
strlcpy(ballot->instance_name, INSTANCE_NAME,
NODE_NAME_SIZE_MAX);
} else if (*cfg_instance_name != '\0') {
strlcpy(ballot->instance_name, cfg_instance_name,
NODE_NAME_SIZE_MAX);
} else {
*ballot->instance_name = '\0';
}
int i = 0;
replicaset_foreach(replica) {
if (replica->id != 0)
Expand Down
1 change: 1 addition & 0 deletions src/box/iproto_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ extern const char *iproto_metadata_key_strs[];
_(CAN_LEAD, 0x07) \
_(BOOTSTRAP_LEADER_UUID, 0x08) \
_(REGISTERED_REPLICA_UUIDS, 0x09) \
_(INSTANCE_NAME, 0x0a) \

#define IPROTO_BALLOT_KEY_MEMBER(s, v) IPROTO_BALLOT_ ## s = v,

Expand Down
18 changes: 16 additions & 2 deletions src/box/xrow.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ mp_sizeof_ballot_max(const struct ballot *ballot)
{
int registered_uuids_size = ballot->registered_replica_uuids_size;
return mp_sizeof_map(1) + mp_sizeof_uint(IPROTO_BALLOT) +
mp_sizeof_map(9) + mp_sizeof_uint(IPROTO_BALLOT_IS_RO_CFG) +
mp_sizeof_map(10) + mp_sizeof_uint(IPROTO_BALLOT_IS_RO_CFG) +
mp_sizeof_bool(ballot->is_ro_cfg) +
mp_sizeof_uint(IPROTO_BALLOT_IS_RO) +
mp_sizeof_bool(ballot->is_ro) +
Expand All @@ -560,6 +560,8 @@ mp_sizeof_ballot_max(const struct ballot *ballot)
mp_sizeof_bool(ballot->can_lead) +
mp_sizeof_uint(IPROTO_BALLOT_BOOTSTRAP_LEADER_UUID) +
mp_sizeof_str(UUID_STR_LEN) +
mp_sizeof_uint(IPROTO_BALLOT_INSTANCE_NAME) +
mp_sizeof_str(NODE_NAME_LEN_MAX) +
mp_sizeof_uint(IPROTO_BALLOT_REGISTERED_REPLICA_UUIDS) +
mp_sizeof_array(registered_uuids_size) +
registered_uuids_size * mp_sizeof_str(UUID_STR_LEN);
Expand All @@ -571,7 +573,8 @@ mp_encode_ballot(char *data, const struct ballot *ballot)
{
data = mp_encode_map(data, 1);
data = mp_encode_uint(data, IPROTO_BALLOT);
data = mp_encode_map(data, 9);
bool has_name = *ballot->instance_name != '\0';
data = mp_encode_map(data, has_name ? 10 : 9);
data = mp_encode_uint(data, IPROTO_BALLOT_IS_RO_CFG);
data = mp_encode_bool(data, ballot->is_ro_cfg);
data = mp_encode_uint(data, IPROTO_BALLOT_IS_RO);
Expand All @@ -588,6 +591,10 @@ mp_encode_ballot(char *data, const struct ballot *ballot)
data = mp_encode_bool(data, ballot->can_lead);
data = mp_encode_uint(data, IPROTO_BALLOT_BOOTSTRAP_LEADER_UUID);
data = xrow_encode_uuid(data, &ballot->bootstrap_leader_uuid);
if (has_name) {
data = mp_encode_uint(data, IPROTO_BALLOT_INSTANCE_NAME);
data = mp_encode_str0(data, ballot->instance_name);
}
data = mp_encode_uint(data, IPROTO_BALLOT_REGISTERED_REPLICA_UUIDS);
data = mp_encode_array(data, ballot->registered_replica_uuids_size);
for (int i = 0; i < ballot->registered_replica_uuids_size; i++) {
Expand Down Expand Up @@ -1791,6 +1798,7 @@ xrow_decode_ballot(const struct xrow_header *row, struct ballot *ballot)
ballot->is_booted = true;
vclock_create(&ballot->vclock);
vclock_create(&ballot->gc_vclock);
*ballot->instance_name = '\0';

if (row->bodycnt == 0)
goto err;
Expand Down Expand Up @@ -1889,6 +1897,12 @@ mp_decode_ballot(const char *data, const char *end,
*is_empty = false;
break;
}
case IPROTO_BALLOT_INSTANCE_NAME:
if (xrow_decode_node_name(&data,
ballot->instance_name) != 0) {
return -1;
}
break;
case IPROTO_BALLOT_REGISTERED_REPLICA_UUIDS: {
if (mp_typeof(*data) != MP_ARRAY)
return -1;
Expand Down
2 changes: 2 additions & 0 deletions src/box/xrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ struct ballot {
struct vclock gc_vclock;
/** The uuid of the instance this node considers a bootstrap leader. */
struct tt_uuid bootstrap_leader_uuid;
/** The name of this node. */
char instance_name[NODE_NAME_LEN_MAX];
/** Replica uuids registered in the replica set. */
struct tt_uuid registered_replica_uuids[VCLOCK_MAX];
/** Number of replicas registered in the replica set. */
Expand Down
4 changes: 4 additions & 0 deletions test/box-luatest/builtin_events_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,8 @@ g.test_internal_ballot = function(cg)
expected[ballot_key.CAN_LEAD] = true
expected[ballot_key.IS_RO] = true
cg.replica:exec(wait_ballot_updated_to, {expected})
cg.replica:update_box_cfg{instance_name='replica-name'}
expected[ballot_key.INSTANCE_NAME] = 'replica-name'
expected[ballot_key.VCLOCK] = cg.master:get_vclock()
cg.replica:exec(wait_ballot_updated_to, {expected})
end
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ local reference_table = {
CAN_LEAD = 0x07,
BOOTSTRAP_LEADER_UUID = 0x08,
REGISTERED_REPLICA_UUIDS = 0x09,
INSTANCE_NAME = 0x10,
},

-- `iproto_type` enumeration.
Expand Down

0 comments on commit d1bb24e

Please sign in to comment.