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

Commit 75a1926

Browse files
Maintain ThisTimeLineID correctly in checkpointer
checkpointer needs to reset ThisTimeLineID after a restartpoint to allow installing/recycling new WAL files. If recovery has already ended this would leave ThisTimeLineID set incorrectly and so we must reset it otherwise later checkpoints do not have the correct timeline. Bug report by Heikki Linnakangas. Further investigation by Heikki and myself.
1 parent 8955dac commit 75a1926

File tree

1 file changed

+26
-0
lines changed
  • src/backend/access/transam

1 file changed

+26
-0
lines changed

src/backend/access/transam/xlog.c

+26
Original file line numberDiff line numberDiff line change
@@ -5970,6 +5970,17 @@ StartupXLOG(void)
59705970
if (record != NULL)
59715971
{
59725972
fast_promoted = true;
5973+
5974+
/*
5975+
* Insert a special WAL record to mark the end of recovery,
5976+
* since we aren't doing a checkpoint. That means that the
5977+
* checkpointer process may likely be in the middle of a
5978+
* time-smoothed restartpoint and could continue to be for
5979+
* minutes after this. That sounds strange, but the effect
5980+
* is roughly the same and it would be stranger to try to
5981+
* come out of the restartpoint and then checkpoint.
5982+
* We request a checkpoint later anyway, just for safety.
5983+
*/
59735984
CreateEndOfRecoveryRecord();
59745985
}
59755986
}
@@ -7465,7 +7476,16 @@ CreateRestartPoint(int flags)
74657476
* after this, the pre-allocated WAL segments on this timeline will
74667477
* not be used, and will go wasted until recycled on the next
74677478
* restartpoint. We'll live with that.
7479+
*
7480+
* It's possible or perhaps even likely that we finish recovery while
7481+
* a restartpoint is in progress. That means we may get to this point
7482+
* some minutes afterwards. Setting ThisTimeLineID at that time would
7483+
* actually set it backwards, so we don't want that to persist; if
7484+
* we do reset it here, make sure to reset it back afterwards. This
7485+
* doesn't look very clean or principled, but its the best of about
7486+
* five different ways of handling this edge case.
74687487
*/
7488+
if (RecoveryInProgress())
74697489
(void) GetXLogReplayRecPtr(&ThisTimeLineID);
74707490

74717491
RemoveOldXlogFiles(_logSegNo, endptr);
@@ -7475,6 +7495,12 @@ CreateRestartPoint(int flags)
74757495
* segments, since that may supply some of the needed files.)
74767496
*/
74777497
PreallocXlogFiles(endptr);
7498+
7499+
/*
7500+
* Reset this always, in case we set ThisTimeLineID backwards above.
7501+
* Requires no locking; see InitXLOGAccess()
7502+
*/
7503+
ThisTimeLineID = XLogCtl->ThisTimeLineID;
74787504
}
74797505

74807506
/*

0 commit comments

Comments
 (0)