Header And Logo

PostgreSQL
| The world's most advanced open source database.

walreceiver.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * walreceiver.h
00004  *    Exports from replication/walreceiverfuncs.c.
00005  *
00006  * Portions Copyright (c) 2010-2013, PostgreSQL Global Development Group
00007  *
00008  * src/include/replication/walreceiver.h
00009  *
00010  *-------------------------------------------------------------------------
00011  */
00012 #ifndef _WALRECEIVER_H
00013 #define _WALRECEIVER_H
00014 
00015 #include "access/xlog.h"
00016 #include "access/xlogdefs.h"
00017 #include "storage/latch.h"
00018 #include "storage/spin.h"
00019 #include "pgtime.h"
00020 
00021 /* user-settable parameters */
00022 extern int  wal_receiver_status_interval;
00023 extern int  wal_receiver_timeout;
00024 extern bool hot_standby_feedback;
00025 
00026 /*
00027  * MAXCONNINFO: maximum size of a connection string.
00028  *
00029  * XXX: Should this move to pg_config_manual.h?
00030  */
00031 #define MAXCONNINFO     1024
00032 
00033 /* Can we allow the standby to accept replication connection from another standby? */
00034 #define AllowCascadeReplication() (EnableHotStandby && max_wal_senders > 0)
00035 
00036 /*
00037  * Values for WalRcv->walRcvState.
00038  */
00039 typedef enum
00040 {
00041     WALRCV_STOPPED,             /* stopped and mustn't start up again */
00042     WALRCV_STARTING,            /* launched, but the process hasn't
00043                                  * initialized yet */
00044     WALRCV_STREAMING,           /* walreceiver is streaming */
00045     WALRCV_WAITING,             /* stopped streaming, waiting for orders */
00046     WALRCV_RESTARTING,          /* asked to restart streaming */
00047     WALRCV_STOPPING             /* requested to stop, but still running */
00048 } WalRcvState;
00049 
00050 /* Shared memory area for management of walreceiver process */
00051 typedef struct
00052 {
00053     /*
00054      * PID of currently active walreceiver process, its current state and
00055      * start time (actually, the time at which it was requested to be
00056      * started).
00057      */
00058     pid_t       pid;
00059     WalRcvState walRcvState;
00060     pg_time_t   startTime;
00061 
00062     /*
00063      * receiveStart and receiveStartTLI indicate the first byte position
00064      * and timeline that will be received. When startup process starts the
00065      * walreceiver, it sets these to the point where it wants the streaming
00066      * to begin.
00067      */
00068     XLogRecPtr  receiveStart;
00069     TimeLineID  receiveStartTLI;
00070 
00071     /*
00072      * receivedUpto-1 is the last byte position that has already been
00073      * received, and receivedTLI is the timeline it came from.  At the first
00074      * startup of walreceiver, these are set to receiveStart and
00075      * receiveStartTLI. After that, walreceiver updates these whenever it
00076      * flushes the received WAL to disk.
00077      */
00078     XLogRecPtr  receivedUpto;
00079     TimeLineID  receivedTLI;
00080 
00081     /*
00082      * latestChunkStart is the starting byte position of the current "batch"
00083      * of received WAL.  It's actually the same as the previous value of
00084      * receivedUpto before the last flush to disk.  Startup process can use
00085      * this to detect whether it's keeping up or not.
00086      */
00087     XLogRecPtr  latestChunkStart;
00088 
00089     /*
00090      * Time of send and receive of any message received.
00091      */
00092     TimestampTz lastMsgSendTime;
00093     TimestampTz lastMsgReceiptTime;
00094 
00095     /*
00096      * Latest reported end of WAL on the sender
00097      */
00098     XLogRecPtr  latestWalEnd;
00099     TimestampTz latestWalEndTime;
00100 
00101     /*
00102      * connection string; is used for walreceiver to connect with the primary.
00103      */
00104     char        conninfo[MAXCONNINFO];
00105 
00106     slock_t     mutex;          /* locks shared variables shown above */
00107 
00108     /*
00109      * Latch used by startup process to wake up walreceiver after telling it
00110      * where to start streaming (after setting receiveStart and
00111      * receiveStartTLI).
00112      */
00113     Latch       latch;
00114 } WalRcvData;
00115 
00116 extern WalRcvData *WalRcv;
00117 
00118 /* libpqwalreceiver hooks */
00119 typedef void (*walrcv_connect_type) (char *conninfo);
00120 extern PGDLLIMPORT walrcv_connect_type walrcv_connect;
00121 
00122 typedef void (*walrcv_identify_system_type) (TimeLineID *primary_tli);
00123 extern PGDLLIMPORT walrcv_identify_system_type walrcv_identify_system;
00124 
00125 typedef void (*walrcv_readtimelinehistoryfile_type) (TimeLineID tli, char **filename, char **content, int *size);
00126 extern PGDLLIMPORT walrcv_readtimelinehistoryfile_type walrcv_readtimelinehistoryfile;
00127 
00128 typedef bool (*walrcv_startstreaming_type) (TimeLineID tli, XLogRecPtr startpoint);
00129 extern PGDLLIMPORT walrcv_startstreaming_type walrcv_startstreaming;
00130 
00131 typedef void (*walrcv_endstreaming_type) (TimeLineID *next_tli);
00132 extern PGDLLIMPORT walrcv_endstreaming_type walrcv_endstreaming;
00133 
00134 typedef int (*walrcv_receive_type) (int timeout, char **buffer);
00135 extern PGDLLIMPORT walrcv_receive_type walrcv_receive;
00136 
00137 typedef void (*walrcv_send_type) (const char *buffer, int nbytes);
00138 extern PGDLLIMPORT walrcv_send_type walrcv_send;
00139 
00140 typedef void (*walrcv_disconnect_type) (void);
00141 extern PGDLLIMPORT walrcv_disconnect_type walrcv_disconnect;
00142 
00143 /* prototypes for functions in walreceiver.c */
00144 extern void WalReceiverMain(void) __attribute__((noreturn));
00145 
00146 /* prototypes for functions in walreceiverfuncs.c */
00147 extern Size WalRcvShmemSize(void);
00148 extern void WalRcvShmemInit(void);
00149 extern void ShutdownWalRcv(void);
00150 extern bool WalRcvStreaming(void);
00151 extern bool WalRcvRunning(void);
00152 extern void RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo);
00153 extern XLogRecPtr GetWalRcvWriteRecPtr(XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI);
00154 extern int  GetReplicationApplyDelay(void);
00155 extern int  GetReplicationTransferLatency(void);
00156 
00157 #endif   /* _WALRECEIVER_H */