From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergepetrenko@tarantool.org Subject: [Tarantool-patches] [PATCH 1/6] replication: refactor replicaset_leader() Date: Sat, 5 Jun 2021 01:37:55 +0200 [thread overview] Message-ID: <751c1367a94e87118a1699579af71af43ee3624d.1622849790.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1622849790.git.v.shpilevoy@tarantool.org> 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)
next prev parent reply other threads:[~2021-06-04 23:38 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-06-04 23:37 [Tarantool-patches] [PATCH 0/6] Instance join should prefer booted instances Vladislav Shpilevoy via Tarantool-patches 2021-06-04 23:37 ` Vladislav Shpilevoy via Tarantool-patches [this message] 2021-06-10 13:54 ` [Tarantool-patches] [PATCH 1/6] replication: refactor replicaset_leader() Serge Petrenko via Tarantool-patches 2021-06-04 23:37 ` [Tarantool-patches] [PATCH 2/6] replication: ballot.is_ro -> is_ro_cfg Vladislav Shpilevoy via Tarantool-patches 2021-06-10 13:56 ` Serge Petrenko via Tarantool-patches 2021-06-04 23:37 ` [Tarantool-patches] [PATCH 3/6] replication: ballot.is_loading -> is_ro Vladislav Shpilevoy via Tarantool-patches 2021-06-10 13:58 ` Serge Petrenko via Tarantool-patches 2021-06-04 23:37 ` [Tarantool-patches] [PATCH 4/6] replication: introduce ballot.is_booted Vladislav Shpilevoy via Tarantool-patches 2021-06-10 14:02 ` Serge Petrenko via Tarantool-patches 2021-06-04 23:37 ` [Tarantool-patches] [PATCH 5/6] replication: use 'score' to find a join-master Vladislav Shpilevoy via Tarantool-patches 2021-06-10 14:06 ` Serge Petrenko via Tarantool-patches 2021-06-10 15:02 ` Cyrill Gorcunov via Tarantool-patches 2021-06-10 20:09 ` Vladislav Shpilevoy via Tarantool-patches 2021-06-10 21:28 ` Cyrill Gorcunov via Tarantool-patches 2021-06-04 23:38 ` [Tarantool-patches] [PATCH 6/6] replication: prefer to join from booted replicas Vladislav Shpilevoy via Tarantool-patches 2021-06-06 17:06 ` Vladislav Shpilevoy via Tarantool-patches 2021-06-10 14:14 ` Serge Petrenko via Tarantool-patches 2021-06-06 17:03 ` [Tarantool-patches] [PATCH 7/6] raft: test join to a raft cluster Vladislav Shpilevoy via Tarantool-patches 2021-06-06 23:01 ` Vladislav Shpilevoy via Tarantool-patches 2021-06-10 14:17 ` Serge Petrenko via Tarantool-patches 2021-06-10 15:03 ` [Tarantool-patches] [PATCH 0/6] Instance join should prefer booted instances Cyrill Gorcunov via Tarantool-patches 2021-06-11 20:56 ` Vladislav Shpilevoy via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=751c1367a94e87118a1699579af71af43ee3624d.1622849790.git.v.shpilevoy@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=gorcunov@gmail.com \ --cc=sergepetrenko@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 1/6] replication: refactor replicaset_leader()' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox