Don't set ThisTimeLineID when there's no reason to do so.
authorRobert Haas <[email protected]>
Wed, 27 Oct 2021 21:03:44 +0000 (17:03 -0400)
committerRobert Haas <[email protected]>
Fri, 29 Oct 2021 18:58:20 +0000 (14:58 -0400)
In slotfuncs.c, pg_replication_slot_advance() needs to determine
the LSN up to which the slot should be advanced, but that doesn't
require us to update ThisTimeLineID, because none of the code called
from here depends on it. If the replication slot is logical,
pg_logical_replication_slot_advance will call read_local_xlog_page,
which does use ThisTimeLineID, but also takes care of making sure
it's up to date. If the replication slot is physical, the timeline
isn't used for anything at all.

In logicalfuncs.c, pg_logical_slot_get_changes_guts() has the same
issue: the only code we're going to run that cares about timelines
is in or downstream of read_local_xlog_page, which already makes
sure that the correct value gets set. Hence, don't do it here.

src/backend/replication/logical/logicalfuncs.c
src/backend/replication/slotfuncs.c

index e59939aad110106e9150ef68dbc8c7306c872344..5a7fae4a87d3a954a231d1320b2cd0469b9a856e 100644 (file)
@@ -208,13 +208,12 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin
        rsinfo->setDesc = p->tupdesc;
 
        /*
-        * Compute the current end-of-wal and maintain ThisTimeLineID.
-        * RecoveryInProgress() will update ThisTimeLineID on promotion.
+        * Compute the current end-of-wal.
         */
        if (!RecoveryInProgress())
                end_of_wal = GetFlushRecPtr();
        else
-               end_of_wal = GetXLogReplayRecPtr(&ThisTimeLineID);
+               end_of_wal = GetXLogReplayRecPtr(NULL);
 
        ReplicationSlotAcquire(NameStr(*name), true);
 
index 17df99c2aceaedfd1a781c04b781405cf3347ca5..877a006d50332bb8b4e4e7375864dcfe04b7e495 100644 (file)
@@ -627,7 +627,7 @@ pg_replication_slot_advance(PG_FUNCTION_ARGS)
        if (!RecoveryInProgress())
                moveto = Min(moveto, GetFlushRecPtr());
        else
-               moveto = Min(moveto, GetXLogReplayRecPtr(&ThisTimeLineID));
+               moveto = Min(moveto, GetXLogReplayRecPtr(NULL));
 
        /* Acquire the slot so we "own" it */
        ReplicationSlotAcquire(NameStr(*slotname), true);