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/latch.h"
22 #include "storage/shmem.h"
23 #include "storage/spin.h"
24 
25 typedef enum WalSndState
26 {
33 
34 /*
35  * Each walsender has a WalSnd struct in shared memory.
36  *
37  * This struct is protected by its 'mutex' spinlock field, except that some
38  * members are only written by the walsender process itself, and thus that
39  * process is free to read those members without holding spinlock. pid and
40  * needreload always require the spinlock to be held for all accesses.
41  */
42 typedef struct WalSnd
43 {
44  pid_t pid; /* this walsender's PID, or 0 if not active */
45 
46  WalSndState state; /* this walsender's state */
47  XLogRecPtr sentPtr; /* WAL has been sent up to this point */
48  bool needreload; /* does currently-open file need to be
49  * reloaded? */
50 
51  /*
52  * The xlog locations that have been written, flushed, and applied by
53  * standby-side. These may be invalid if the standby-side has not offered
54  * values yet.
55  */
59 
60  /* Measured lag times, or -1 for unknown/none. */
64 
65  /*
66  * The priority order of the standby managed by this WALSender, as listed
67  * in synchronous_standby_names, or 0 if not-listed.
68  */
70 
71  /* Protects shared variables in this structure. */
73 
74  /*
75  * Pointer to the walsender's latch. Used by backends to wake up this
76  * walsender when it has work to do. NULL if the walsender isn't active.
77  */
79 
80  /*
81  * Timestamp of the last message received from standby.
82  */
84 
87 
89 
90 /* There is one WalSndCtl struct for the whole database cluster */
91 typedef struct
92 {
93  /*
94  * Synchronous replication queue with one queue per request type.
95  * Protected by SyncRepLock.
96  */
98 
99  /*
100  * Current location of the head of the queue. All waiters should have a
101  * waitLSN that follows this value. Protected by SyncRepLock.
102  */
104 
105  /*
106  * Are any sync standbys defined? Waiting backends can't reload the
107  * config file safely, so checkpointer updates this value as needed.
108  * Protected by SyncRepLock.
109  */
111 
112  /* used as a registry of physical / logical walsenders to wake */
115 
116  /*
117  * Used by physical walsenders holding slots specified in
118  * standby_slot_names to wake up logical walsenders holding logical
119  * failover slots when a walreceiver confirms the receipt of LSN.
120  */
122 
124 } WalSndCtlData;
125 
127 
128 
129 extern void WalSndSetState(WalSndState state);
130 
131 /*
132  * Internal functions for parsing the replication grammar, in repl_gram.y and
133  * repl_scanner.l
134  */
135 extern int replication_yyparse(void);
136 extern int replication_yylex(void);
137 extern void replication_yyerror(const char *message) pg_attribute_noreturn();
138 extern void replication_scanner_init(const char *str);
139 extern void replication_scanner_finish(void);
141 
143 
144 #endif /* _WALSENDER_PRIVATE_H */
#define PGDLLIMPORT
Definition: c.h:1316
#define pg_attribute_noreturn()
Definition: c.h:217
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:398
int64 TimestampTz
Definition: timestamp.h:39
int64 TimeOffset
Definition: timestamp.h:40
const char * str
ReplicationKind
Definition: replnodes.h:21
int slock_t
Definition: s_lock.h:735
Definition: latch.h:113
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
Latch * latch
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:3809
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