walsender.c: Don't rely on the global variable ThisTimeLineID.
authorRobert Haas <rhaas@postgresql.org>
Fri, 29 Oct 2021 20:55:04 +0000 (16:55 -0400)
committerRobert Haas <rhaas@postgresql.org>
Fri, 29 Oct 2021 21:05:21 +0000 (17:05 -0400)
commit9cd558add3c2d0fe68a77263c3ecaa38d0b09c27
tree541708e7c0a7bc3567d494fd5c9fd177b107b922
parentc00f605ab03aec7df21eff0f098751837f2ba935
walsender.c: Don't rely on the global variable ThisTimeLineID.

IdentifySystem(), StartReplication(), and read_local_xlog_page() rely
on xlog.c to set ThisTimeLineID to the current timeline ID when not in
recovery; and when in recovery, they set ThisTimeLineID themsleves.
Instead, have them rely on only on local variables.  When not in
recovery, they now obtain the current timeline via GetFlushRecPtr(),
and when in recovery, they obtain it just as they did before.  As part
of this change, GetStandbyFlushRecPtr() now returns the TLI via an out
parameter rather than storing it into ThisTimeLineID.

logical_read_xlog_page() and ReadReplicationSlot() rely on
ThisTimeLineID to determine the current timeline, but only when
in normal running, since ReadReplicationSlot() uses an another
method when in recovery, and logical_read_xlog_page() can't run
during recovery. Use GetWALInsertionTimeLine() instead, and add
some comments highlighting the need for logical_read_xlog_page()
to be changed if we ever want to run logical decoding on standbys.

Because read_local_xlog_page() and logical_read_xlog_page() both
call XLogReadDetermineTimeline() which considers ThisTimeLineID
as a sort of implicit argument, update that function to take
the current system timeline as an explicit argument instead.

Remove the logic in XlogReadTwoPhaseData() which saves and restores
the value of ThisTimeLineID. Since the walsender.c functions are
no longer changing it, this isn't required any more.
src/backend/access/transam/twophase.c
src/backend/access/transam/xlogutils.c
src/backend/replication/walsender.c
src/include/access/xlogutils.h