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 0FF826EC55; Thu, 10 Jun 2021 18:02:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0FF826EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1623337372; bh=pCpzY9OVMX1nRE78+Wqd7fHTQSCQz4KJxXo5XsS6epo=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=B8SWY5xWoiDttyTD8+Qx5g0qcRAmuhG1lASuPk4Rcb8K5uiPo97krCSuJ8GiTlin5 Gg5/MONoWjmHDYGKBzlQorHFOkslYKwwAEsS7PiBudLAmzcWrEzSpt7fpxsrwXvilY 2D0i86UMK/QA/OHvG6cWnwsvbkNZ2IRTBwcNHoH8= Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 567186EC55 for ; Thu, 10 Jun 2021 18:02:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 567186EC55 Received: by mail-lj1-f173.google.com with SMTP id z22so5326824ljh.8 for ; Thu, 10 Jun 2021 08:02:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Vn6vEKnLsflIkwNJ9VY9VWjJXV7oXXFE/LwmuI0Mglg=; b=kvxi4nThRbKAQnr7kN9kIGj/eDSXcA8+uUCvgX6K8FhdjhkwQYo7TC0u1/NIoS8Tcd N3z2PnpPrcR/Fk8y9euNXM0uh/b0nS/9tbLETs4C6y7Gct1VHQVxk5P3iV+gDhSMQjo7 kNT4D+ynGG79kIKHgY3hg4A5fgEDDRHP/Wz2fOwAwlEZrqc0VDTDqfekLYayPa/lzq7F yzvAnMLze55cryMHl9LY/Jr6vSngme6ZETQ4FnQsD5YQQqipWFf2qkl1E5J8v1yFCM9+ QTSf9O/R/eiNCZp5bL12/c5gmRGBGiQZn8zljrvjL7TrYWgphNubKBfQoAmSUdDK+yDY RtIg== X-Gm-Message-State: AOAM533DZIKxYiglqF8s/q4JEPTGYjMpiy26vMHnfgxfDQdE36lFEsQC KN1kao7F0cdm6d1akKYk169DcEPBwrQ= X-Google-Smtp-Source: ABdhPJzfaKoDVdQRkCNTY64jVJxP1VCqXEkCZkXbCe6MAyQzth8ZQzo7Hfud0MtDLKna5+BKZZeUtA== X-Received: by 2002:a2e:b8cc:: with SMTP id s12mr2595238ljp.66.1623337368675; Thu, 10 Jun 2021 08:02:48 -0700 (PDT) Received: from grain.localdomain ([5.18.171.94]) by smtp.gmail.com with ESMTPSA id h34sm319725lfv.249.2021.06.10.08.02.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 08:02:47 -0700 (PDT) Received: by grain.localdomain (Postfix, from userid 1000) id 2B5435A0041; Thu, 10 Jun 2021 18:02:46 +0300 (MSK) Date: Thu, 10 Jun 2021 18:02:46 +0300 To: Vladislav Shpilevoy Message-ID: References: <6675abcfa409f1fd6e05a7e7852b42e1a08d1795.1622849790.git.v.shpilevoy@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6675abcfa409f1fd6e05a7e7852b42e1a08d1795.1622849790.git.v.shpilevoy@tarantool.org> User-Agent: Mutt/2.0.7 (2021-05-04) 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: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On Sat, Jun 05, 2021 at 01:37:59AM +0200, Vladislav Shpilevoy wrote: > + 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; Vlad, if only I'm not missing something obvious we can do simplier without branching at all, say score = (ballot->is_booted << 3) | (ballot->is_ro_cfg << 2) | (ballot->is_ro << 1); up to you, just an idea. ... > if (cmp == 0 && tt_uuid_compare(&replica->uuid, > &leader->uuid) > 0) > continue; > + elect: seems extra tab here? > leader = replica; > + leader_score = score; > } > return leader; > }