Skip to content

Commit 3c91ad5

Browse files
committed
replication: broadcast instance name in the ballot
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.
1 parent 116df1d commit 3c91ad5

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed

src/box/box.cc

+9
Original file line numberDiff line numberDiff line change
@@ -4426,6 +4426,15 @@ box_process_vote(struct ballot *ballot)
44264426
vclock_copy(&ballot->vclock, &replicaset.vclock);
44274427
vclock_copy(&ballot->gc_vclock, &gc.vclock);
44284428
ballot->bootstrap_leader_uuid = bootstrap_leader_uuid;
4429+
if (*INSTANCE_NAME != '\0') {
4430+
strlcpy(ballot->instance_name, INSTANCE_NAME,
4431+
NODE_NAME_SIZE_MAX);
4432+
} else if (*cfg_instance_name != '\0') {
4433+
strlcpy(ballot->instance_name, cfg_instance_name,
4434+
NODE_NAME_SIZE_MAX);
4435+
} else {
4436+
*ballot->instance_name = '\0';
4437+
}
44294438
int i = 0;
44304439
replicaset_foreach(replica) {
44314440
if (replica->id != 0)

src/box/iproto_constants.h

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ extern const char *iproto_metadata_key_strs[];
263263
_(CAN_LEAD, 0x07) \
264264
_(BOOTSTRAP_LEADER_UUID, 0x08) \
265265
_(REGISTERED_REPLICA_UUIDS, 0x09) \
266+
_(INSTANCE_NAME, 0x0a) \
266267

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

src/box/xrow.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ mp_sizeof_ballot_max(const struct ballot *ballot)
544544
{
545545
int registered_uuids_size = ballot->registered_replica_uuids_size;
546546
return mp_sizeof_map(1) + mp_sizeof_uint(IPROTO_BALLOT) +
547-
mp_sizeof_map(9) + mp_sizeof_uint(IPROTO_BALLOT_IS_RO_CFG) +
547+
mp_sizeof_map(10) + mp_sizeof_uint(IPROTO_BALLOT_IS_RO_CFG) +
548548
mp_sizeof_bool(ballot->is_ro_cfg) +
549549
mp_sizeof_uint(IPROTO_BALLOT_IS_RO) +
550550
mp_sizeof_bool(ballot->is_ro) +
@@ -560,6 +560,8 @@ mp_sizeof_ballot_max(const struct ballot *ballot)
560560
mp_sizeof_bool(ballot->can_lead) +
561561
mp_sizeof_uint(IPROTO_BALLOT_BOOTSTRAP_LEADER_UUID) +
562562
mp_sizeof_str(UUID_STR_LEN) +
563+
mp_sizeof_uint(IPROTO_BALLOT_INSTANCE_NAME) +
564+
mp_sizeof_str(NODE_NAME_LEN_MAX) +
563565
mp_sizeof_uint(IPROTO_BALLOT_REGISTERED_REPLICA_UUIDS) +
564566
mp_sizeof_array(registered_uuids_size) +
565567
registered_uuids_size * mp_sizeof_str(UUID_STR_LEN);
@@ -571,7 +573,8 @@ mp_encode_ballot(char *data, const struct ballot *ballot)
571573
{
572574
data = mp_encode_map(data, 1);
573575
data = mp_encode_uint(data, IPROTO_BALLOT);
574-
data = mp_encode_map(data, 9);
576+
bool has_name = *ballot->instance_name != '\0';
577+
data = mp_encode_map(data, has_name ? 10 : 9);
575578
data = mp_encode_uint(data, IPROTO_BALLOT_IS_RO_CFG);
576579
data = mp_encode_bool(data, ballot->is_ro_cfg);
577580
data = mp_encode_uint(data, IPROTO_BALLOT_IS_RO);
@@ -588,6 +591,10 @@ mp_encode_ballot(char *data, const struct ballot *ballot)
588591
data = mp_encode_bool(data, ballot->can_lead);
589592
data = mp_encode_uint(data, IPROTO_BALLOT_BOOTSTRAP_LEADER_UUID);
590593
data = xrow_encode_uuid(data, &ballot->bootstrap_leader_uuid);
594+
if (has_name) {
595+
data = mp_encode_uint(data, IPROTO_BALLOT_INSTANCE_NAME);
596+
data = mp_encode_str0(data, ballot->instance_name);
597+
}
591598
data = mp_encode_uint(data, IPROTO_BALLOT_REGISTERED_REPLICA_UUIDS);
592599
data = mp_encode_array(data, ballot->registered_replica_uuids_size);
593600
for (int i = 0; i < ballot->registered_replica_uuids_size; i++) {
@@ -1791,6 +1798,7 @@ xrow_decode_ballot(const struct xrow_header *row, struct ballot *ballot)
17911798
ballot->is_booted = true;
17921799
vclock_create(&ballot->vclock);
17931800
vclock_create(&ballot->gc_vclock);
1801+
*ballot->instance_name = '\0';
17941802

17951803
if (row->bodycnt == 0)
17961804
goto err;
@@ -1889,6 +1897,12 @@ mp_decode_ballot(const char *data, const char *end,
18891897
*is_empty = false;
18901898
break;
18911899
}
1900+
case IPROTO_BALLOT_INSTANCE_NAME:
1901+
if (xrow_decode_node_name(&data,
1902+
ballot->instance_name) != 0) {
1903+
return -1;
1904+
}
1905+
break;
18921906
case IPROTO_BALLOT_REGISTERED_REPLICA_UUIDS: {
18931907
if (mp_typeof(*data) != MP_ARRAY)
18941908
return -1;

src/box/xrow.h

+2
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ struct ballot {
509509
struct vclock gc_vclock;
510510
/** The uuid of the instance this node considers a bootstrap leader. */
511511
struct tt_uuid bootstrap_leader_uuid;
512+
/** The name of this node. */
513+
char instance_name[NODE_NAME_SIZE_MAX];
512514
/** Replica uuids registered in the replica set. */
513515
struct tt_uuid registered_replica_uuids[VCLOCK_MAX];
514516
/** Number of replicas registered in the replica set. */

test/box-luatest/builtin_events_test.lua

+4
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,8 @@ g.test_internal_ballot = function(cg)
414414
expected[ballot_key.CAN_LEAD] = true
415415
expected[ballot_key.IS_RO] = true
416416
cg.replica:exec(wait_ballot_updated_to, {expected})
417+
cg.replica:update_box_cfg{instance_name='replica-name'}
418+
expected[ballot_key.INSTANCE_NAME] = 'replica-name'
419+
expected[ballot_key.VCLOCK] = cg.master:get_vclock()
420+
cg.replica:exec(wait_ballot_updated_to, {expected})
417421
end

test/box-luatest/gh_7894_export_iproto_constants_and_features_test.lua

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ local reference_table = {
107107
CAN_LEAD = 0x07,
108108
BOOTSTRAP_LEADER_UUID = 0x08,
109109
REGISTERED_REPLICA_UUIDS = 0x09,
110+
INSTANCE_NAME = 0x0a,
110111
},
111112

112113
-- `iproto_type` enumeration.

0 commit comments

Comments
 (0)