postgresql/src/include/access
Alexander Korotkov 3b4e53a075 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 <i.kartyshov@postgrespro.ru>
Author: Alexander Korotkov <aekorotkov@gmail.com>
Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Alexander Lakhin <exclusion@gmail.com>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Euler Taveira <euler@eulerto.com>
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
2025-11-05 11:44:13 +02:00
..
amapi.h Do a tiny bit of header file maintenance 2025-09-30 12:28:29 +02:00
amvalidate.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
attmap.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
attnum.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
brin.h Don't include execnodes.h in brin.h or gin.h 2025-10-05 17:35:25 +02:00
brin_internal.h Update some more forward declarations to use typedef 2025-09-25 14:33:19 +02:00
brin_page.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
brin_pageops.h Add some const qualifications 2025-10-27 09:55:59 +01:00
brin_revmap.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
brin_tuple.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
brin_xlog.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
bufmask.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
clog.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
cmptype.h Convert strategies to and from compare types 2025-02-02 10:26:04 +01:00
commit_ts.h Remove leftover dead code from commit_ts.h. 2025-07-03 23:39:45 +09:00
detoast.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
genam.h Do a tiny bit of header file maintenance 2025-09-30 12:28:29 +02:00
generic_xlog.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
gin.h Don't include execnodes.h in brin.h or gin.h 2025-10-05 17:35:25 +02:00
gin_private.h Fix some confusing uses of const 2025-10-30 11:20:04 +01:00
gin_tuple.h Fix various incorrect filename references 2025-09-22 13:33:17 +12:00
ginblock.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
ginxlog.h Add comment in ginxlog.h about block used with ginxlogInsertListPage 2025-10-06 16:23:51 +09:00
gist.h Rename gist stratnum support function 2025-06-02 08:41:27 +02:00
gist_private.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
gistscan.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
gistxlog.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
hash.h Mark function arguments of type "Datum *" as "const Datum *" where possible 2025-10-31 10:47:25 +01:00
hash_xlog.h Fix description of WAL record blocks in hash_xlog.h 2025-09-11 17:17:04 +09:00
heapam.h Mark ItemPointer arguments as const throughout 2025-10-30 14:12:06 +01:00
heapam_xlog.h Eliminate XLOG_HEAP2_VISIBLE from vacuum phase III 2025-10-13 18:01:06 -04:00
heaptoast.h Mark function arguments of type "Datum *" as "const Datum *" where possible 2025-10-31 10:47:25 +01:00
hio.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
htup.h Remove PointerIsValid() 2025-09-24 15:17:20 +02:00
htup_details.h Fix type of infomask parameter in htup_details.h functions. 2025-10-22 16:47:38 -05:00
itup.h Remove PointerIsValid() 2025-09-24 15:17:20 +02:00
multixact.h Refactor ReadMultiXactCounts() into GetMultiXactInfo() 2025-08-19 14:04:09 +09:00
nbtree.h Mark ItemPointer arguments as const throughout 2025-10-30 14:12:06 +01:00
nbtxlog.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
parallel.h Rename some signal and interrupt handling functions for consistency 2025-03-05 16:22:26 +02:00
printsimple.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
printtup.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
relation.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
reloptions.h Rename transformRelOptions()'s "namspace" parameter to "nameSpace". 2025-08-06 12:08:07 -05:00
relscan.h Show index search count in EXPLAIN ANALYZE, take 2. 2025-03-11 09:20:50 -04:00
rewriteheap.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
rmgr.h Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
rmgrdesc_utils.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
rmgrlist.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
sdir.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
sequence.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
session.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
skey.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
slru.h Update outdated references to the SLRU ControlLock 2025-09-03 10:20:28 +09:00
spgist.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
spgist_private.h Mark function arguments of type "Datum *" as "const Datum *" where possible 2025-10-31 10:47:25 +01:00
spgxlog.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
stratnum.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
subtrans.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
syncscan.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
sysattr.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
table.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
tableam.h Update some more forward declarations to use typedef 2025-09-25 14:33:19 +02:00
tidstore.h Mark ItemPointer arguments as const throughout 2025-10-30 14:12:06 +01:00
timeline.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
toast_compression.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
toast_helper.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
toast_internals.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
transam.h Inline TransactionIdFollows/Precedes[OrEquals]() 2025-10-14 17:03:48 -04:00
tsmapi.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
tupconvert.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
tupdesc.h Allow NOT NULL constraints to be added as NOT VALID 2025-04-07 19:19:50 +02:00
tupdesc_details.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
tupmacs.h Grab the low-hanging fruit from forcing sizeof(Datum) to 8. 2025-08-13 17:18:22 -04:00
twophase.h Post-commit review fixes for 228c370868. 2025-09-08 06:10:15 +00:00
twophase_rmgr.h Integrate FullTransactionIds deeper into two-phase code 2025-07-07 12:50:40 +09:00
valid.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
visibilitymap.h Eliminate COPY FREEZE use of XLOG_HEAP2_VISIBLE 2025-10-09 16:29:01 -04:00
visibilitymapdefs.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
xact.h Improve comment about snapshot macros 2025-09-11 19:49:57 +02:00
xlog.h Fix unconditional WAL receiver shutdown during stream-archive transition 2025-11-04 10:47:38 +09:00
xlog_internal.h Bump XLOG_PAGE_MAGIC after xl_heap_prune change 2025-10-14 10:13:10 -04:00
xlogarchive.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
xlogbackup.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
xlogdefs.h Fix incorrect LSN format in comment. 2025-08-14 11:12:03 +09:00
xloginsert.h Refactor some repetitive SLRU code 2025-07-07 16:49:19 +02:00
xlogprefetcher.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
xlogreader.h Remove unused data_bufsz from DecodedBkpBlock struct. 2025-10-17 11:28:54 -07:00
xlogrecord.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
xlogrecovery.h Move enum RecoveryTargetAction to xlogrecovery.h 2025-07-23 11:02:13 +02:00
xlogstats.h Fix two typos in xlogstats.h and xlogstats.c 2025-10-10 11:51:45 +09:00
xlogutils.h Update copyright for 2025 2025-01-01 11:21:55 -05:00
xlogwait.h Add infrastructure for efficient LSN waiting 2025-11-05 11:44:13 +02:00