Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: v.shpilevoy@tarantool.org, tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 1/2] box: refactor in_promote using a guard
Date: Thu, 27 May 2021 13:57:19 +0300	[thread overview]
Message-ID: <0ab586a8-bb17-6e18-b486-c4dd5a0de42c@tarantool.org> (raw)
In-Reply-To: <YK34AnyRzY0vSfE9@grain>



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


  reply	other threads:[~2021-05-27 10:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-25 10:39 [Tarantool-patches] [PATCH v2 0/2] fix an assertion failure in box.ctl.promote() Serge Petrenko via Tarantool-patches
2021-05-25 10:39 ` [Tarantool-patches] [PATCH v2 1/2] box: refactor in_promote using a guard Serge Petrenko via Tarantool-patches
2021-05-26  7:25   ` Cyrill Gorcunov via Tarantool-patches
2021-05-27 10:57     ` Serge Petrenko via Tarantool-patches [this message]
2021-05-27 11:02       ` Cyrill Gorcunov via Tarantool-patches
2021-05-25 10:39 ` [Tarantool-patches] [PATCH v2 2/2] box: fix an assertion failure in box.ctl.promote() Serge Petrenko via Tarantool-patches
2021-05-26  6:14   ` Cyrill Gorcunov via Tarantool-patches
2021-05-26  8:25     ` Serge Petrenko via Tarantool-patches
2021-05-26 18:46       ` Vladislav Shpilevoy via Tarantool-patches
2021-05-27 10:53         ` Serge Petrenko via Tarantool-patches
2021-05-27 11:03           ` Cyrill Gorcunov via Tarantool-patches
2021-05-27 19:30           ` Vladislav Shpilevoy via Tarantool-patches
2021-06-01 12:20 ` [Tarantool-patches] [PATCH v2 0/2] " Kirill Yukhin via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0ab586a8-bb17-6e18-b486-c4dd5a0de42c@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=sergepetrenko@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 1/2] box: refactor in_promote using a guard' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox