PostgreSQL Source Code  git master
waitlsn.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * waitlsn.h
4  * Declarations for LSN replay waiting routines.
5  *
6  * Copyright (c) 2024, PostgreSQL Global Development Group
7  *
8  * src/include/commands/waitlsn.h
9  *
10  *-------------------------------------------------------------------------
11  */
12 #ifndef WAIT_LSN_H
13 #define WAIT_LSN_H
14 
15 #include "lib/pairingheap.h"
16 #include "postgres.h"
17 #include "port/atomics.h"
18 #include "storage/latch.h"
19 #include "storage/spin.h"
20 #include "tcop/dest.h"
21 
22 /*
23  * WaitLSNProcInfo - the shared memory structure representing information
24  * about the single process, which may wait for LSN replay. An item of
25  * waitLSN->procInfos array.
26  */
27 typedef struct WaitLSNProcInfo
28 {
29  /* LSN, which this process is waiting for */
31 
32  /*
33  * A pointer to the latch, which should be set once the waitLSN is
34  * replayed.
35  */
37 
38  /* A pairing heap node for participation in waitLSNState->waitersHeap */
40 
41  /*
42  * A flag indicating that this item is present in
43  * waitLSNState->waitersHeap
44  */
45  bool inHeap;
47 
48 /*
49  * WaitLSNState - the shared memory state for the replay LSN waiting facility.
50  */
51 typedef struct WaitLSNState
52 {
53  /*
54  * The minimum LSN value some process is waiting for. Used for the
55  * fast-path checking if we need to wake up any waiters after replaying a
56  * WAL record. Could be read lock-less. Update protected by WaitLSNLock.
57  */
59 
60  /*
61  * A pairing heap of waiting processes order by LSN values (least LSN is
62  * on top). Protected by WaitLSNLock.
63  */
65 
66  /*
67  * An array with per-process information, indexed by the process number.
68  * Protected by WaitLSNLock.
69  */
72 
74 
75 extern Size WaitLSNShmemSize(void);
76 extern void WaitLSNShmemInit(void);
77 extern void WaitLSNSetLatches(XLogRecPtr currentLSN);
78 extern void WaitLSNCleanup(void);
79 extern void WaitForLSNReplay(XLogRecPtr targetLSN, int64 timeout);
80 
81 #endif /* WAIT_LSN_H */
#define PGDLLIMPORT
Definition: c.h:1307
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:401
size_t Size
Definition: c.h:596
Definition: latch.h:113
pairingheap_node phNode
Definition: waitlsn.h:39
XLogRecPtr waitLSN
Definition: waitlsn.h:30
Latch * latch
Definition: waitlsn.h:36
WaitLSNProcInfo procInfos[FLEXIBLE_ARRAY_MEMBER]
Definition: waitlsn.h:70
pairingheap waitersHeap
Definition: waitlsn.h:64
pg_atomic_uint64 minWaitedLSN
Definition: waitlsn.h:58
void WaitLSNShmemInit(void)
Definition: waitlsn.c:52
void WaitForLSNReplay(XLogRecPtr targetLSN, int64 timeout)
Definition: waitlsn.c:221
void WaitLSNCleanup(void)
Definition: waitlsn.c:204
PGDLLIMPORT WaitLSNState * waitLSNState
Definition: waitlsn.c:37
struct WaitLSNProcInfo WaitLSNProcInfo
struct WaitLSNState WaitLSNState
Size WaitLSNShmemSize(void)
Definition: waitlsn.c:41
void WaitLSNSetLatches(XLogRecPtr currentLSN)
Definition: waitlsn.c:155
uint64 XLogRecPtr
Definition: xlogdefs.h:21