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 2D1EB6EC58; Thu, 27 May 2021 13:57:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2D1EB6EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1622113042; bh=v0g+DHuPry7m4twG7ZcQT6hXM/ay4TAik548nB7SsWM=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=qhcXJnxuAyzEs9fqCOfCXZdOpb4eLl6Wp19fIWj77DAxapTK35oEWtsbPUVk+BHiI INPUNKgErGeqdip2JWWmn7PRtEY+snLLxnps+/vozkJE9n5xCi+m8AYe7xG+I2zReB hwGf6dX9j9lAYqXSoufSzxpjIWwX0eOHoD7OOCfE= Received: from smtp51.i.mail.ru (smtp51.i.mail.ru [94.100.177.111]) (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 A25D16EC58 for ; Thu, 27 May 2021 13:57:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A25D16EC58 Received: by smtp51.i.mail.ru with esmtpa (envelope-from ) id 1lmDhX-0006ui-RD; Thu, 27 May 2021 13:57:20 +0300 To: Cyrill Gorcunov Cc: v.shpilevoy@tarantool.org, tarantool-patches@dev.tarantool.org References: <913a4471008f32c4f9448f25ae54c3de6ee2f249.1621935783.git.sergepetrenko@tarantool.org> Message-ID: <0ab586a8-bb17-6e18-b486-c4dd5a0de42c@tarantool.org> Date: Thu, 27 May 2021 13:57:19 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9157EECD0FDB90B9A3828624E6E8B1F07482114E64581541200894C459B0CD1B942D5AD15263FCB4FB006BD1AF480C034E9D6F8471C2FED9C5709D77201D190DA X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE72777B9F191503624EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006377BA6DB23C50317A38638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D853DCA3DF4FB114A66C3002BD832E0946117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18C26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6BF3059D42242344A089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5C3132C0DDB3AA02C1650CE77EC7159208F1C6D03E4767D26D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75E3127721F5A72C97410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C6EC1BD9807109D261BCBA50EDCE43F2EF0029CC3B148C859AFAEC4DB7780B042CF3E7B4038312981D7E09C32AA3244C9621060F40F3AC95357109BE8B03B613725D5B54B2FE4575FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojywAFAsvjBJi/nfO+cUXm3g== X-Mailru-Sender: 3B9A0136629DC9125D61937A2360A4467A4782A5D3C55024D55490C675CBD8871580CEDF0085965D424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok 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: Serge Petrenko via Tarantool-patches Reply-To: Serge Petrenko Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 26.05.2021 10:25, Cyrill Gorcunov пишет: > 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. Thanks for the review! I think this piece of code is unrelated to what I'm changing. This commit was introduced to avoid multiple additions of `in_promote = false;` in the next commit. The change you propose is good, but it's out of scope of this patchset IMO. I may change apply it though if you insist. -- Serge Petrenko