PostgreSQL Source Code git master
xlogwait.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * xlogwait.h
4 * Declarations for LSN replay waiting routines.
5 *
6 * Copyright (c) 2025, 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 WAIT_LSN_TYPE_REPLAY = 0, /* Waiting for replay on standby */
39 WAIT_LSN_TYPE_FLUSH = 1, /* Waiting for flush on primary */
42
43/*
44 * WaitLSNProcInfo - the shared memory structure representing information
45 * about the single process, which may wait for LSN operations. An item of
46 * waitLSNState->procInfos array.
47 */
48typedef struct WaitLSNProcInfo
49{
50 /* LSN, which this process is waiting for */
52
53 /* The type of LSN to wait */
55
56 /* Process to wake up once the waitLSN is reached */
58
59 /*
60 * Heap membership flag. A process can wait for only one LSN type at a
61 * time, so a single flag suffices (tracked by the lsnType field).
62 */
63 bool inHeap;
64
65 /* Pairing heap node for the waiters' heap (one per process) */
68
69/*
70 * WaitLSNState - the shared memory state for the LSN waiting facility.
71 */
72typedef struct WaitLSNState
73{
74 /*
75 * The minimum LSN values some process is waiting for. Used for the
76 * fast-path checking if we need to wake up any waiters after replaying a
77 * WAL record. Could be read lock-less. Update protected by WaitLSNLock.
78 */
80
81 /*
82 * A pairing heaps of waiting processes ordered by LSN values (least LSN
83 * is on top). Protected by WaitLSNLock.
84 */
86
87 /*
88 * An array with per-process information, indexed by the process number.
89 * Protected by WaitLSNLock.
90 */
93
94
96
97extern Size WaitLSNShmemSize(void);
98extern void WaitLSNShmemInit(void);
99extern void WaitLSNWakeup(WaitLSNType lsnType, XLogRecPtr currentLSN);
100extern void WaitLSNCleanup(void);
101extern WaitLSNResult WaitForLSN(WaitLSNType lsnType, XLogRecPtr targetLSN,
102 int64 timeout);
103
104#endif /* XLOG_WAIT_H */
#define PGDLLIMPORT
Definition: c.h:1320
int64_t int64
Definition: c.h:540
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:475
size_t Size
Definition: c.h:615
int ProcNumber
Definition: procnumber.h:24
ProcNumber procno
Definition: xlogwait.h:57
pairingheap_node heapNode
Definition: xlogwait.h:66
XLogRecPtr waitLSN
Definition: xlogwait.h:51
WaitLSNType lsnType
Definition: xlogwait.h:54
WaitLSNProcInfo procInfos[FLEXIBLE_ARRAY_MEMBER]
Definition: xlogwait.h:91
pg_atomic_uint64 minWaitedLSN[WAIT_LSN_TYPE_COUNT]
Definition: xlogwait.h:79
pairingheap waitersHeap[WAIT_LSN_TYPE_COUNT]
Definition: xlogwait.h:85
uint64 XLogRecPtr
Definition: xlogdefs.h:21
void WaitLSNShmemInit(void)
Definition: xlogwait.c:78
void WaitLSNCleanup(void)
Definition: xlogwait.c:290
PGDLLIMPORT WaitLSNState * waitLSNState
Definition: xlogwait.c:63
WaitLSNResult WaitForLSN(WaitLSNType lsnType, XLogRecPtr targetLSN, int64 timeout)
Definition: xlogwait.c:314
struct WaitLSNProcInfo WaitLSNProcInfo
struct WaitLSNState WaitLSNState
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_COUNT
Definition: xlogwait.h:40
@ WAIT_LSN_TYPE_FLUSH
Definition: xlogwait.h:39
@ WAIT_LSN_TYPE_REPLAY
Definition: xlogwait.h:38
void WaitLSNWakeup(WaitLSNType lsnType, XLogRecPtr currentLSN)
Definition: xlogwait.c:269
Size WaitLSNShmemSize(void)
Definition: xlogwait.c:67