pgsql: Remove all use of ThisTimeLineID global variable outside of xlog

From: Robert Haas <rhaas(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Remove all use of ThisTimeLineID global variable outside of xlog
Date: 2021-11-05 16:52:32
Message-ID: E1mj2S8-0000VE-Ng@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Remove all use of ThisTimeLineID global variable outside of xlog.c

All such code deals with this global variable in one of three ways.
Sometimes the same functions use it in more than one of these ways
at the same time.

First, sometimes it's an implicit argument to one or more functions
being called in xlog.c or elsewhere, and must be set to the
appropriate value before calling those functions lest they
misbehave. In those cases, it is now passed as an explicit argument
instead.

Second, sometimes it's used to obtain the current timeline after
the end of recovery, i.e. the timeline to which WAL is being
written and flushed. Such code now calls GetWALInsertionTimeLine()
or relies on the new out parameter added to GetFlushRecPtr().

Third, sometimes it's used during recovery to store the current
replay timeline. That can change, so such code must generally
update the value before each use. It can still do that, but must
now use a local variable instead.

The net effect of these changes is to reduce by a fair amount the
amount of code that is directly accessing this global variable.
That's good, because history has shown that we don't always think
clearly about which timeline ID it's supposed to contain at any
given point in time, or indeed, whether it has been or needs to
be initialized at any given point in the code.

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/e997a0c642860a96df0151cbeccfecbdf0450d08

Modified Files
--------------
src/backend/access/transam/twophase.c | 14 +----
src/backend/access/transam/xlog.c | 78 ++++++++++++++++++--------
src/backend/access/transam/xlogarchive.c | 6 +-
src/backend/access/transam/xlogfuncs.c | 8 ++-
src/backend/access/transam/xlogutils.c | 43 +++++++-------
src/backend/replication/logical/logicalfuncs.c | 2 +-
src/backend/replication/logical/worker.c | 2 +-
src/backend/replication/slotfuncs.c | 2 +-
src/backend/replication/walreceiver.c | 54 ++++++++++--------
src/backend/replication/walsender.c | 77 ++++++++++++-------------
src/include/access/xlog.h | 9 ++-
src/include/access/xlogarchive.h | 2 +-
src/include/access/xlogutils.h | 4 +-
13 files changed, 169 insertions(+), 132 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Robert Haas 2021-11-05 16:55:52 pgsql: Change ThisTimeLineID from a global variable to a local variable
Previous Message Robert Haas 2021-11-05 16:49:28 pgsql: Don't set ThisTimeLineID when there's no reason to do so.