Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: tml <tarantool-patches@dev.tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH 5/6] txn: stop using txn_has_flag
Date: Wed, 3 Feb 2021 20:47:39 +0100	[thread overview]
Message-ID: <68089c28-ef69-0573-32dc-89bf9e9467e6@tarantool.org> (raw)
In-Reply-To: <20210131221317.GB2172@grain>

On 31.01.2021 23:13, Cyrill Gorcunov wrote:
> On Sat, Jan 30, 2021 at 08:17:59PM +0100, Vladislav Shpilevoy wrote:
>>> --- a/src/box/txn.c
>>> +++ b/src/box/txn.c
>>> @@ -526,7 +526,7 @@ txn_free_or_wakeup(struct txn *txn)
>>>  void
>>>  txn_complete_fail(struct txn *txn)
>>>  {
>>> -	assert(!txn_has_flag(txn, TXN_IS_DONE));
>>> +	assert(!(txn->flags & TXN_IS_DONE));
>>
>> Please, use explicit != 0. We don't apply '!' operator to
>> non-boolean values. The same in other places. This I can even
>> find in the code style guide:
>>
>> https://github.com/tarantool/tarantool/wiki/Code-review-procedure#code-style
> 
> I remember this. And used this style initially. But with this rule applied
> code becomes a way more ugly. For example
> 
> -       if (!txn_has_flag(txn, TXN_CAN_YIELD))
> +       if ((txn->flags & TXN_CAN_YIELD) == 0)
> 
> In first place a person notes the "logical not" operator immediately,
> and this sounds more natural than excessive five symbols at the tail of
> the 'if' statement.
> 
> Another example
> 
> -       assert(!txn_has_flag(txn, TXN_IS_DONE));
> -       assert(!txn_has_flag(txn, TXN_WAIT_SYNC));
> +       assert(!(txn->flags & (TXN_IS_DONE | TXN_WAIT_SYNC)));
> 
> Which should be changed to either
> 
> 	assert((txn->flags & (TXN_IS_DONE | TXN_WAIT_SYNC)) == 0);
> 
> or back to pair
> 
> 	assert((txn->flags & TXN_IS_DONE) == 0);
> 	assert((txn->flags & TXN_WAIT_SYNC) == 0);
> 
> which is a way more worse than it was with txn_has_flag() helper,
> at least for me.
> 
> The initial rationale for this series was (as far as I remember) to
> setup several flags at once, so I think you could consider implementing
> txn_set_flags() helper which would do the trick instead. Thus lets drop
> this series, it doesn't make anything better without using neg operator.

Another purpose of the issue was to make TXN_WAIT_SYNC a part of
TXN_WAIT_ACK. Because ACK is never present without SYNC.

Talking of the setting many flags at once - you still can do this,
even with txn_set_flag(). Just rename txn_set_flag() to txn_set_flags(),
and make the flags proper bitfields like in the first commits of this
series. Then we could do

	txn_set_flags(TXN_WAIT_SYNC | TXN_WAIT_ACK)

Although I don't know what to do with checking flags. If we add
txn_has_flags(), then should it return true if all the requested
flags are present, or if any of them?

  reply	other threads:[~2021-02-03 19:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-22 13:26 [Tarantool-patches] [PATCH 0/6] txn: drop txn_X_flag helpers Cyrill Gorcunov via Tarantool-patches
2021-01-22 13:26 ` [Tarantool-patches] [PATCH 1/6] txn: convert flags to explicit bitfield Cyrill Gorcunov via Tarantool-patches
2021-01-22 13:26 ` [Tarantool-patches] [PATCH 2/6] txn: stop using txn_set_flag Cyrill Gorcunov via Tarantool-patches
2021-01-22 13:26 ` [Tarantool-patches] [PATCH 3/6] test/unit: snap_quorum_delay -- " Cyrill Gorcunov via Tarantool-patches
2021-01-30 19:17   ` Vladislav Shpilevoy via Tarantool-patches
2021-01-31 10:40     ` Cyrill Gorcunov via Tarantool-patches
2021-01-22 13:26 ` [Tarantool-patches] [PATCH 4/6] txn: stop using txn_clear_flag Cyrill Gorcunov via Tarantool-patches
2021-01-22 13:26 ` [Tarantool-patches] [PATCH 5/6] txn: stop using txn_has_flag Cyrill Gorcunov via Tarantool-patches
2021-01-30 19:17   ` Vladislav Shpilevoy via Tarantool-patches
2021-01-31 22:13     ` Cyrill Gorcunov via Tarantool-patches
2021-02-03 19:47       ` Vladislav Shpilevoy via Tarantool-patches [this message]
2021-02-03 22:02         ` Cyrill Gorcunov via Tarantool-patches
2021-01-22 13:27 ` [Tarantool-patches] [PATCH 6/6] txn: drop unused txn_x_flag helpers Cyrill Gorcunov via Tarantool-patches
2021-01-27 12:08 ` [Tarantool-patches] [PATCH 0/6] txn: drop txn_X_flag helpers Serge Petrenko 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=68089c28-ef69-0573-32dc-89bf9e9467e6@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 5/6] txn: stop using txn_has_flag' \
    /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