PostgreSQL Source Code git master
Loading...
Searching...
No Matches
xlogwait.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * xlogwait.h
4 * Declarations for WAL flush, write, and replay waiting routines.
5 *
6 * Copyright (c) 2025-2026, PostgreSQL Global Development Group
7 *
8 * src/include/access/xlogwait.h
9 *
10 *-------------------------------------------------------------------------
11 */
12#ifndef XLOG_WAIT_H
13#define XLOG_WAIT_H
14
15#include "access/xlogdefs.h"
16#include "lib/pairingheap.h"
17#include "port/atomics.h"
18#include "storage/procnumber.h"
19#include "storage/spin.h"
20#include "tcop/dest.h"
21
22/*
23 * Result statuses for WaitForLSN().
24 */
25typedef enum
26{
27 WAIT_LSN_RESULT_SUCCESS, /* Target LSN is reached */
28 WAIT_LSN_RESULT_NOT_IN_RECOVERY, /* Recovery ended before or during our
29 * wait */
30 WAIT_LSN_RESULT_TIMEOUT /* Timeout occurred */
32
33/*
34 * LSN type for waiting facility.
35 */
36typedef enum WaitLSNType
37{
38 /* Standby wait types (walreceiver/startup wakes) */
42
43 /* Primary wait types (WAL writer/backends wake) */
46
47#define WAIT_LSN_TYPE_COUNT (WAIT_LSN_TYPE_PRIMARY_FLUSH + 1)
48
49/*
50 * WaitLSNProcInfo - the shared memory structure representing information
51 * about the single process, which may wait for LSN operations. An item of
52 * waitLSNState->procInfos array.
53 */
54typedef struct WaitLSNProcInfo
55{
56 /* LSN, which this process is waiting for */
58
59 /* The type of LSN to wait */
61
62 /* Process to wake up once the waitLSN is reached */
64
65 /*
66 * Heap membership flag. A process can wait for only one LSN type at a
67 * time, so a single flag suffices (tracked by the lsnType field).
68 */
69 bool inHeap;
70
71 /* Pairing heap node for the waiters' heap (one per process) */
74
75/*
76 * WaitLSNState - the shared memory state for the LSN waiting facility.
77 */
78typedef struct WaitLSNState
79{
80 /*
81 * The minimum LSN values some process is waiting for. Used for the
82 * fast-path checking if we need to wake up any waiters after replaying a
83 * WAL record. Could be read lock-less. Update protected by WaitLSNLock.
84 */
86
87 /*
88 * A pairing heaps of waiting processes ordered by LSN values (least LSN
89 * is on top). Protected by WaitLSNLock.
90 */
92
93 /*
94 * An array with per-process information, indexed by the process number.
95 * Protected by WaitLSNLock.
96 */
99
100
102
103extern Size WaitLSNShmemSize(void);
104extern void WaitLSNShmemInit(void);
106extern void WaitLSNWakeup(WaitLSNType lsnType, XLogRecPtr currentLSN);
107extern void WaitLSNCleanup(void);
109 int64 timeout);
110
111#endif /* XLOG_WAIT_H */
#define PGDLLIMPORT
Definition c.h:1328
int64_t int64
Definition c.h:553
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:490
size_t Size
Definition c.h:629
static int fb(int x)
int ProcNumber
Definition procnumber.h:24
ProcNumber procno
Definition xlogwait.h:63
pairingheap_node heapNode
Definition xlogwait.h:72
XLogRecPtr waitLSN
Definition xlogwait.h:57
WaitLSNType lsnType
Definition xlogwait.h:60
WaitLSNProcInfo procInfos[FLEXIBLE_ARRAY_MEMBER]
Definition xlogwait.h:97
pg_atomic_uint64 minWaitedLSN[WAIT_LSN_TYPE_COUNT]
Definition xlogwait.h:85
pairingheap waitersHeap[WAIT_LSN_TYPE_COUNT]
Definition xlogwait.h:91
uint64 XLogRecPtr
Definition xlogdefs.h:21
void WaitLSNShmemInit(void)
Definition xlogwait.c:124
void WaitLSNCleanup(void)
Definition xlogwait.c:338
PGDLLIMPORT WaitLSNState * waitLSNState
Definition xlogwait.c:68
#define WAIT_LSN_TYPE_COUNT
Definition xlogwait.h:47
XLogRecPtr GetCurrentLSNForWaitType(WaitLSNType lsnType)
Definition xlogwait.c:88
WaitLSNResult WaitForLSN(WaitLSNType lsnType, XLogRecPtr targetLSN, int64 timeout)
Definition xlogwait.c:375
WaitLSNResult
Definition xlogwait.h:26
@ WAIT_LSN_RESULT_NOT_IN_RECOVERY
Definition xlogwait.h:28
@ WAIT_LSN_RESULT_TIMEOUT
Definition xlogwait.h:30
@ WAIT_LSN_RESULT_SUCCESS
Definition xlogwait.h:27
WaitLSNType
Definition xlogwait.h:37
@ WAIT_LSN_TYPE_PRIMARY_FLUSH
Definition xlogwait.h:44
@ WAIT_LSN_TYPE_STANDBY_REPLAY
Definition xlogwait.h:39
@ WAIT_LSN_TYPE_STANDBY_FLUSH
Definition xlogwait.h:41
@ WAIT_LSN_TYPE_STANDBY_WRITE
Definition xlogwait.h:40
void WaitLSNWakeup(WaitLSNType lsnType, XLogRecPtr currentLSN)
Definition xlogwait.c:317
Size WaitLSNShmemSize(void)
Definition xlogwait.c:113