pgsql: Add infrastructure for efficient LSN waiting

Поиск
Список
Период
Сортировка
Искать

pgsql: Add infrastructure for efficient LSN waiting

От:
Alexander Korotkov <akorotkov@postgresql.org>
Дата:
Add infrastructure for efficient LSN waiting

Implement a new facility that allows processes to wait for WAL to reach
specific LSNs, both on primary (waiting for flush) and standby (waiting
for replay) servers.

The implementation uses shared memory with per-backend information
organized into pairing heaps, allowing O(1) access to the minimum
waited LSN. This enables fast-path checks: after replaying or flushing
WAL, the startup process or WAL writer can quickly determine if any
waiters need to be awakened.

Key components:
- New xlogwait.c/h module with WaitForLSNReplay() and WaitForLSNFlush()
- Separate pairing heaps for replay and flush waiters
- WaitLSN lightweight lock for coordinating shared state
- Wait events WAIT_FOR_WAL_REPLAY and WAIT_FOR_WAL_FLUSH for monitoring

This infrastructure can be used by features that need to wait for WAL
operations to complete.

Discussion: https://www.postgresql.org/message-id/flat/CAPpHfdsjtZLVzxjGT8rJHCYbM0D5dwkO+BBjcirozJ6nYbOW8Q@mail.gmail.com
Discussion: https://www.postgresql.org/message-id/flat/CABPTF7UNft368x-RgOXkfj475OwEbp%2BVVO-wEXz7StgjD_%3D6sw%40mail.gmail.com
Author: Kartyshov Ivan 
Author: Alexander Korotkov 
Author: Xuneng Zhou 
Reviewed-by: Michael Paquier 
Reviewed-by: Peter Eisentraut 
Reviewed-by: Dilip Kumar 
Reviewed-by: Amit Kapila 
Reviewed-by: Alexander Lakhin 
Reviewed-by: Bharath Rupireddy 
Reviewed-by: Euler Taveira 
Reviewed-by: Heikki Linnakangas 
Reviewed-by: Kyotaro Horiguchi 
Reviewed-by: Xuneng Zhou 

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3b4e53a075ea5671b075f8fd873241179f8e64af

Modified Files
--------------
src/backend/access/transam/Makefile             |   3 +-
src/backend/access/transam/meson.build          |   1 +
src/backend/access/transam/xlogwait.c           | 409 ++++++++++++++++++++++++
src/backend/storage/ipc/ipci.c                  |   3 +
src/backend/utils/activity/wait_event_names.txt |   3 +
src/include/access/xlogwait.h                   |  98 ++++++
src/include/storage/lwlocklist.h                |   1 +
src/tools/pgindent/typedefs.list                |   4 +
8 files changed, 521 insertions(+), 1 deletion(-)

FAQ