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-2019, 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 "nodes/nodes.h"
17 #include "replication/syncrep.h"
18 #include "storage/latch.h"
19 #include "storage/shmem.h"
20 #include "storage/spin.h"
21 
22 typedef enum WalSndState
23 {
29 } WalSndState;
30 
31 /*
32  * Each walsender has a WalSnd struct in shared memory.
33  *
34  * This struct is protected by 'mutex', with two exceptions: one is
35  * sync_standby_priority as noted below. The other exception is that some
36  * members are only written by the walsender process itself, and thus that
37  * process is free to read those members without holding spinlock. pid and
38  * needreload always require the spinlock to be held for all accesses.
39  */
40 typedef struct WalSnd
41 {
42  pid_t pid; /* this walsender's PID, or 0 if not active */
43 
44  WalSndState state; /* this walsender's state */
45  XLogRecPtr sentPtr; /* WAL has been sent up to this point */
46  bool needreload; /* does currently-open file need to be
47  * reloaded? */
48 
49  /*
50  * The xlog locations that have been written, flushed, and applied by
51  * standby-side. These may be invalid if the standby-side has not offered
52  * values yet.
53  */
57 
58  /* Measured lag times, or -1 for unknown/none. */
62 
63  /* Protects shared variables shown above. */
65 
66  /*
67  * Pointer to the walsender's latch. Used by backends to wake up this
68  * walsender when it has work to do. NULL if the walsender isn't active.
69  */
71 
72  /*
73  * The priority order of the standby managed by this WALSender, as listed
74  * in synchronous_standby_names, or 0 if not-listed. Protected by
75  * SyncRepLock.
76  */
78 
79  /*
80  * Timestamp of the last message received from standby.
81  */
83 } WalSnd;
84 
85 extern WalSnd *MyWalSnd;
86 
87 /* There is one WalSndCtl struct for the whole database cluster */
88 typedef struct
89 {
90  /*
91  * Synchronous replication queue with one queue per request type.
92  * Protected by SyncRepLock.
93  */
95 
96  /*
97  * Current location of the head of the queue. All waiters should have a
98  * waitLSN that follows this value. Protected by SyncRepLock.
99  */
101 
102  /*
103  * Are any sync standbys defined? Waiting backends can't reload the
104  * config file safely, so checkpointer updates this value as needed.
105  * Protected by SyncRepLock.
106  */
108 
109  WalSnd walsnds[FLEXIBLE_ARRAY_MEMBER];
110 } WalSndCtlData;
111 
112 extern WalSndCtlData *WalSndCtl;
113 
114 
115 extern void WalSndSetState(WalSndState state);
116 
117 /*
118  * Internal functions for parsing the replication grammar, in repl_gram.y and
119  * repl_scanner.l
120  */
121 extern int replication_yyparse(void);
122 extern int replication_yylex(void);
123 extern void replication_yyerror(const char *str) pg_attribute_noreturn();
124 extern void replication_scanner_init(const char *query_string);
125 extern void replication_scanner_finish(void);
126 
128 
129 #endif /* _WALSENDER_PRIVATE_H */
int slock_t
Definition: s_lock.h:934
XLogRecPtr write
int64 TimestampTz
Definition: timestamp.h:39
TimeOffset flushLag
Definition: nodes.h:525
TimeOffset writeLag
struct WalSnd WalSnd
slock_t mutex
Node * replication_parse_result
XLogRecPtr flush
Latch * latch
void replication_yyerror(const char *str) pg_attribute_noreturn()
Definition: latch.h:110
void WalSndSetState(WalSndState state)
Definition: walsender.c:3166
WalSndState state
int replication_yyparse(void)
int64 TimeOffset
Definition: timestamp.h:40
XLogRecPtr sentPtr
WalSndCtlData * WalSndCtl
Definition: walsender.c:108
WalSnd * MyWalSnd
Definition: walsender.c:111
TimeOffset applyLag
uint64 XLogRecPtr
Definition: xlogdefs.h:21
int sync_standby_priority
Definition: regguts.h:298
bool needreload
WalSndState
#define pg_attribute_noreturn()
Definition: c.h:147
int replication_yylex(void)
TimestampTz replyTime
#define NUM_SYNC_REP_WAIT_MODE
Definition: syncrep.h:28
XLogRecPtr apply
void replication_scanner_finish(void)
void replication_scanner_init(const char *query_string)