pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Change ThisTimeLineID from a global variable to a local variable
6+ messages / 4 participants
[nested] [flat]
Commits from this thread:
2021-11-07 c3ec4f8fe8 Silence uninitialized-variable warning.
* pgsql: Change ThisTimeLineID from a global variable to a local variable
@ 2021-11-05 16:55 Robert Haas <rhaas@postgresql.org>
2021-11-06 00:17 ` Re: pgsql: Change ThisTimeLineID from a global variable to a local variable Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 6+ messages in thread
From: Robert Haas @ 2021-11-05 16:55 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Change ThisTimeLineID from a global variable to a local variable.
StartupXLOG() still has ThisTimeLineID as a local variable, but the
remaining code in xlog.c now needs to the relevant TimeLineID by some
other means. Mostly, this means that we now pass it as a function
parameter to a bunch of functions where we didn't previously.
However, a few cases require special handling:
- In functions that might be called by outside callers who
wouldn't necessarily know what timeline to specify, we get
the timeline ID from shared memory. XLogCtl->ThisTimeLineID
can be used in most cases since recovery is known to have
completed by the time those functions are called. In
xlog_redo(), we can use XLogCtl->replayEndTLI.
- XLogFileClose() needs to know the TLI of the open logfile.
Do that with a new global variable openLogTLI. While
someone could argue that this is just trading one global
variable for another, the new one has a far more narrow
purposes and is referenced in just a few places.
- read_backup_label() now returns the TLI that it obtains
by parsing the backup_label file. Previously, ReadRecord()
could be called to parse the checkpoint record without
ThisTimeLineID having been initialized. Now, the timeline
is passed down, and I didn't want to pass an uninitialized
variable; this change lets us avoid that. The old coding
didn't seem to have any practical consequences that we need
to worry about, but this is cleaner.
- In BootstrapXLOG(), it's just a constant.
Patch by me, reviewed and tested by Michael Paquier, Amul Sul, and
Álvaro Herrera.
Discussion: https://postgr.es/m/CA+TgmobfAAqhfWa1kaFBBFvX+5CjM=7TE=n4r4Q1o2bjbGYBpA@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/4a92a1c3d1c361ffb031ed05bf65b801241d7cdd
Modified Files
--------------
src/backend/access/transam/xlog.c | 340 +++++++++++++++++++++-----------------
src/include/access/xlog.h | 2 +-
2 files changed, 192 insertions(+), 150 deletions(-)
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pgsql: Change ThisTimeLineID from a global variable to a local variable
2021-11-05 16:55 pgsql: Change ThisTimeLineID from a global variable to a local variable Robert Haas <rhaas@postgresql.org>
@ 2021-11-06 00:17 ` Michael Paquier <michael@paquier.xyz>
2021-11-07 17:23 ` Re: pgsql: Change ThisTimeLineID from a global variable to a local variable Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 6+ messages in thread
From: Michael Paquier @ 2021-11-06 00:17 UTC (permalink / raw)
To: Robert Haas <rhaas@postgresql.org>; +Cc: pgsql-committers@lists.postgresql.org
Hi Robert,
On Fri, Nov 05, 2021 at 04:55:52PM +0000, Robert Haas wrote:
> Change ThisTimeLineID from a global variable to a local variable.
>
> StartupXLOG() still has ThisTimeLineID as a local variable, but the
> remaining code in xlog.c now needs to the relevant TimeLineID by some
> other means. Mostly, this means that we now pass it as a function
> parameter to a bunch of functions where we didn't previously.
> However, a few cases require special handling:
lapwing looks unhappy after this commit:
https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=lapwing&dt=2021-11-05%2022%3A40%3A10
xlog.c: In function 'StartupXLOG':
xlog.c:7249:5: error: 'checkPointLoc' may be used uninitialized in
this function [-Werror=maybe-uninitialized]
xlog.c:6686:5: note: 'checkPointLoc' was declared here
Thanks,
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pgsql: Change ThisTimeLineID from a global variable to a local variable
2021-11-05 16:55 pgsql: Change ThisTimeLineID from a global variable to a local variable Robert Haas <rhaas@postgresql.org>
2021-11-06 00:17 ` Re: pgsql: Change ThisTimeLineID from a global variable to a local variable Michael Paquier <michael@paquier.xyz>
@ 2021-11-07 17:23 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-11-07 20:52 ` Re: pgsql: Change ThisTimeLineID from a global variable to a local variable Robert Haas <robertmhaas@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Tom Lane @ 2021-11-07 17:23 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; +Cc: Robert Haas <rhaas@postgresql.org>; pgsql-committers@lists.postgresql.org
Michael Paquier <michael@paquier.xyz> writes:
> On Fri, Nov 05, 2021 at 04:55:52PM +0000, Robert Haas wrote:
>> Change ThisTimeLineID from a global variable to a local variable.
> lapwing looks unhappy after this commit:
> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=lapwing&dt=2021-11-05%2022%3A40%3A10
> xlog.c: In function 'StartupXLOG':
> xlog.c:7249:5: error: 'checkPointLoc' may be used uninitialized in
> this function [-Werror=maybe-uninitialized]
> xlog.c:6686:5: note: 'checkPointLoc' was declared here
Yeah. I've seen some older compilers complain about that code before,
but now there are over a dozen buildfarm members warning about it.
It's clearly a false positive, since checkPointLoc does get set in
the read_backup_label()-failure-return code path. I think we've
seen a few other places where likely-to-be-inlined functions have
to initialize their result variables to prevent compiler warnings,
so I stuck an initialization step into read_backup_label in hopes
of silencing it.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pgsql: Change ThisTimeLineID from a global variable to a local variable
2021-11-05 16:55 pgsql: Change ThisTimeLineID from a global variable to a local variable Robert Haas <rhaas@postgresql.org>
2021-11-06 00:17 ` Re: pgsql: Change ThisTimeLineID from a global variable to a local variable Michael Paquier <michael@paquier.xyz>
2021-11-07 17:23 ` Re: pgsql: Change ThisTimeLineID from a global variable to a local variable Tom Lane <tgl@sss.pgh.pa.us>
@ 2021-11-07 20:52 ` Robert Haas <robertmhaas@gmail.com>
2021-11-07 21:39 ` Re: pgsql: Change ThisTimeLineID from a global variable to a local variable Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 6+ messages in thread
From: Robert Haas @ 2021-11-07 20:52 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Michael Paquier <michael@paquier.xyz>; pgsql-committers <pgsql-committers@lists.postgresql.org>
On Sun, Nov 7, 2021 at 12:23 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Yeah. I've seen some older compilers complain about that code before,
> but now there are over a dozen buildfarm members warning about it.
> It's clearly a false positive, since checkPointLoc does get set in
> the read_backup_label()-failure-return code path. I think we've
> seen a few other places where likely-to-be-inlined functions have
> to initialize their result variables to prevent compiler warnings,
> so I stuck an initialization step into read_backup_label in hopes
> of silencing it.
That makes sense, and sorry for not noticing this discussion sooner.
But, I'm a bit confused about what's going on here. Why did we start
getting this complaint only now? AFAICS I didn't change anything about
how checkPointLoc is handled. It's an XLogRecPtr, not a TLI, and all
the stuff I changed has to do with TLI handling. I think, anyway.
--
Robert Haas
EDB: http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pgsql: Change ThisTimeLineID from a global variable to a local variable
2021-11-05 16:55 pgsql: Change ThisTimeLineID from a global variable to a local variable Robert Haas <rhaas@postgresql.org>
2021-11-06 00:17 ` Re: pgsql: Change ThisTimeLineID from a global variable to a local variable Michael Paquier <michael@paquier.xyz>
2021-11-07 17:23 ` Re: pgsql: Change ThisTimeLineID from a global variable to a local variable Tom Lane <tgl@sss.pgh.pa.us>
2021-11-07 20:52 ` Re: pgsql: Change ThisTimeLineID from a global variable to a local variable Robert Haas <robertmhaas@gmail.com>
@ 2021-11-07 21:39 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-11-07 22:20 ` Re: pgsql: Change ThisTimeLineID from a global variable to a local variable Robert Haas <robertmhaas@gmail.com>
0 siblings, 1 reply; 6+ messages in thread
From: Tom Lane @ 2021-11-07 21:39 UTC (permalink / raw)
To: Robert Haas <robertmhaas@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; pgsql-committers <pgsql-committers@lists.postgresql.org>
Robert Haas <robertmhaas@gmail.com> writes:
> On Sun, Nov 7, 2021 at 12:23 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Yeah. I've seen some older compilers complain about that code before,
>> but now there are over a dozen buildfarm members warning about it.
>> It's clearly a false positive, since checkPointLoc does get set in
>> the read_backup_label()-failure-return code path. I think we've
>> seen a few other places where likely-to-be-inlined functions have
>> to initialize their result variables to prevent compiler warnings,
>> so I stuck an initialization step into read_backup_label in hopes
>> of silencing it.
> That makes sense, and sorry for not noticing this discussion sooner.
> But, I'm a bit confused about what's going on here. Why did we start
> getting this complaint only now? AFAICS I didn't change anything about
> how checkPointLoc is handled.
I think it's pretty clearly a compiler bug. The triggering conditions
are obscure, but they seem to have to do with inlining a function that
is supposed to initialize some variables but skips doing so in some
code paths for which "it shouldn't matter". You'd think that having
inlined, the compiler could see that all live code paths initialize
the variable ... but sometimes it doesn't see that.
Based on this data point, we can speculate that the number of such
variables matters, too.
Also, as I said, I've seen compilers warn about checkPointLoc before.
prairiedog's admittedly-ancient gcc has been doing so for years.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pgsql: Change ThisTimeLineID from a global variable to a local variable
2021-11-05 16:55 pgsql: Change ThisTimeLineID from a global variable to a local variable Robert Haas <rhaas@postgresql.org>
2021-11-06 00:17 ` Re: pgsql: Change ThisTimeLineID from a global variable to a local variable Michael Paquier <michael@paquier.xyz>
2021-11-07 17:23 ` Re: pgsql: Change ThisTimeLineID from a global variable to a local variable Tom Lane <tgl@sss.pgh.pa.us>
2021-11-07 20:52 ` Re: pgsql: Change ThisTimeLineID from a global variable to a local variable Robert Haas <robertmhaas@gmail.com>
2021-11-07 21:39 ` Re: pgsql: Change ThisTimeLineID from a global variable to a local variable Tom Lane <tgl@sss.pgh.pa.us>
@ 2021-11-07 22:20 ` Robert Haas <robertmhaas@gmail.com>
0 siblings, 0 replies; 6+ messages in thread
From: Robert Haas @ 2021-11-07 22:20 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Michael Paquier <michael@paquier.xyz>; pgsql-committers <pgsql-committers@lists.postgresql.org>
On Sun, Nov 7, 2021 at 4:39 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Based on this data point, we can speculate that the number of such
> variables matters, too.
Yeah, apparently. Well, at least I don't feel bad about not guessing
that that would happen. That's pretty magical.
--
Robert Haas
EDB: http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2021-11-07 22:20 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05 16:55 pgsql: Change ThisTimeLineID from a global variable to a local variable Robert Haas <rhaas@postgresql.org>
2021-11-06 00:17 ` Michael Paquier <michael@paquier.xyz>
2021-11-07 17:23 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-11-07 20:52 ` Robert Haas <robertmhaas@gmail.com>
2021-11-07 21:39 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-11-07 22:20 ` Robert Haas <robertmhaas@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox