pgsql: Wake standby_write/standby_flush waiters from the WAL replay loo - Mailing list pgsql-committers

From Alexander Korotkov
Subject pgsql: Wake standby_write/standby_flush waiters from the WAL replay loo
Date
Msg-id E1wJWm6-000Cx4-0x@gemulon.postgresql.org
Whole thread
List pgsql-committers
Wake standby_write/standby_flush waiters from the WAL replay loop

The startup process only woke STANDBY_REPLAY waiters after replaying
each WAL record. STANDBY_WRITE and STANDBY_FLUSH waiters depended only
on walreceiver write/flush callbacks. As a result, replay progress alone
did not wake those waiters, and in pure archive recovery (where no
walreceiver exists) they could sleep until timeout.

Fix by also calling WaitLSNWakeup() for STANDBY_WRITE and
STANDBY_FLUSH after each replay. For the replay-floor semantics used by
GetCurrentLSNForWaitType(), replay progress is a valid lower bound for
both modes: WAL cannot be replayed unless it has already been written
and flushed locally.

This works together with the replay-position floor in
GetCurrentLSNForWaitType(). The getter ensures that a waiter woken by
replay can recheck successfully; the replay-side wakeups ensure that a
waiter already asleep is notified when replay reaches its target.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/1957514.1775526774%40sss.pgh.pa.us
Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e7cd592174d94f9aea197edc5f0c6f708df27271

Modified Files
--------------
src/backend/access/transam/xlogrecovery.c | 10 ++++-
src/test/recovery/t/049_wait_for_lsn.pl   | 64 +++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 2 deletions(-)


pgsql-committers by date:

Previous
From: Andrew Dunstan
Date:
Subject: pgsql: Add missing connection validation in ECPG
Next
From: Alexander Korotkov
Date:
Subject: pgsql: Mark modified the FSM buffer as dirty during recovery