diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c index e1027b137b9..50b792e08d1 100644 --- a/src/backend/access/transam/xlogrecovery.c +++ b/src/backend/access/transam/xlogrecovery.c @@ -491,35 +491,53 @@ EnableStandbyMode(void) disable_startup_progress_timeout(); } +static XLogRecPtr replayRecPtr = InvalidXLogRecPtr; + /* - * Wait for recovery to complete replaying all WAL up to and including - * redoEndRecPtr. + * Check if a record at given LSN has been replayed yet. * - * This gets woken up for every WAL record replayed, so make sure you're not - * trying to wait an LSN that is too far in the future. + * Always returns TRUE when not in recovery mode. */ -void -XLogWaitForReplayOf(XLogRecPtr redoEndRecPtr) +bool +XLogRecordReplayFinished(XLogRecPtr redoEndRecPtr) { - static XLogRecPtr replayRecPtr = 0; - if (!RecoveryInProgress()) - return; + return true; /* * Check the backend-local variable first, we may be able to skip accessing * shared memory (which requires locking) */ if (redoEndRecPtr <= replayRecPtr) - return; + return true; + /* update the backend-local cache with more up-to-date values */ replayRecPtr = GetXLogReplayRecPtr(NULL); + return redoEndRecPtr <= replayRecPtr; +} + +/* + * Wait for recovery to complete replaying all WAL up to and including + * redoEndRecPtr. + * + * This gets woken up for every WAL record replayed, so make sure you're not + * trying to wait an LSN that is too far in the future. + */ +void +XLogWaitForReplayOf(XLogRecPtr redoEndRecPtr) +{ + if (!RecoveryInProgress()) + return; + /* - * Check again if we're going to need to wait, now that we've updated - * the local cached variable. + * Check if the record has been replayed yet. This includes up-to-date + * information about current replay state - if it hasn't been replayed, + * we're probably going to have to wait. + * + * This also returns if we're not in recovery mode. */ - if (redoEndRecPtr <= replayRecPtr) + if (XLogRecordReplayFinished(redoEndRecPtr)) return; /* @@ -776,11 +794,7 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr, CheckPointLoc = zenithLastRec; CheckPointTLI = ControlFile->checkPointCopy.ThisTimeLineID; RedoStartLSN = ControlFile->checkPointCopy.redo; - // FIXME needs review. rebase of ff41b709abea6a9c42100a4fcb0ff434b2c846c9 - // Is it still relevant? - /* make basebackup LSN available for walproposer */ SetRedoStartLsn(RedoStartLSN); - //EndRecPtr = ControlFile->checkPointCopy.redo; memcpy(&checkPoint, &ControlFile->checkPointCopy, sizeof(CheckPoint)); diff --git a/src/include/access/xlogrecovery.h b/src/include/access/xlogrecovery.h index aa1b1be0a94..2c55eaec038 100644 --- a/src/include/access/xlogrecovery.h +++ b/src/include/access/xlogrecovery.h @@ -137,6 +137,7 @@ extern void ShutdownWalRecovery(void); extern void RemovePromoteSignalFiles(void); extern bool HotStandbyActive(void); +extern bool XLogRecordReplayFinished(XLogRecPtr redoEndRecPtr); extern void XLogWaitForReplayOf(XLogRecPtr redoEndRecPtr); extern XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI); extern RecoveryPauseState GetRecoveryPauseState(void);