@@ -7463,39 +7463,35 @@ CreateRestartPoint(int flags)
74637463 {
74647464 XLogRecPtr receivePtr ;
74657465 XLogRecPtr replayPtr ;
7466+ TimeLineID replayTLI ;
74667467 XLogRecPtr endptr ;
74677468
74687469 /*
74697470 * Get the current end of xlog replayed or received, whichever is
74707471 * later.
74717472 */
74727473 receivePtr = GetWalRcvWriteRecPtr (NULL , NULL );
7473- replayPtr = GetXLogReplayRecPtr (NULL );
7474+ replayPtr = GetXLogReplayRecPtr (& replayTLI );
74747475 endptr = (receivePtr < replayPtr ) ? replayPtr : receivePtr ;
74757476
74767477 KeepLogSeg (endptr , & _logSegNo );
74777478 _logSegNo -- ;
74787479
74797480 /*
7480- * Update ThisTimeLineID to the timeline we're currently replaying, so
7481- * that we install any recycled segments on that timeline.
7481+ * Try to recycle segments on a useful timeline. If we've been promoted
7482+ * since the beginning of this restartpoint, use the new timeline
7483+ * chosen at end of recovery (RecoveryInProgress() sets ThisTimeLineID
7484+ * in that case). If we're still in recovery, use the timeline we're
7485+ * currently replaying.
74827486 *
74837487 * There is no guarantee that the WAL segments will be useful on the
74847488 * current timeline; if recovery proceeds to a new timeline right
74857489 * after this, the pre-allocated WAL segments on this timeline will
74867490 * not be used, and will go wasted until recycled on the next
74877491 * restartpoint. We'll live with that.
7488- *
7489- * It's possible or perhaps even likely that we finish recovery while
7490- * a restartpoint is in progress. That means we may get to this point
7491- * some minutes afterwards. Setting ThisTimeLineID at that time would
7492- * actually set it backwards, so we don't want that to persist; if we
7493- * do reset it here, make sure to reset it back afterwards. This
7494- * doesn't look very clean or principled, but its the best of about
7495- * five different ways of handling this edge case.
74967492 */
74977493 if (RecoveryInProgress ())
7498- ( void ) GetXLogReplayRecPtr ( & ThisTimeLineID ) ;
7494+ ThisTimeLineID = replayTLI ;
74997495
75007496 RemoveOldXlogFiles (_logSegNo , endptr );
75017497
@@ -7506,10 +7502,14 @@ CreateRestartPoint(int flags)
75067502 PreallocXlogFiles (endptr );
75077503
75087504 /*
7509- * Reset this always, in case we set ThisTimeLineID backwards above.
7510- * Requires no locking; see InitXLOGAccess()
7505+ * ThisTimeLineID is normally not set when we're still in recovery.
7506+ * However, recycling/preallocating segments above needed
7507+ * ThisTimeLineID to determine which timeline to install the segments
7508+ * on. Reset it now, to restore the normal state of affairs for
7509+ * debugging purposes.
75117510 */
7512- ThisTimeLineID = XLogCtl -> ThisTimeLineID ;
7511+ if (RecoveryInProgress ())
7512+ ThisTimeLineID = 0 ;
75137513 }
75147514
75157515 /*
0 commit comments