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.