Re: Incorrect initialization of sentPtr in walsender.c

Lists: pgsql-hackers
From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Incorrect initialization of sentPtr in walsender.c
Date: 2014-09-12 00:08:39
Message-ID: CAB7nPqS2ujOxFxNRRxm8vv-cSAEBGWQT-49jRpr5ArRxrrNVYA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi all,

In walsender.c, sentPtr is initialized as follows:
static XLogRecPtr sentPtr = 0;
Isn't that incorrect and shouldn't we use InvalidXLogRecPtr instead?
Patch is attached.
Regards,
--
Michael

Attachment Content-Type Size
20140912_walsender_sentptr.patch text/x-diff 629 bytes

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Incorrect initialization of sentPtr in walsender.c
Date: 2014-09-12 00:17:53
Message-ID: CAB7nPqR1tzEpzY3VBg3Nsk5w_q6+wtspiOkXAM2HSu36pHz_LQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Sep 12, 2014 at 9:08 AM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> In walsender.c, sentPtr is initialized as follows:
> static XLogRecPtr sentPtr = 0;
> Isn't that incorrect and shouldn't we use InvalidXLogRecPtr instead?
Actually by looking more around I found a couple of extra places where
the same inconsistencies are present, mainly in xlog.c and
walreceiver.c. Updated patch attached for all those things.
Regards,
--
Michael

Attachment Content-Type Size
20140912_wal_incorrect_ptr.patch text/x-diff 2.2 KB

From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Incorrect initialization of sentPtr in walsender.c
Date: 2014-09-12 07:55:43
Message-ID: 5412A6FF.6030008@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 09/12/2014 03:17 AM, Michael Paquier wrote:
> On Fri, Sep 12, 2014 at 9:08 AM, Michael Paquier
> <michael(dot)paquier(at)gmail(dot)com> wrote:
>> In walsender.c, sentPtr is initialized as follows:
>> static XLogRecPtr sentPtr = 0;
>> Isn't that incorrect and shouldn't we use InvalidXLogRecPtr instead?
> Actually by looking more around I found a couple of extra places where
> the same inconsistencies are present, mainly in xlog.c and
> walreceiver.c. Updated patch attached for all those things.

InvalidXLogRecPtr == 0, so it's just a style issue which one is more
correct.

I haven't looked at those places closely, but it seems possible that at
least some of those variables are supposed to be initialized to a value
smaller than any valid WAL position, rather than just Invalid. In other
words, if we defined InvalidXLogRecPtr as INT64_MAX rather than 0, we
would still want those variables to be initialized to zero. As I said, I
didn't check the code, but before we change those that ought to be checked.

- Heikki


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Incorrect initialization of sentPtr in walsender.c
Date: 2014-09-12 12:16:42
Message-ID: CAB7nPqRUaFyTJ024W-HiihW4PwfcadZN9HFMsJQfOZSQtZtDUA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Sep 12, 2014 at 4:55 PM, Heikki Linnakangas
<hlinnakangas(at)vmware(dot)com> wrote:
> I haven't looked at those places closely, but it seems possible that at
> least some of those variables are supposed to be initialized to a value
> smaller than any valid WAL position, rather than just Invalid. In other
> words, if we defined InvalidXLogRecPtr as INT64_MAX rather than 0, we would
> still want those variables to be initialized to zero. As I said, I didn't
> check the code, but before we change those that ought to be checked.

Ah, OK. I just had a look at that, and receivedUpto and lastComplaint
in xlog.c need to use the lowest pointer value possible as they do a
couple of comparisons with other positions. This is as well the case
of sentPtr in walsender.c. However, that's not the case of writePtr
and flushPtr in walreceiver.c as those positions are just used for
direct comparison with LogstreamResult, so we could use
InvalidXLogRecPtr in this case.

What do you think of the addition of a #define for the lowest possible
XLOG location pointer? I've wanted that as well a couple of times when
working on clients using replication connections for for example
START_REPLICATION. That would be better than hardcoding a position
like '0/0', and would make the current code more solid.

Patch attached in case.

Regards,
--
Michael

Attachment Content-Type Size
20140912_wal_incorrect_ptr_v2.patch text/x-diff 2.9 KB

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Incorrect initialization of sentPtr in walsender.c
Date: 2014-10-13 20:18:34
Message-ID: 20141013201834.GK21267@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Sep 12, 2014 at 09:16:42PM +0900, Michael Paquier wrote:
> On Fri, Sep 12, 2014 at 4:55 PM, Heikki Linnakangas
> <hlinnakangas(at)vmware(dot)com> wrote:
> > I haven't looked at those places closely, but it seems possible that at
> > least some of those variables are supposed to be initialized to a value
> > smaller than any valid WAL position, rather than just Invalid. In other
> > words, if we defined InvalidXLogRecPtr as INT64_MAX rather than 0, we would
> > still want those variables to be initialized to zero. As I said, I didn't
> > check the code, but before we change those that ought to be checked.
>
> Ah, OK. I just had a look at that, and receivedUpto and lastComplaint
> in xlog.c need to use the lowest pointer value possible as they do a
> couple of comparisons with other positions. This is as well the case
> of sentPtr in walsender.c. However, that's not the case of writePtr
> and flushPtr in walreceiver.c as those positions are just used for
> direct comparison with LogstreamResult, so we could use
> InvalidXLogRecPtr in this case.
>
> What do you think of the addition of a #define for the lowest possible
> XLOG location pointer? I've wanted that as well a couple of times when
> working on clients using replication connections for for example
> START_REPLICATION. That would be better than hardcoding a position
> like '0/0', and would make the current code more solid.
>
> Patch attached in case.

I like this. Can we apply it Heikki?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Incorrect initialization of sentPtr in walsender.c
Date: 2014-10-14 01:31:56
Message-ID: CAB7nPqRt_AOyHAaSzi17p0eN8cDVdn-XNExGbCzrx99xjYrpqA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Oct 14, 2014 at 5:18 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> On Fri, Sep 12, 2014 at 09:16:42PM +0900, Michael Paquier wrote:
>> Patch attached in case.
> I like this. Can we apply it Heikki?
I actually registered it to the next CF so as it does not fall into
oblivion, simply forgot to mention it:
https://commitfest.postgresql.org/action/patch_view?id=1572
Note that this patch still sets InvalidXLogRecPtr to 0. I think that
it should be INT64_MAX for clarity.
Regards
--
Michael


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Incorrect initialization of sentPtr in walsender.c
Date: 2014-10-16 10:09:16
Message-ID: CA+U5nM+aVaL2k0pQhu39DzEehOpo3F2vsjD1pMR91rE60i41=Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 12 September 2014 13:16, Michael Paquier <michael(dot)paquier(at)gmail(dot)com> wrote:
> On Fri, Sep 12, 2014 at 4:55 PM, Heikki Linnakangas
> <hlinnakangas(at)vmware(dot)com> wrote:
>> I haven't looked at those places closely, but it seems possible that at
>> least some of those variables are supposed to be initialized to a value
>> smaller than any valid WAL position, rather than just Invalid. In other
>> words, if we defined InvalidXLogRecPtr as INT64_MAX rather than 0, we would
>> still want those variables to be initialized to zero. As I said, I didn't
>> check the code, but before we change those that ought to be checked.
>
> Ah, OK. I just had a look at that, and receivedUpto and lastComplaint
> in xlog.c need to use the lowest pointer value possible as they do a
> couple of comparisons with other positions. This is as well the case
> of sentPtr in walsender.c. However, that's not the case of writePtr
> and flushPtr in walreceiver.c as those positions are just used for
> direct comparison with LogstreamResult, so we could use
> InvalidXLogRecPtr in this case.

I don't see this patch gives us anything. All it will do is prevent
easy backpatching of related fixes.

-1 for changing the code in this kind of way

I find it confusing that the "Lowest" pointer value is also "Invalid".
Valid != Invalid

-1 for this patch

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


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>
Cc: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Incorrect initialization of sentPtr in walsender.c
Date: 2014-10-16 12:01:33
Message-ID: CAB7nPqQTf6H6pCzgvZv_emyGpyhzzsjNthe3oTDKWAna8+71gg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Oct 16, 2014 at 7:09 PM, Simon Riggs <simon(at)2ndquadrant(dot)com> wrote:

> I find it confusing that the "Lowest" pointer value is also "Invalid".
> Valid != Invalid
>
In complement to that, note that I mentioned Invalid should be UINT_MAX for
clarity.
--
Michael


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Simon Riggs <simon(at)2ndquadrant(dot)com>
Cc: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Incorrect initialization of sentPtr in walsender.c
Date: 2014-11-18 08:32:26
Message-ID: CAB7nPqRChWTC754e69+Zy2pSr-OvFOFkRjGHhpoACNfp9YWPdQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Oct 16, 2014 at 9:01 PM, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
wrote:

> On Thu, Oct 16, 2014 at 7:09 PM, Simon Riggs <simon(at)2ndquadrant(dot)com>
> wrote:
>
>> I find it confusing that the "Lowest" pointer value is also "Invalid".
>> Valid != Invalid
>>
> In complement to that, note that I mentioned Invalid should be UINT_MAX
> for clarity.
>
Worth noticing that this patch has been marked as returned with feedback.
--
Michael