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