From 86822df9b5d5fe16d2528c7fc9428137414faa4f Mon Sep 17 00:00:00 2001 From: Alvaro Herrera <alvherre@alvh.no-ip.org> Date: Mon, 12 Sep 2011 15:24:29 -0300 Subject: [PATCH] Split walsender.h in public/private headers This dramatically cuts short the number of headers the public one brings into whatever includes it. --- src/backend/replication/basebackup.c | 1 + src/backend/replication/repl_gram.y | 1 + src/backend/replication/syncrep.c | 1 + src/backend/replication/walsender.c | 1 + src/include/replication/walsender.h | 93 +---------------- src/include/replication/walsender_private.h | 109 ++++++++++++++++++++ 6 files changed, 115 insertions(+), 91 deletions(-) create mode 100644 src/include/replication/walsender_private.h diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index 785b9998ff6..4841095d176 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -25,6 +25,7 @@ #include "nodes/pg_list.h" #include "replication/basebackup.h" #include "replication/walsender.h" +#include "replication/walsender_private.h" #include "storage/fd.h" #include "storage/ipc.h" #include "utils/builtins.h" diff --git a/src/backend/replication/repl_gram.y b/src/backend/replication/repl_gram.y index 70b34ff82e2..b3fd051e934 100644 --- a/src/backend/replication/repl_gram.y +++ b/src/backend/replication/repl_gram.y @@ -19,6 +19,7 @@ #include "nodes/makefuncs.h" #include "nodes/replnodes.h" #include "replication/walsender.h" +#include "replication/walsender_private.h" /* Result of the parsing is returned here */ diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c index 542bdf2bceb..95de6c7cb3c 100644 --- a/src/backend/replication/syncrep.c +++ b/src/backend/replication/syncrep.c @@ -49,6 +49,7 @@ #include "miscadmin.h" #include "replication/syncrep.h" #include "replication/walsender.h" +#include "replication/walsender_private.h" #include "storage/pmsignal.h" #include "storage/proc.h" #include "tcop/tcopprot.h" diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 6e1d82acb11..5d1c5180f2d 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -51,6 +51,7 @@ #include "replication/walprotocol.h" #include "replication/walreceiver.h" #include "replication/walsender.h" +#include "replication/walsender_private.h" #include "storage/fd.h" #include "storage/ipc.h" #include "storage/pmsignal.h" diff --git a/src/include/replication/walsender.h b/src/include/replication/walsender.h index a386ea9b1b2..f5ea9e2b3b4 100644 --- a/src/include/replication/walsender.h +++ b/src/include/replication/walsender.h @@ -12,84 +12,9 @@ #ifndef _WALSENDER_H #define _WALSENDER_H -#include "access/xlog.h" -#include "fmgr.h" -#include "nodes/nodes.h" -#include "storage/latch.h" -#include "storage/shmem.h" -#include "storage/spin.h" - -typedef enum WalSndState -{ - WALSNDSTATE_STARTUP = 0, - WALSNDSTATE_BACKUP, - WALSNDSTATE_CATCHUP, - WALSNDSTATE_STREAMING -} WalSndState; - -/* - * Each walsender has a WalSnd struct in shared memory. - */ -typedef struct WalSnd -{ - pid_t pid; /* this walsender's process id, or 0 */ - WalSndState state; /* this walsender's state */ - XLogRecPtr sentPtr; /* WAL has been sent up to this point */ - bool needreload; /* does currently-open file need to be reloaded? */ - - /* - * The xlog locations that have been written, flushed, and applied by - * standby-side. These may be invalid if the standby-side has not offered - * values yet. - */ - XLogRecPtr write; - XLogRecPtr flush; - XLogRecPtr apply; - - /* Protects shared variables shown above. */ - slock_t mutex; - - /* - * Latch used by backends to wake up this walsender when it has work to - * do. - */ - Latch latch; - - /* - * The priority order of the standby managed by this WALSender, as listed - * in synchronous_standby_names, or 0 if not-listed. Protected by - * SyncRepLock. - */ - int sync_standby_priority; -} WalSnd; - -extern WalSnd *MyWalSnd; +#include <signal.h> -/* There is one WalSndCtl struct for the whole database cluster */ -typedef struct -{ - /* - * Synchronous replication queue. Protected by SyncRepLock. - */ - SHM_QUEUE SyncRepQueue; - - /* - * Current location of the head of the queue. All waiters should have a - * waitLSN that follows this value. Protected by SyncRepLock. - */ - XLogRecPtr lsn; - - /* - * Are any sync standbys defined? Waiting backends can't reload the - * config file safely, so WAL writer updates this value as needed. - * Protected by SyncRepLock. - */ - bool sync_standbys_defined; - - WalSnd walsnds[1]; /* VARIABLE LENGTH ARRAY */ -} WalSndCtlData; - -extern WalSndCtlData *WalSndCtl; +#include "fmgr.h" /* global state */ extern bool am_walsender; @@ -106,22 +31,8 @@ extern void WalSndSignals(void); extern Size WalSndShmemSize(void); extern void WalSndShmemInit(void); extern void WalSndWakeup(void); -extern void WalSndSetState(WalSndState state); -extern void XLogRead(char *buf, XLogRecPtr startptr, Size count); extern void WalSndRqstFileReload(void); extern Datum pg_stat_get_wal_senders(PG_FUNCTION_ARGS); -/* - * Internal functions for parsing the replication grammar, in repl_gram.y and - * repl_scanner.l - */ -extern int replication_yyparse(void); -extern int replication_yylex(void); -extern void replication_yyerror(const char *str); -extern void replication_scanner_init(const char *query_string); -extern void replication_scanner_finish(void); - -extern Node *replication_parse_result; - #endif /* _WALSENDER_H */ diff --git a/src/include/replication/walsender_private.h b/src/include/replication/walsender_private.h new file mode 100644 index 00000000000..be7a341e618 --- /dev/null +++ b/src/include/replication/walsender_private.h @@ -0,0 +1,109 @@ +/*------------------------------------------------------------------------- + * + * walsender_private.h + * Private definitions from replication/walsender.c. + * + * Portions Copyright (c) 2010-2011, PostgreSQL Global Development Group + * + * src/include/replication/walsender_private.h + * + *------------------------------------------------------------------------- + */ +#ifndef _WALSENDER_PRIVATE_H +#define _WALSENDER_PRIVATE_H + +#include "access/xlog.h" +#include "nodes/nodes.h" +#include "storage/latch.h" +#include "storage/shmem.h" +#include "storage/spin.h" + +typedef enum WalSndState +{ + WALSNDSTATE_STARTUP = 0, + WALSNDSTATE_BACKUP, + WALSNDSTATE_CATCHUP, + WALSNDSTATE_STREAMING +} WalSndState; + +/* + * Each walsender has a WalSnd struct in shared memory. + */ +typedef struct WalSnd +{ + pid_t pid; /* this walsender's process id, or 0 */ + WalSndState state; /* this walsender's state */ + XLogRecPtr sentPtr; /* WAL has been sent up to this point */ + bool needreload; /* does currently-open file need to be reloaded? */ + + /* + * The xlog locations that have been written, flushed, and applied by + * standby-side. These may be invalid if the standby-side has not offered + * values yet. + */ + XLogRecPtr write; + XLogRecPtr flush; + XLogRecPtr apply; + + /* Protects shared variables shown above. */ + slock_t mutex; + + /* + * Latch used by backends to wake up this walsender when it has work to + * do. + */ + Latch latch; + + /* + * The priority order of the standby managed by this WALSender, as listed + * in synchronous_standby_names, or 0 if not-listed. Protected by + * SyncRepLock. + */ + int sync_standby_priority; +} WalSnd; + +extern WalSnd *MyWalSnd; + +/* There is one WalSndCtl struct for the whole database cluster */ +typedef struct +{ + /* + * Synchronous replication queue. Protected by SyncRepLock. + */ + SHM_QUEUE SyncRepQueue; + + /* + * Current location of the head of the queue. All waiters should have a + * waitLSN that follows this value. Protected by SyncRepLock. + */ + XLogRecPtr lsn; + + /* + * Are any sync standbys defined? Waiting backends can't reload the + * config file safely, so WAL writer updates this value as needed. + * Protected by SyncRepLock. + */ + bool sync_standbys_defined; + + WalSnd walsnds[1]; /* VARIABLE LENGTH ARRAY */ +} WalSndCtlData; + +extern WalSndCtlData *WalSndCtl; + + +extern void WalSndSetState(WalSndState state); +extern void XLogRead(char *buf, XLogRecPtr startptr, Size count); + +/* + * Internal functions for parsing the replication grammar, in repl_gram.y and + * repl_scanner.l + */ +extern int replication_yyparse(void); +extern int replication_yylex(void); +extern void replication_yyerror(const char *str); +extern void replication_scanner_init(const char *query_string); +extern void replication_scanner_finish(void); + +extern Node *replication_parse_result; + +#endif /* _WALSENDER_PRIVATE_H */ -- GitLab