Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4d894b4

Browse files
committed
Change the order that pg_xlog and WAL archive are polled for WAL segments.
If there is a WAL segment with same ID but different TLI present in both the WAL archive and pg_xlog, prefer the one with higher TLI. Before this patch, the archive was polled first, for all expected TLIs, and only if no file was found was pg_xlog scanned. This was a change in behavior from 9.3, which first scanned archive and pg_xlog for the highest TLI, then archive and pg_xlog for the next highest TLI and so forth. This patch reverts the behavior back to what it was in 9.2. The reason for this is that if for example you try to do archive recovery to timeline 2, which branched off timeline 1, but the WAL for timeline 2 is not archived yet, we would replay past the timeline switch point on timeline 1 using the archived files, before even looking timeline 2's files in pg_xlog Report and patch by Kyotaro Horiguchi. Backpatch to 9.3 where the behavior was changed.
1 parent 0f2ca00 commit 4d894b4

File tree

1 file changed

+10
-13
lines changed
  • src/backend/access/transam

1 file changed

+10
-13
lines changed

src/backend/access/transam/xlog.c

+10-13
Original file line numberDiff line numberDiff line change
@@ -11006,17 +11006,15 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
1100611006
/*-------
1100711007
* Standby mode is implemented by a state machine:
1100811008
*
11009-
* 1. Read from archive (XLOG_FROM_ARCHIVE)
11010-
* 2. Read from pg_xlog (XLOG_FROM_PG_XLOG)
11011-
* 3. Check trigger file
11012-
* 4. Read from primary server via walreceiver (XLOG_FROM_STREAM)
11013-
* 5. Rescan timelines
11014-
* 6. Sleep 5 seconds, and loop back to 1.
11009+
* 1. Read from either archive or pg_xlog (XLOG_FROM_ARCHIVE), or just
11010+
* pg_xlog (XLOG_FROM_XLOG)
11011+
* 2. Check trigger file
11012+
* 3. Read from primary server via walreceiver (XLOG_FROM_STREAM)
11013+
* 4. Rescan timelines
11014+
* 5. Sleep 5 seconds, and loop back to 1.
1101511015
*
1101611016
* Failure to read from the current source advances the state machine to
11017-
* the next state. In addition, successfully reading a file from pg_xlog
11018-
* moves the state machine from state 2 back to state 1 (we always prefer
11019-
* files in the archive over files in pg_xlog).
11017+
* the next state.
1102011018
*
1102111019
* 'currentSource' indicates the current state. There are no currentSource
1102211020
* values for "check trigger", "rescan timelines", and "sleep" states,
@@ -11044,9 +11042,6 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
1104411042
switch (currentSource)
1104511043
{
1104611044
case XLOG_FROM_ARCHIVE:
11047-
currentSource = XLOG_FROM_PG_XLOG;
11048-
break;
11049-
1105011045
case XLOG_FROM_PG_XLOG:
1105111046

1105211047
/*
@@ -11212,7 +11207,9 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
1121211207
* Try to restore the file from archive, or read an existing
1121311208
* file from pg_xlog.
1121411209
*/
11215-
readFile = XLogFileReadAnyTLI(readSegNo, DEBUG2, currentSource);
11210+
readFile = XLogFileReadAnyTLI(readSegNo, DEBUG2,
11211+
currentSource == XLOG_FROM_ARCHIVE ? XLOG_FROM_ANY :
11212+
currentSource);
1121611213
if (readFile >= 0)
1121711214
return true; /* success! */
1121811215

0 commit comments

Comments
 (0)