]> granicus.if.org Git - postgresql/blob - src/include/replication/walreceiver.h
Remove leftovers of BeOS port
[postgresql] / src / include / replication / walreceiver.h
1 /*-------------------------------------------------------------------------
2  *
3  * walreceiver.h
4  *        Exports from replication/walreceiverfuncs.c.
5  *
6  * Portions Copyright (c) 2010-2012, PostgreSQL Global Development Group
7  *
8  * src/include/replication/walreceiver.h
9  *
10  *-------------------------------------------------------------------------
11  */
12 #ifndef _WALRECEIVER_H
13 #define _WALRECEIVER_H
14
15 #include "access/xlog.h"
16 #include "access/xlogdefs.h"
17 #include "storage/spin.h"
18 #include "pgtime.h"
19
20 extern bool am_walreceiver;
21 extern int      wal_receiver_status_interval;
22 extern bool hot_standby_feedback;
23
24 /*
25  * MAXCONNINFO: maximum size of a connection string.
26  *
27  * XXX: Should this move to pg_config_manual.h?
28  */
29 #define MAXCONNINFO             1024
30
31 /* Can we allow the standby to accept replication connection from another standby? */
32 #define AllowCascadeReplication() (EnableHotStandby && max_wal_senders > 0)
33
34 /*
35  * Values for WalRcv->walRcvState.
36  */
37 typedef enum
38 {
39         WALRCV_STOPPED,                         /* stopped and mustn't start up again */
40         WALRCV_STARTING,                        /* launched, but the process hasn't
41                                                                  * initialized yet */
42         WALRCV_RUNNING,                         /* walreceiver is running */
43         WALRCV_STOPPING                         /* requested to stop, but still running */
44 } WalRcvState;
45
46 /* Shared memory area for management of walreceiver process */
47 typedef struct
48 {
49         /*
50          * PID of currently active walreceiver process, its current state and
51          * start time (actually, the time at which it was requested to be
52          * started).
53          */
54         pid_t           pid;
55         WalRcvState walRcvState;
56         pg_time_t       startTime;
57
58         /*
59          * receiveStart is the first byte position that will be received. When
60          * startup process starts the walreceiver, it sets receiveStart to the
61          * point where it wants the streaming to begin.
62          */
63         XLogRecPtr      receiveStart;
64
65         /*
66          * receivedUpto-1 is the last byte position that has already been
67          * received.  At the first startup of walreceiver, receivedUpto is set to
68          * receiveStart. After that, walreceiver updates this whenever it flushes
69          * the received WAL to disk.
70          */
71         XLogRecPtr      receivedUpto;
72
73         /*
74          * latestChunkStart is the starting byte position of the current "batch"
75          * of received WAL.  It's actually the same as the previous value of
76          * receivedUpto before the last flush to disk.  Startup process can use
77          * this to detect whether it's keeping up or not.
78          */
79         XLogRecPtr      latestChunkStart;
80
81         /*
82          * Time of send and receive of any message received.
83          */
84         TimestampTz lastMsgSendTime;
85         TimestampTz lastMsgReceiptTime;
86
87         /*
88          * connection string; is used for walreceiver to connect with the primary.
89          */
90         char            conninfo[MAXCONNINFO];
91
92         slock_t         mutex;                  /* locks shared variables shown above */
93 } WalRcvData;
94
95 extern WalRcvData *WalRcv;
96
97 /* libpqwalreceiver hooks */
98 typedef bool (*walrcv_connect_type) (char *conninfo, XLogRecPtr startpoint);
99 extern PGDLLIMPORT walrcv_connect_type walrcv_connect;
100
101 typedef bool (*walrcv_receive_type) (int timeout, unsigned char *type,
102                                                                                                  char **buffer, int *len);
103 extern PGDLLIMPORT walrcv_receive_type walrcv_receive;
104
105 typedef void (*walrcv_send_type) (const char *buffer, int nbytes);
106 extern PGDLLIMPORT walrcv_send_type walrcv_send;
107
108 typedef void (*walrcv_disconnect_type) (void);
109 extern PGDLLIMPORT walrcv_disconnect_type walrcv_disconnect;
110
111 /* prototypes for functions in walreceiver.c */
112 extern void WalReceiverMain(void);
113
114 /* prototypes for functions in walreceiverfuncs.c */
115 extern Size WalRcvShmemSize(void);
116 extern void WalRcvShmemInit(void);
117 extern void ShutdownWalRcv(void);
118 extern bool WalRcvInProgress(void);
119 extern void RequestXLogStreaming(XLogRecPtr recptr, const char *conninfo);
120 extern XLogRecPtr GetWalRcvWriteRecPtr(XLogRecPtr *latestChunkStart);
121 extern int GetReplicationApplyDelay(void);
122 extern int GetReplicationTransferLatency(void);
123
124 #endif   /* _WALRECEIVER_H */