pgsql: xlog.c: Remove global variables ReadRecPtr and EndRecPtr. - Mailing list pgsql-committers

From Robert Haas
Subject pgsql: xlog.c: Remove global variables ReadRecPtr and EndRecPtr.
Date
Msg-id E1mpv7m-0007hR-QG@gemulon.postgresql.org
Whole thread Raw
Responses Re: pgsql: xlog.c: Remove global variables ReadRecPtr and EndRecPtr.  (Andres Freund <andres@anarazel.de>)
List pgsql-committers
xlog.c: Remove global variables ReadRecPtr and EndRecPtr.

In most places, the variables necessarily store the same value as the
eponymous members of the XLogReaderState that we use during WAL
replay, because ReadRecord() assigns the values from the structure
members to the global variables just after XLogReadRecord() returns.
However, XLogBeginRead() adjusts the structure members but not the
global variables, so after XLogBeginRead() and before the completion
of XLogReadRecord() the values can differ. Otherwise, they must be
identical.  According to my analysis, the only place where either
variable is referenced at a point where it might not have the same
value as the structure member is the refrence to EndRecPtr within
XLogPageRead.

Therefore, at every other place where we are using the global
variable, we can just switch to using the structure member instead,
and remove the global variable. However, we can, and in fact should,
do this in XLogPageRead() as well, because at that point in the code,
the global variable will actually store the start of the record we
want to read - either because it's where the last WAL record ended, or
because the read position has been changed using XLogBeginRead since
the last record was read. The structure member, on the other hand,
will already have been updated to point to the end of the record we
just read. Elsewhere, the latter is what we use as an argument to
emode_for_corrupt_record(), so we should do the same here.

This part of the patch is perhaps a bug fix, but I don't think it has
any important consequences, so no back-patch. The point here is just
to continue to whittle down the entirely excessive use of global
variables in xlog.c.

Discussion: http://postgr.es/m/CA+Tgmoao96EuNeSPd+hspRKcsCddu=b1h-QNRuKfY8VmfNQdfg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d2ddfa681db27a138acb63c8defa8cc6fa588922

Modified Files
--------------
src/backend/access/transam/xlog.c | 53 ++++++++++++++++++---------------------
1 file changed, 24 insertions(+), 29 deletions(-)


pgsql-committers by date:

Previous
From: Robert Haas
Date:
Subject: pgsql: Fix corner-case failure to detect improper timeline switch.
Next
From: Heikki Linnakangas
Date:
Subject: pgsql: Fix missing space in docs.