[Tarantool-patches] [PATCH 1/6] replication: refactor replicaset_leader()
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Sat Jun 5 02:37:55 MSK 2021
Firstly, rename it to replicaset_find_join_master(). Now, when
there is Raft with a concept of an actual leader, the function
name becomes confusing.
Secondly, do not access ballot member in struct applier in such a
long way - save the ballot pointer on the stack. This is going to
become useful when in one of the next patches the ballot will be
used more.
Part of #5613
---
src/box/box.cc | 5 ++---
src/box/replication.cc | 12 +++++++-----
src/box/replication.h | 5 +++--
3 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/box/box.cc b/src/box/box.cc
index 6dc991dc8..0e615e944 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -1369,7 +1369,7 @@ box_set_replication_anon(void)
* Wait until the master has registered this
* instance.
*/
- struct replica *master = replicaset_leader();
+ struct replica *master = replicaset_find_join_master();
if (master == NULL || master->applier == NULL ||
master->applier->state != APPLIER_CONNECTED) {
tnt_raise(ClientError, ER_CANNOT_REGISTER);
@@ -3114,8 +3114,7 @@ bootstrap(const struct tt_uuid *instance_uuid,
*/
box_sync_replication(true);
- /* Use the first replica by URI as a bootstrap leader */
- struct replica *master = replicaset_leader();
+ struct replica *master = replicaset_find_join_master();
assert(master == NULL || master->applier != NULL);
if (master != NULL && !tt_uuid_is_equal(&master->uuid, &INSTANCE_UUID)) {
diff --git a/src/box/replication.cc b/src/box/replication.cc
index aefb812b3..a1c6e3c7c 100644
--- a/src/box/replication.cc
+++ b/src/box/replication.cc
@@ -968,6 +968,7 @@ replicaset_round(bool skip_ro)
struct applier *applier = replica->applier;
if (applier == NULL)
continue;
+ const struct ballot *ballot = &applier->ballot;
/**
* While bootstrapping a new cluster, read-only
* replicas shouldn't be considered as a leader.
@@ -975,17 +976,18 @@ replicaset_round(bool skip_ro)
* replicas since there is still a possibility
* that all replicas exist in cluster table.
*/
- if (skip_ro && applier->ballot.is_ro)
+ if (skip_ro && ballot->is_ro)
continue;
if (leader == NULL) {
leader = replica;
continue;
}
+ const struct ballot *leader_ballot = &leader->applier->ballot;
/*
* Try to find a replica which has already left
* orphan mode.
*/
- if (applier->ballot.is_loading && ! leader->applier->ballot.is_loading)
+ if (ballot->is_loading && !leader_ballot->is_loading)
continue;
/*
* Choose the replica with the most advanced
@@ -993,8 +995,8 @@ replicaset_round(bool skip_ro)
* with the same vclock, prefer the one with
* the lowest uuid.
*/
- int cmp = vclock_compare_ignore0(&applier->ballot.vclock,
- &leader->applier->ballot.vclock);
+ int cmp = vclock_compare_ignore0(&ballot->vclock,
+ &leader_ballot->vclock);
if (cmp < 0)
continue;
if (cmp == 0 && tt_uuid_compare(&replica->uuid,
@@ -1006,7 +1008,7 @@ replicaset_round(bool skip_ro)
}
struct replica *
-replicaset_leader(void)
+replicaset_find_join_master(void)
{
bool skip_ro = true;
/**
diff --git a/src/box/replication.h b/src/box/replication.h
index 2ad1cbf66..5cc380373 100644
--- a/src/box/replication.h
+++ b/src/box/replication.h
@@ -356,10 +356,11 @@ struct replica *
replica_by_id(uint32_t replica_id);
/**
- * Return the replica set leader.
+ * Find a node in the replicaset on which the instance can try to register to
+ * join the replicaset.
*/
struct replica *
-replicaset_leader(void);
+replicaset_find_join_master(void);
struct replica *
replicaset_first(void);
--
2.24.3 (Apple Git-128)
More information about the Tarantool-patches
mailing list