]> granicus.if.org Git - postgresql/blob - src/include/replication/walsender_private.h
Centralize definition of integer limits.
[postgresql] / src / include / replication / walsender_private.h
1 /*-------------------------------------------------------------------------
2  *
3  * walsender_private.h
4  *        Private definitions from replication/walsender.c.
5  *
6  * Portions Copyright (c) 2010-2015, 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 {
24         WALSNDSTATE_STARTUP = 0,
25         WALSNDSTATE_BACKUP,
26         WALSNDSTATE_CATCHUP,
27         WALSNDSTATE_STREAMING
28 } WalSndState;
29
30 /*
31  * Each walsender has a WalSnd struct in shared memory.
32  */
33 typedef struct WalSnd
34 {
35         pid_t           pid;                    /* this walsender's process id, or 0 */
36         WalSndState state;                      /* this walsender's state */
37         XLogRecPtr      sentPtr;                /* WAL has been sent up to this point */
38         bool            needreload;             /* does currently-open file need to be
39                                                                  * reloaded? */
40
41         /*
42          * The xlog locations that have been written, flushed, and applied by
43          * standby-side. These may be invalid if the standby-side has not offered
44          * values yet.
45          */
46         XLogRecPtr      write;
47         XLogRecPtr      flush;
48         XLogRecPtr      apply;
49
50         /* Protects shared variables shown above. */
51         slock_t         mutex;
52
53         /*
54          * Pointer to the walsender's latch. Used by backends to wake up this
55          * walsender when it has work to do. NULL if the walsender isn't active.
56          */
57         Latch      *latch;
58
59         /*
60          * The priority order of the standby managed by this WALSender, as listed
61          * in synchronous_standby_names, or 0 if not-listed. Protected by
62          * SyncRepLock.
63          */
64         int                     sync_standby_priority;
65 } WalSnd;
66
67 extern WalSnd *MyWalSnd;
68
69 /* There is one WalSndCtl struct for the whole database cluster */
70 typedef struct
71 {
72         /*
73          * Synchronous replication queue with one queue per request type.
74          * Protected by SyncRepLock.
75          */
76         SHM_QUEUE       SyncRepQueue[NUM_SYNC_REP_WAIT_MODE];
77
78         /*
79          * Current location of the head of the queue. All waiters should have a
80          * waitLSN that follows this value. Protected by SyncRepLock.
81          */
82         XLogRecPtr      lsn[NUM_SYNC_REP_WAIT_MODE];
83
84         /*
85          * Are any sync standbys defined?  Waiting backends can't reload the
86          * config file safely, so checkpointer updates this value as needed.
87          * Protected by SyncRepLock.
88          */
89         bool            sync_standbys_defined;
90
91         WalSnd          walsnds[FLEXIBLE_ARRAY_MEMBER];
92 } WalSndCtlData;
93
94 extern WalSndCtlData *WalSndCtl;
95
96
97 extern void WalSndSetState(WalSndState state);
98
99 /*
100  * Internal functions for parsing the replication grammar, in repl_gram.y and
101  * repl_scanner.l
102  */
103 extern int      replication_yyparse(void);
104 extern int      replication_yylex(void);
105 extern void replication_yyerror(const char *str);
106 extern void replication_scanner_init(const char *query_string);
107 extern void replication_scanner_finish(void);
108
109 extern Node *replication_parse_result;
110
111 #endif   /* _WALSENDER_PRIVATE_H */