From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 7247D6EC55; Thu, 10 Jun 2021 16:54:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7247D6EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1623333263; bh=xjCgueSoULf6Rr9HdKqeP2orLipZ4NkxZ1MotvhzCnI=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fUGoHjMMBCrFCLQM/wq7/0azA+7SP/5GkbyiY+kab9EXaTBl7LJa4fpPz8V+2t8mQ Ounr0Bwl6w11V8VDua/SawwIucoSkMNBnwqiY6Mvy+jBa7dCQSroHq3rmdLA3UxWDi 6HdgDZDeJtUSQxpq5q7ddT4v/Cs0oQYHG6tGenTw= Received: from smtp53.i.mail.ru (smtp53.i.mail.ru [94.100.177.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 4D5FE6EC55 for ; Thu, 10 Jun 2021 16:54:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4D5FE6EC55 Received: by smtp53.i.mail.ru with esmtpa (envelope-from ) id 1lrL8V-0006jC-KF; Thu, 10 Jun 2021 16:54:20 +0300 To: Vladislav Shpilevoy , tarantool-patches@dev.tarantool.org, gorcunov@gmail.com References: <751c1367a94e87118a1699579af71af43ee3624d.1622849790.git.v.shpilevoy@tarantool.org> Message-ID: <265eb7c3-4681-4bcd-5dff-fd3cb73b10e9@tarantool.org> Date: Thu, 10 Jun 2021 16:54:19 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <751c1367a94e87118a1699579af71af43ee3624d.1622849790.git.v.shpilevoy@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9D5B0DA836B685C549A9F97C297FFF2C725C7934AD8E7B4B9182A05F538085040B6351EFA627638A1E2787B6F7E6C1A5AE9FD221A21B5D44545D6A5EE058F712F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7661D1C86A3B4DE39EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637E88AB9B4A10918C78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D81AE1D45F69B8B34FA011A05A59D41A77117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751F2CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE91ADC097FE2C3A087B089FF177BE8049D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE34AB4081B6A6C2E079735652A29929C6CC4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F79006371F24DFF1B2961425731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A5862B5FB4F30E33DBD36C3E6CA4B5EC0C7FEAE5A1A4F12A8AD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75448CF9D3A7B2C848410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D041FB2E16F174C469D4463A0AB33EBA2F7DED747B6557E6E263433C990608F750F9C198C5C90F381D7E09C32AA3244C5D8511D2B7AB01606941B909625DFFB035DA7DC5AF9B58C0FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojCpYK6nkTlbH1hwahb/vbRQ== X-Mailru-Sender: 583F1D7ACE8F49BD9DF7A8DAE6E2B08A35DEE5FCAE8520E23F76B5FB84A52095FB23F4119BE8E6F7424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH 1/6] replication: refactor replicaset_leader() X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Serge Petrenko via Tarantool-patches Reply-To: Serge Petrenko Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 05.06.2021 02:37, Vladislav Shpilevoy пишет: > 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 Hi! Thanks for the patch! LGTM. > --- > 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); -- Serge Petrenko