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