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 629FC6EC55; Thu, 10 Jun 2021 17:06:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 629FC6EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1623333979; bh=xoEb0vejTc/59+C1T6GxD8N0qTYA9imwOF2RWdkCor8=; 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=hpLIQMzg0e4WKNv2obw9kCpC34aYxtWzwhH1Gq4TFzuNpKxKzK5H+cu23FP/KXRDq 59fCQTVpoRGYJhCAASEV25KHjU2j8nmqOhFk2r87e0fqkZOwFBhAnukNa+Rw6+1gAc Gv4dEY6Vwpegf80wnZLMrrFeCiSAM1h0OYScKcdE= 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 A7CF86EC55 for ; Thu, 10 Jun 2021 17:06:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A7CF86EC55 Received: by smtp53.i.mail.ru with esmtpa (envelope-from ) id 1lrLK4-0007BS-UW; Thu, 10 Jun 2021 17:06:17 +0300 To: Vladislav Shpilevoy , tarantool-patches@dev.tarantool.org, gorcunov@gmail.com References: <6675abcfa409f1fd6e05a7e7852b42e1a08d1795.1622849790.git.v.shpilevoy@tarantool.org> Message-ID: <3f77385e-9bcd-654c-68eb-8bad8a634a0a@tarantool.org> Date: Thu, 10 Jun 2021 17:06:16 +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: <6675abcfa409f1fd6e05a7e7852b42e1a08d1795.1622849790.git.v.shpilevoy@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: ru X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9D5B0DA836B685C546075B3437CB362FF47FF2EE3FBA69D6F182A05F5380850403767987B909C64996A93049AD13D7419030EF80872F6D5E64B10CA51191DFE87 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE765F8192D394616BAEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375E347E1311495C1B8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8B392C4185226095F23139D6548837ABA117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BF1175FABE1C0F9B6A471835C12D1D977C4224003CC836476EB9C4185024447017B076A6E789B0E975F5C1EE8F4F765FCD326B257D56EBB5F3AA81AA40904B5D9CF19DD082D7633A078D18283394535A93AA81AA40904B5D98AA50765F79006378135B3BBB5A3AE06EC76A7562686271EEC990983EF5C03292E808ACE2090B5E14AD6D5ED66289B5259CC434672EE63711DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C34B08FA16E56A400835872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A54DC56162EBAE4E9AE37B86D27EE560D63B7255268FEBE57DD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75448CF9D3A7B2C848410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C786159FDC4342B030855000D803B707B63B3A09FED134C1D409AEAD200CDD5A3D0F8FDE708656D01D7E09C32AA3244CB674051D7F4F34D2B7548E5DA8B7D19FE646F07CC2D4F3D8FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojCpYK6nkTlbFr/0kXeyfxDg== X-Mailru-Sender: 583F1D7ACE8F49BD9DF7A8DAE6E2B08A8592DC5ACF554A7F8C48E4F9035F80CCB234E1755B658A9C424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH 5/6] replication: use 'score' to find a join-master 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 пишет: > The patch refactors the algorithm of finding a join-master (in > replicaset_find_join_master()) to use scores instead of multiple > iterations with different criteria. > > The original code was relatively fine as long as it had only > one parameter to change - whether should it skip > `box.cfg{read_only = true}` nodes. > > Although it was clear that it was "on the edge" of acceptable > complexity due to a second non-configurable parameter whether a > replica is in read-only state regardless of its config. > > It is going to get more complicated when the algorithm will take > into account the third parameter whether an instance is > bootstrapped. > > Then it should make decisions like "among bootstrapped nodes try > to prefer instances not having read_only=true, and not being in > read-only state". The easiest way to do so is to use > scores/weights incremented according to the instance's parameters > matching certain "good points". > > Part of #5613 LGTM. > --- > src/box/replication.cc | 62 ++++++++++++++++-------------------------- > 1 file changed, 23 insertions(+), 39 deletions(-) > > diff --git a/src/box/replication.cc b/src/box/replication.cc > index 990f6239c..d33e70f28 100644 > --- a/src/box/replication.cc > +++ b/src/box/replication.cc > @@ -960,71 +960,55 @@ replicaset_next(struct replica *replica) > * replicas, choose a read-only replica with biggest vclock > * as a leader, in hope it will become read-write soon. > */ > -static struct replica * > -replicaset_round(bool skip_ro) > +struct replica * > +replicaset_find_join_master(void) > { > struct replica *leader = NULL; > + int leader_score = -1; > replicaset_foreach(replica) { > 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. > - * The only exception if there is no read-write > - * replicas since there is still a possibility > - * that all replicas exist in cluster table. > - */ > - if (skip_ro && ballot->is_ro_cfg) > - continue; > - if (leader == NULL) { > - leader = replica; > - continue; > - } > - const struct ballot *leader_ballot = &leader->applier->ballot; > + int score = 0; > /* > - * Try to find a replica which has already left > - * orphan mode. > + * Prefer instances not configured as read-only via box.cfg, and > + * not being in read-only state due to any other reason. The > + * config is stronger because if it is configured as read-only, > + * it is in read-only state for sure, until the config is > + * changed. > */ > - if (ballot->is_ro && !leader_ballot->is_ro) > + if (!ballot->is_ro_cfg) > + score += 5; > + if (!ballot->is_ro) > + score += 1; > + if (leader_score < score) > + goto elect; > + if (score < leader_score) > continue; > + const struct ballot *leader_ballot; > + leader_ballot = &leader->applier->ballot; > /* > * Choose the replica with the most advanced > * vclock. If there are two or more replicas > * with the same vclock, prefer the one with > * the lowest uuid. > */ > - int cmp = vclock_compare_ignore0(&ballot->vclock, > - &leader_ballot->vclock); > + int cmp; > + cmp = vclock_compare_ignore0(&ballot->vclock, > + &leader_ballot->vclock); > if (cmp < 0) > continue; > if (cmp == 0 && tt_uuid_compare(&replica->uuid, > &leader->uuid) > 0) > continue; > + elect: > leader = replica; > + leader_score = score; > } > return leader; > } > > -struct replica * > -replicaset_find_join_master(void) > -{ > - bool skip_ro = true; > - /** > - * Two loops, first prefers read-write replicas among others. > - * Second for backward compatibility, if there is no such > - * replicas at all. > - */ > - struct replica *leader = replicaset_round(skip_ro); > - if (leader == NULL) { > - skip_ro = false; > - leader = replicaset_round(skip_ro); > - } > - > - return leader; > -} > - > struct replica * > replica_by_uuid(const struct tt_uuid *uuid) > { -- Serge Petrenko