pgsql: Wake primary_flush waiters after implicit WAL flushes

Started by Alexander Korotkov3 months ago1 messagescommitters
Jump to latest
#1Alexander Korotkov
akorotkov@postgresql.org

Wake primary_flush waiters after implicit WAL flushes

XLogWrite() can advance the flush position when it finishes a WAL
segment, even if its caller requested only a write. When this happens
while AdvanceXLInsertBuffer() recycles a buffer, primary_flush waiters
are not notified and can sleep until an unrelated flush or checkpoint.

Track such progress with a process-local pending flag and perform the
wakeup after releasing WAL write and insertion locks, keeping
WaitLSNLock acquisition outside the contended WAL path. Add a
deterministic injection-point test that forces this path and inspects
the registration directly in shared memory.

Author: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: /messages/by-id/CABPTF7U0gW5+-4oL7-qdML-yerZxUb7ku4QXp7JxCYo0qyJ_Tw@mail.gmail.com
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Backpatch-through: 19

Branch
------
master

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

Modified Files
--------------
src/backend/access/transam/xlog.c | 34 ++++++++
src/backend/access/transam/xlogwait.c | 3 +
src/backend/postmaster/walwriter.c | 3 +
src/test/recovery/t/049_wait_for_lsn.pl | 146 ++++++++++++++++++++++++++++++++
4 files changed, 186 insertions(+)