Header And Logo

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

walsender_private.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * walsender_private.h
00004  *    Private definitions from replication/walsender.c.
00005  *
00006  * Portions Copyright (c) 2010-2013, PostgreSQL Global Development Group
00007  *
00008  * src/include/replication/walsender_private.h
00009  *
00010  *-------------------------------------------------------------------------
00011  */
00012 #ifndef _WALSENDER_PRIVATE_H
00013 #define _WALSENDER_PRIVATE_H
00014 
00015 #include "access/xlog.h"
00016 #include "nodes/nodes.h"
00017 #include "replication/syncrep.h"
00018 #include "storage/latch.h"
00019 #include "storage/shmem.h"
00020 #include "storage/spin.h"
00021 
00022 typedef enum WalSndState
00023 {
00024     WALSNDSTATE_STARTUP = 0,
00025     WALSNDSTATE_BACKUP,
00026     WALSNDSTATE_CATCHUP,
00027     WALSNDSTATE_STREAMING
00028 } WalSndState;
00029 
00030 /*
00031  * Each walsender has a WalSnd struct in shared memory.
00032  */
00033 typedef struct WalSnd
00034 {
00035     pid_t       pid;            /* this walsender's process id, or 0 */
00036     WalSndState state;          /* this walsender's state */
00037     XLogRecPtr  sentPtr;        /* WAL has been sent up to this point */
00038     bool        needreload;     /* does currently-open file need to be
00039                                  * reloaded? */
00040 
00041     /*
00042      * The xlog locations that have been written, flushed, and applied by
00043      * standby-side. These may be invalid if the standby-side has not offered
00044      * values yet.
00045      */
00046     XLogRecPtr  write;
00047     XLogRecPtr  flush;
00048     XLogRecPtr  apply;
00049 
00050     /* Protects shared variables shown above. */
00051     slock_t     mutex;
00052 
00053     /*
00054      * Latch used by backends to wake up this walsender when it has work to
00055      * do.
00056      */
00057     Latch       latch;
00058 
00059     /*
00060      * The priority order of the standby managed by this WALSender, as listed
00061      * in synchronous_standby_names, or 0 if not-listed. Protected by
00062      * SyncRepLock.
00063      */
00064     int         sync_standby_priority;
00065 } WalSnd;
00066 
00067 extern WalSnd *MyWalSnd;
00068 
00069 /* There is one WalSndCtl struct for the whole database cluster */
00070 typedef struct
00071 {
00072     /*
00073      * Synchronous replication queue with one queue per request type.
00074      * Protected by SyncRepLock.
00075      */
00076     SHM_QUEUE   SyncRepQueue[NUM_SYNC_REP_WAIT_MODE];
00077 
00078     /*
00079      * Current location of the head of the queue. All waiters should have a
00080      * waitLSN that follows this value. Protected by SyncRepLock.
00081      */
00082     XLogRecPtr  lsn[NUM_SYNC_REP_WAIT_MODE];
00083 
00084     /*
00085      * Are any sync standbys defined?  Waiting backends can't reload the
00086      * config file safely, so checkpointer updates this value as needed.
00087      * Protected by SyncRepLock.
00088      */
00089     bool        sync_standbys_defined;
00090 
00091     WalSnd      walsnds[1];     /* VARIABLE LENGTH ARRAY */
00092 } WalSndCtlData;
00093 
00094 extern WalSndCtlData *WalSndCtl;
00095 
00096 
00097 extern void WalSndSetState(WalSndState state);
00098 
00099 /*
00100  * Internal functions for parsing the replication grammar, in repl_gram.y and
00101  * repl_scanner.l
00102  */
00103 extern int  replication_yyparse(void);
00104 extern int  replication_yylex(void);
00105 extern void replication_yyerror(const char *str);
00106 extern void replication_scanner_init(const char *query_string);
00107 extern void replication_scanner_finish(void);
00108 
00109 extern Node *replication_parse_result;
00110 
00111 #endif   /* _WALSENDER_PRIVATE_H */