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 5033D6EC58; Wed, 26 May 2021 10:25:59 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5033D6EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1622013959; bh=Fbf/pbH+80Mff2foT18LKXxaGtvOwawrrg516XiALvw=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=nVj62c7wdhrWOY6WNryi3ULI+KL2y6A7s+NU153TAsqoVjGO748zXVK5V8VUpYhYc fkluqonG5No9AtRqu47TWOb/+9D8sCpqs6mCwCfGqqABxF1G8gY+UCZ50lwVmsynR0 LYRoXYz5khuqO3AIUK0sj4lBv4V/W7tHb7RBU4v4= Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 633276EC58 for ; Wed, 26 May 2021 10:25:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 633276EC58 Received: by mail-lf1-f49.google.com with SMTP id a2so1019731lfc.9 for ; Wed, 26 May 2021 00:25:57 -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=RSHSbyJ+aACqfk7vAHOpIIxzywilbBWEkzvUxfhjtE0=; b=XGmxSeltsOGvOsaN70S5/KJu7Q0+LExLTH5GDT4n+e/87dRcTqpxIpgRILiVXya3DR zUCoOWzD20Wlg+TaQaoich8QzJIjnyHJlGtROVx1b6O3rGYTEI/zo26mQTLQoguMiSW9 rl3bfDewQleZ+872DqmDH1lRaw4hv/xcjToyrPXEGxN8N55J3X6maT70r5cHScTxmm7F 936Ds8TPVXeTbcgcLayCc1cD+sa7f2h3JJqMy8/Y7Jcqpk0pEEIYsXvmSrKPHtcChXqq 9e7uKG23iXBB7FbHl/Dib87ZhwG6TH/3SPCnIYw2XZEaEBFvhUJ/DatR7CB7DoY0/RQW WW3w== X-Gm-Message-State: AOAM530MWe9tTeoaa9GFa05MY17LLRdCI4DB+YqEEE5/gXZTUdtN0MkI 6YsDtuVFCvPl+ORBCaFsr7eNY+ttF7g= X-Google-Smtp-Source: ABdhPJzhBPdOgX9QYqB67bKfinSbcOj4xw+eF57dWFpxV0AJUG26L6BWkrePDtA3g9emkYiPDBC2DQ== X-Received: by 2002:ac2:5447:: with SMTP id d7mr1172826lfn.348.1622013956181; Wed, 26 May 2021 00:25:56 -0700 (PDT) Received: from grain.localdomain ([5.18.171.94]) by smtp.gmail.com with ESMTPSA id v26sm1953791lfd.291.2021.05.26.00.25.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 00:25:55 -0700 (PDT) Received: by grain.localdomain (Postfix, from userid 1000) id 7B0CC5A003F; Wed, 26 May 2021 10:25:54 +0300 (MSK) Date: Wed, 26 May 2021 10:25:54 +0300 To: Serge Petrenko Cc: v.shpilevoy@tarantool.org, tarantool-patches@dev.tarantool.org Message-ID: References: <913a4471008f32c4f9448f25ae54c3de6ee2f249.1621935783.git.sergepetrenko@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <913a4471008f32c4f9448f25ae54c3de6ee2f249.1621935783.git.sergepetrenko@tarantool.org> User-Agent: Mutt/2.0.7 (2021-05-04) Subject: Re: [Tarantool-patches] [PATCH v2 1/2] box: refactor in_promote using a guard 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 Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On Tue, May 25, 2021 at 01:39:28PM +0300, Serge Petrenko wrote: > --- > src/box/box.cc | 11 ++++------- > 1 file changed, 4 insertions(+), 7 deletions(-) > > diff --git a/src/box/box.cc b/src/box/box.cc > index c10e0d8bf..894e3d0f4 100644 > --- a/src/box/box.cc > +++ b/src/box/box.cc > @@ -1562,6 +1562,9 @@ box_promote(void) > int rc = 0; > int quorum = replication_synchro_quorum; > in_promote = true; > + auto promote_guard = make_scoped_guard([&] { > + in_promote = false; > + }); Looks ok to me, though I must confess I always consider such flags spread all over the code is somehow clumsy. Since this is a common pattern in our cpp code lets keep it but still in my humble opinion we could rather move all box_promote code into some box_do_promote helper and we would have int box_promote(void) { static bool in_promote = false; if (in_promote) { diag_set(ClientError, ER_UNSUPPORTED, "box.ctl.promote", "simultaneous invocations"); return -1; } in_promote = true; int rc = box_do_promote(); in_promote = false; return rc; } but surely this is not a request for code refactoring, current form is ok as well ;) Ack. Serge, while you're at this code anyway, could you please change switch (box_election_mode) { case ELECTION_MODE_OFF: try_wait = true; break; ... default: panic("enexpected box_election_mode mode"); break; } instead of unreacheable() call. We should stop using unreacheable() as much as we could.