Skip to content

XLog: Expose WAL replay progress test [PG17] #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: REL_17_STABLE_neon
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions src/backend/access/transam/xlogrecovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand Down Expand Up @@ -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));

Expand Down
1 change: 1 addition & 0 deletions src/include/access/xlogrecovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down