On 05/11/2025 11:44, Alexander Korotkov wrote:
> Implement WAIT FOR command
Happened to just spot this:
> @@ -1831,20 +1832,30 @@ PerformWalRecovery(void)
> */
> ApplyWalRecord(xlogreader, record, &replayTLI);
>
> /* Exit loop if we reached inclusive recovery target */
> if (recoveryStopsAfter(xlogreader))
> {
> reachedRecoveryTarget = true;
> break;
> }
>
> + /*
> + * If we replayed an LSN that someone was waiting for then walk
> + * over the shared memory array and set latches to notify the
> + * waiters.
> + */
> + if (waitLSNState &&
> + (XLogRecoveryCtl->lastReplayedEndRecPtr >=
> + pg_atomic_read_u64(&waitLSNState->minWaitedLSN[WAIT_LSN_TYPE_REPLAY])))
> + WaitLSNWakeup(WAIT_LSN_TYPE_REPLAY, XLogRecoveryCtl->lastReplayedEndRecPtr);
> +
> /* Else, try to fetch the next WAL record */
> record = ReadRecord(xlogprefetcher, LOG, false, replayTLI);
> } while (record != NULL);
>
> /*
> * end of main redo apply loop
> */
>
> if (reachedRecoveryTarget)
> {
I think that WaitLSNWakeup() call is a little misplaced. It's after the
recoveryStopsAfter() call, so if recovery is paused right after the
record, the waiters won't be woken up until recovery is continued. And I
suppose if recovery is stopped and the server is promoted, the waiters
will never be woken up, although I didn't verify that.
To fix, that should be moved to between the ApplyWalRecord() and
recoveryStopsHere() calls.
- Heikki