diff options
author | Simon Riggs <simon@2ndQuadrant.com> | 2017-03-22 07:05:12 +0000 |
---|---|---|
committer | Simon Riggs <simon@2ndQuadrant.com> | 2017-03-22 07:05:12 +0000 |
commit | 1148e22a82edc96172fc78855da392b6f0015c88 (patch) | |
tree | ba60e49124bf0eb9f003ee11f2d2a275dffddb1b /src/backend/replication/logical/logicalfuncs.c | |
parent | 9ca2dd578db4086ae8a6eb6fd82ac376b7b2804e (diff) | |
download | postgresql-1148e22a82edc96172fc78855da392b6f0015c88.tar.gz postgresql-1148e22a82edc96172fc78855da392b6f0015c88.zip |
Teach xlogreader to follow timeline switches
Uses page-based mechanism to ensure we’re using the correct timeline.
Tests are included to exercise the functionality using a cold disk-level copy
of the master that's started up as a replica with slots intact, but the
intended use of the functionality is with later features.
Craig Ringer, reviewed by Simon Riggs and Andres Freund
Diffstat (limited to 'src/backend/replication/logical/logicalfuncs.c')
-rw-r--r-- | src/backend/replication/logical/logicalfuncs.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c index 41c50005d7f..c251b92f57b 100644 --- a/src/backend/replication/logical/logicalfuncs.c +++ b/src/backend/replication/logical/logicalfuncs.c @@ -235,11 +235,14 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin rsinfo->setResult = p->tupstore; rsinfo->setDesc = p->tupdesc; - /* compute the current end-of-wal */ + /* + * Compute the current end-of-wal and maintain ThisTimeLineID. + * RecoveryInProgress() will update ThisTimeLineID on promotion. + */ if (!RecoveryInProgress()) end_of_wal = GetFlushRecPtr(); else - end_of_wal = GetXLogReplayRecPtr(NULL); + end_of_wal = GetXLogReplayRecPtr(&ThisTimeLineID); ReplicationSlotAcquire(NameStr(*name)); @@ -280,6 +283,7 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin /* invalidate non-timetravel entries */ InvalidateSystemCaches(); + /* Decode until we run out of records */ while ((startptr != InvalidXLogRecPtr && startptr < end_of_wal) || (ctx->reader->EndRecPtr != InvalidXLogRecPtr && ctx->reader->EndRecPtr < end_of_wal)) { |