PostgreSQL Source Code  git master
walsender_private.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * walsender_private.h
4  * Private definitions from replication/walsender.c.
5  *
6  * Portions Copyright (c) 2010-2024, PostgreSQL Global Development Group
7  *
8  * src/include/replication/walsender_private.h
9  *
10  *-------------------------------------------------------------------------
11  */
12 #ifndef _WALSENDER_PRIVATE_H
13 #define _WALSENDER_PRIVATE_H
14 
15 #include "access/xlog.h"
16 #include "lib/ilist.h"
17 #include "nodes/nodes.h"
18 #include "nodes/replnodes.h"
19 #include "replication/syncrep.h"
21 #include "storage/shmem.h"
22 #include "storage/spin.h"
23 
24 typedef enum WalSndState
25 {
32 
33 /*
34  * Each walsender has a WalSnd struct in shared memory.
35  *
36  * This struct is protected by its 'mutex' spinlock field, except that some
37  * members are only written by the walsender process itself, and thus that
38  * process is free to read those members without holding spinlock. pid and
39  * needreload always require the spinlock to be held for all accesses.
40  */
41 typedef struct WalSnd
42 {
43  pid_t pid; /* this walsender's PID, or 0 if not active */
44 
45  WalSndState state; /* this walsender's state */
46  XLogRecPtr sentPtr; /* WAL has been sent up to this point */
47  bool needreload; /* does currently-open file need to be
48  * reloaded? */
49 
50  /*
51  * The xlog locations that have been written, flushed, and applied by
52  * standby-side. These may be invalid if the standby-side has not offered
53  * values yet.
54  */
58 
59  /* Measured lag times, or -1 for unknown/none. */
63 
64  /*
65  * The priority order of the standby managed by this WALSender, as listed
66  * in synchronous_standby_names, or 0 if not-listed.
67  */
69 
70  /* Protects shared variables in this structure. */
71  slock_t mutex;
72 
73  /*
74  * Timestamp of the last message received from standby.
75  */
77 
80 
82 
83 /* There is one WalSndCtl struct for the whole database cluster */
84 typedef struct
85 {
86  /*
87  * Synchronous replication queue with one queue per request type.
88  * Protected by SyncRepLock.
89  */
91 
92  /*
93  * Current location of the head of the queue. All waiters should have a
94  * waitLSN that follows this value. Protected by SyncRepLock.
95  */
97 
98  /*
99  * Are any sync standbys defined? Waiting backends can't reload the
100  * config file safely, so checkpointer updates this value as needed.
101  * Protected by SyncRepLock.
102  */
104 
105  /* used as a registry of physical / logical walsenders to wake */
108 
109  /*
110  * Used by physical walsenders holding slots specified in
111  * synchronized_standby_slots to wake up logical walsenders holding
112  * logical failover slots when a walreceiver confirms the receipt of LSN.
113  */
115 
117 } WalSndCtlData;
118 
120 
121 
122 extern void WalSndSetState(WalSndState state);
123 
124 /*
125  * Internal functions for parsing the replication grammar, in repl_gram.y and
126  * repl_scanner.l
127  */
128 extern int replication_yyparse(void);
129 extern int replication_yylex(void);
130 extern void replication_yyerror(const char *message) pg_attribute_noreturn();
131 extern void replication_scanner_init(const char *str);
132 extern void replication_scanner_finish(void);
134 
136 
137 #endif /* _WALSENDER_PRIVATE_H */
#define PGDLLIMPORT
Definition: c.h:1274
#define pg_attribute_noreturn()
Definition: c.h:236
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:417
int64 TimestampTz
Definition: timestamp.h:39
int64 TimeOffset
Definition: timestamp.h:40
const char * str
ReplicationKind
Definition: replnodes.h:21
Definition: nodes.h:129
ConditionVariable wal_confirm_rcv_cv
ConditionVariable wal_replay_cv
ConditionVariable wal_flush_cv
TimeOffset writeLag
slock_t mutex
XLogRecPtr flush
XLogRecPtr sentPtr
TimeOffset flushLag
WalSndState state
ReplicationKind kind
XLogRecPtr write
TimeOffset applyLag
int sync_standby_priority
bool needreload
TimestampTz replyTime
XLogRecPtr apply
Definition: regguts.h:323
#define NUM_SYNC_REP_WAIT_MODE
Definition: syncrep.h:27
PGDLLIMPORT Node * replication_parse_result
WalSndState
@ WALSNDSTATE_STREAMING
@ WALSNDSTATE_BACKUP
@ WALSNDSTATE_CATCHUP
@ WALSNDSTATE_STARTUP
@ WALSNDSTATE_STOPPING
void replication_scanner_finish(void)
int replication_yyparse(void)
void WalSndSetState(WalSndState state)
Definition: walsender.c:3781
void replication_scanner_init(const char *str)
PGDLLIMPORT WalSndCtlData * WalSndCtl
Definition: walsender.c:109
struct WalSnd WalSnd
bool replication_scanner_is_replication_command(void)
void replication_yyerror(const char *message) pg_attribute_noreturn()
int replication_yylex(void)
PGDLLIMPORT WalSnd * MyWalSnd
Definition: walsender.c:112
uint64 XLogRecPtr
Definition: xlogdefs.h:21