Re: Yet another small patch - reorderbuffer.c:1099

Lists: pgsql-hackers
From: Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Robert Haas <rhaas(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Yet another small patch - reorderbuffer.c:1099
Date: 2016-04-04 16:03:45
Message-ID: 20160404190345.54d84ee8@fujitsu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

There is weired peace of code in reorderbuffer.c:

```
/* delete from list of known subxacts */
if (txn->is_known_as_subxact)
{
/* NB: nsubxacts count of parent will be too high now */
dlist_delete(&txn->node);
}
/* delete from LSN ordered list of toplevel TXNs */
else
{
dlist_delete(&txn->node);
}
```

As you see `if` an `else` branches are exactly the same. I wonder
whether this is a bug or code just requires a bit of cleaning. In the
latter case here is a patch.

According to `git log` both branches were introduced in one commit
b89e1510. I added author and committer of this code to CC since they
have much better understanding of it than I do.

--
Best regards,
Aleksander Alekseev
http://eax.me/

Attachment Content-Type Size
reorderbuffer.diff text/x-patch 711 bytes

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <rhaas(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: Yet another small patch - reorderbuffer.c:1099
Date: 2016-04-05 01:00:41
Message-ID: CAB7nPqTvzAxvTuBQh+MTuPVfwHUeMq30z0hrVT3fWoYD-q71gA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Apr 5, 2016 at 1:03 AM, Aleksander Alekseev
<a(dot)alekseev(at)postgrespro(dot)ru> wrote:
> There is weird peace of code in reorderbuffer.c:
>
> ```
> /* delete from list of known subxacts */
> if (txn->is_known_as_subxact)
> {
> /* NB: nsubxacts count of parent will be too high now */
> dlist_delete(&txn->node);
> }
> /* delete from LSN ordered list of toplevel TXNs */
> else
> {
> dlist_delete(&txn->node);
> }
> ```
>
> As you see `if` an `else` branches are exactly the same. I wonder
> whether this is a bug or code just requires a bit of cleaning. In the
> latter case here is a patch.
>
> According to `git log` both branches were introduced in one commit
> b89e1510. I added author and committer of this code to CC since they
> have much better understanding of it than I do.

I recall discussing this code with Andres, and I think that he has
mentioned me this is intentional, because should things be changed for
a reason or another in the future, we want to keep in mind that a list
of TXIDs and a list of sub-TXIDs should be handled differently.
--
Michael


From: Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <rhaas(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: Yet another small patch - reorderbuffer.c:1099
Date: 2016-04-05 09:07:40
Message-ID: 20160405120740.5d92447c@fujitsu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> I recall discussing this code with Andres, and I think that he has
> mentioned me this is intentional, because should things be changed for
> a reason or another in the future, we want to keep in mind that a list
> of TXIDs and a list of sub-TXIDs should be handled differently.

I see. If this it true I think there should be a comment that explains
it. When you read such a code you suspect a bug. Not mentioning that
static code analyzers (I'm currently experimenting with Clang and PVS
Studio) complain about code like this.

--
Best regards,
Aleksander Alekseev
http://eax.me/


From: Andres Freund <andres(at)anarazel(dot)de>
To: Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <rhaas(at)postgresql(dot)org>
Subject: Re: Yet another small patch - reorderbuffer.c:1099
Date: 2016-04-05 09:12:35
Message-ID: 20160405091235.avds6xcqlzp7yd5l@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2016-04-05 12:07:40 +0300, Aleksander Alekseev wrote:
> > I recall discussing this code with Andres, and I think that he has
> > mentioned me this is intentional, because should things be changed for
> > a reason or another in the future, we want to keep in mind that a list
> > of TXIDs and a list of sub-TXIDs should be handled differently.
>
> I see. If this it true I think there should be a comment that explains
> it. When you read such a code you suspect a bug. Not mentioning that
> static code analyzers (I'm currently experimenting with Clang and PVS
> Studio) complain about code like this.

There's different comments in both branches...


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <rhaas(at)postgresql(dot)org>
Subject: Re: Yet another small patch - reorderbuffer.c:1099
Date: 2016-04-05 09:19:14
Message-ID: CANP8+jJWjt-RD8oA_ya=MXcs3OPmg4Qxt=JUy_1ovnBJ5Fi6=g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 5 April 2016 at 10:12, Andres Freund <andres(at)anarazel(dot)de> wrote:

> On 2016-04-05 12:07:40 +0300, Aleksander Alekseev wrote:
> > > I recall discussing this code with Andres, and I think that he has
> > > mentioned me this is intentional, because should things be changed for
> > > a reason or another in the future, we want to keep in mind that a list
> > > of TXIDs and a list of sub-TXIDs should be handled differently.
> >
> > I see. If this it true I think there should be a comment that explains
> > it. When you read such a code you suspect a bug. Not mentioning that
> > static code analyzers (I'm currently experimenting with Clang and PVS
> > Studio) complain about code like this.
>
> There's different comments in both branches...

Then one or both of the comments is incomplete.

--
Simon Riggs http://www.2ndQuadrant.com/
<http://www.2ndquadrant.com/>
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Simon Riggs <simon(at)2ndQuadrant(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <rhaas(at)postgresql(dot)org>
Subject: Re: Yet another small patch - reorderbuffer.c:1099
Date: 2016-04-05 14:38:27
Message-ID: 20160405143827.GA258373@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Simon Riggs wrote:
> On 5 April 2016 at 10:12, Andres Freund <andres(at)anarazel(dot)de> wrote:
>
> > On 2016-04-05 12:07:40 +0300, Aleksander Alekseev wrote:
> > > > I recall discussing this code with Andres, and I think that he has
> > > > mentioned me this is intentional, because should things be changed for
> > > > a reason or another in the future, we want to keep in mind that a list
> > > > of TXIDs and a list of sub-TXIDs should be handled differently.
> > >
> > > I see. If this it true I think there should be a comment that explains
> > > it. When you read such a code you suspect a bug. Not mentioning that
> > > static code analyzers (I'm currently experimenting with Clang and PVS
> > > Studio) complain about code like this.
> >
> > There's different comments in both branches...
>
> Then one or both of the comments is incomplete.

IMO the code is wrong. There should be a single block comment saying
something like "Remove the node from its containing list. In the FOO
case, the list corresponds to BAR and therefore we delete it because
BAZ. In the QUUX case the list is PLUGH and we delete in because THUD."
Then a single line dlist_delete(...) follows.

The current arrangement looks bizantine to me, for no reason. If we
think that one of the two branches might do something additional to the
list deletion, surely that will be in a separate stanza with its own
comment; and if we ever want to remove the list deletion from one of the
two cases (something that strikes me as unlikely) then we will need to
fix the comment, too.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Yet another small patch - reorderbuffer.c:1099
Date: 2016-04-05 20:32:00
Message-ID: CA+Tgmoa6OJWnezmyvVkrXO-B-OpYzT=GsoRKtXwjDQyoqDvEiw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Apr 5, 2016 at 10:38 AM, Alvaro Herrera
<alvherre(at)2ndquadrant(dot)com> wrote:
> IMO the code is wrong. There should be a single block comment saying
> something like "Remove the node from its containing list. In the FOO
> case, the list corresponds to BAR and therefore we delete it because
> BAZ. In the QUUX case the list is PLUGH and we delete in because THUD."
> Then a single line dlist_delete(...) follows.
>
> The current arrangement looks bizantine to me, for no reason. If we
> think that one of the two branches might do something additional to the
> list deletion, surely that will be in a separate stanza with its own
> comment; and if we ever want to remove the list deletion from one of the
> two cases (something that strikes me as unlikely) then we will need to
> fix the comment, too.

+1 to everything here except for the way byzantine is spelled.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Simon Riggs <simon(at)2ndquadrant(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Yet another small patch - reorderbuffer.c:1099
Date: 2016-04-06 10:07:33
Message-ID: 20160406130733.686c2764@fujitsu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> > IMO the code is wrong. There should be a single block comment
> > saying something like "Remove the node from its containing list.
> > In the FOO case, the list corresponds to BAR and therefore we
> > delete it because BAZ. In the QUUX case the list is PLUGH and we
> > delete in because THUD." Then a single line dlist_delete(...)
> > follows.
> >
> > The current arrangement looks bizantine to me, for no reason. If we
> > think that one of the two branches might do something additional to
> > the list deletion, surely that will be in a separate stanza with
> > its own comment; and if we ever want to remove the list deletion
> > from one of the two cases (something that strikes me as unlikely)
> > then we will need to fix the comment, too.
>
> +1 to everything here except for the way byzantine is spelled.
>

+1 and yet another patch.

--
Best regards,
Aleksander Alekseev
http://eax.me/

Attachment Content-Type Size
reorderbuffer-v2.diff text/x-patch 1.0 KB

From: Andres Freund <andres(at)anarazel(dot)de>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Simon Riggs <simon(at)2ndQuadrant(dot)com>, Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <rhaas(at)postgresql(dot)org>
Subject: Re: Yet another small patch - reorderbuffer.c:1099
Date: 2016-04-06 10:15:00
Message-ID: 20160406101500.yn75uifbo67ee4je@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2016-04-05 11:38:27 -0300, Alvaro Herrera wrote:
> IMO the code is wrong.

I'm a bit confused how an intentionally duplicated block makes code
wrong...

But whatever, I found it to be clerarer that way, but apparently I'm alone.

> The current arrangement looks bizantine to me, for no reason. If we
> think that one of the two branches might do something additional to the
> list deletion, surely that will be in a separate stanza with its own
> comment; and if we ever want to remove the list deletion from one of the
> two cases (something that strikes me as unlikely) then we will need to
> fix the comment, too.

You realize it's two different lists they're deleted in the different
branches?

Greetings,

Andres Freund


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Simon Riggs <simon(at)2ndquadrant(dot)com>, Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <rhaas(at)postgresql(dot)org>
Subject: Re: Yet another small patch - reorderbuffer.c:1099
Date: 2016-09-05 00:52:36
Message-ID: 24716.1473036756@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andres Freund <andres(at)anarazel(dot)de> writes:
> On 2016-04-05 11:38:27 -0300, Alvaro Herrera wrote:
>> The current arrangement looks bizantine to me, for no reason. If we
>> think that one of the two branches might do something additional to the
>> list deletion, surely that will be in a separate stanza with its own
>> comment; and if we ever want to remove the list deletion from one of the
>> two cases (something that strikes me as unlikely) then we will need to
>> fix the comment, too.

> You realize it's two different lists they're deleted in the different
> branches?

I looked at this and can see some of the argument on both sides, but
if it's setting off static-analyzer warnings for some people, that
seems like a sufficient reason to change it. We certainly make more
significant changes than this in order to silence warnings.

I rewrote the comment a bit more and pushed it.

regards, tom lane


From: Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Simon Riggs <simon(at)2ndquadrant(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Robert Haas <rhaas(at)postgresql(dot)org>
Subject: Re: Yet another small patch - reorderbuffer.c:1099
Date: 2016-09-05 09:03:45
Message-ID: 20160905090345.GC8871@e733
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> I looked at this and can see some of the argument on both sides, but
> if it's setting off static-analyzer warnings for some people, that
> seems like a sufficient reason to change it. We certainly make more
> significant changes than this in order to silence warnings.
>
> I rewrote the comment a bit more and pushed it.

Tom, thank you for committing this patch. And thanks everyone for your
contribution!

--
Best regards,
Aleksander Alekseev