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 2821B6EC40; Sat, 5 Jun 2021 02:38:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2821B6EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1622849914; bh=GMOjT+47/meyk5vmw1Eo7BOp6Rk4ORQBLnbjShJwXk4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Q/gW3Yyxt5SXL3e9LX8Xpw3hrJe4kg89OKrRLOlOwC0Gb0lRiJ1NyhuKpa3RAde2f rwACx2Mu1tPG99gI//jD6KMxiXHxhmeo5T+N5A+9je/eReZVY86+UdVhwEzU8SbU4/ pLURxkv5JMu1afsh6rGLWaQJKSU1VvIRwEryxh14= Received: from smtp16.mail.ru (smtp16.mail.ru [94.100.176.153]) (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 DDB376EC40 for ; Sat, 5 Jun 2021 02:38:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DDB376EC40 Received: by smtp16.mail.ru with esmtpa (envelope-from ) id 1lpJO6-0001Ge-21; Sat, 05 Jun 2021 02:38:02 +0300 To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergepetrenko@tarantool.org Date: Sat, 5 Jun 2021 01:37:55 +0200 Message-Id: <751c1367a94e87118a1699579af71af43ee3624d.1622849790.git.v.shpilevoy@tarantool.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D5B0DA836B685C544BBC2A69B1B4100B389BF69B7A224D7C182A05F538085040FF76B59B1A8119095C05714E0162F6FB1396A0964804678261C4BD8434935039 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE789DCD78EC958A690EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CC84CAE328DCD2648638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8E322F945373DACF9E51B6AFB1CC6A8FE117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10F2CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEC24E1E72F37C03A0CEDA8D6C8C3B0531D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE389DDFE3E282F3DD103F1AB874ED89028C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F79006373BC478629CBEC79DEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824A2A04A2ABAA09D25379311020FFC8D4AD775094620C760E12ACE8209ECF4A4009 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CC176FDF34A1E429F60F11469A42761BA5FCCE6560F20CFDD9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFD99FB7B2A39B4961699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34F1ADD4D8CD3C81CEAFA38B9C2B657AA1DD061B2F78DA1158D40B2D8EA56B322F346F1FC514A0A2341D7E09C32AA3244CC772B4CB786BEDF3492246185EEB891D33C9DC155518937FFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojz99asgmzejoSpfZZyHV9zA== X-Mailru-Sender: 504CC1E875BF3E7D9BC0E5172ADA3110B8F3BE3BFF3B965003760132911205A140F6B5942722552207784C02288277CA03E0582D3806FB6A5317862B1921BA260ED6CFD6382C13A6112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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)