2010-01-15 10:19:10 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* walsender.h
|
|
|
|
* Exports from replication/walsender.c.
|
|
|
|
*
|
2011-01-01 19:18:15 +01:00
|
|
|
* Portions Copyright (c) 2010-2011, PostgreSQL Global Development Group
|
2010-01-15 10:19:10 +01:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/replication/walsender.h
|
2010-01-15 10:19:10 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef _WALSENDER_H
|
|
|
|
#define _WALSENDER_H
|
|
|
|
|
|
|
|
#include "access/xlog.h"
|
2011-01-14 16:30:33 +01:00
|
|
|
#include "nodes/nodes.h"
|
Introduce latches. A latch is a boolean variable, with the capability to
wait until it is set. Latches can be used to reliably wait until a signal
arrives, which is hard otherwise because signals don't interrupt select()
on some platforms, and even when they do, there's race conditions.
On Unix, latches use the so called self-pipe trick under the covers to
implement the sleep until the latch is set, without race conditions. On
Windows, Windows events are used.
Use the new latch abstraction to sleep in walsender, so that as soon as
a transaction finishes, walsender is woken up to immediately send the WAL
to the standby. This reduces the latency between master and standby, which
is good.
Preliminary work by Fujii Masao. The latch implementation is by me, with
helpful comments from many people.
2010-09-11 17:48:04 +02:00
|
|
|
#include "storage/latch.h"
|
2011-03-06 23:49:16 +01:00
|
|
|
#include "replication/syncrep.h"
|
2010-01-15 10:19:10 +01:00
|
|
|
#include "storage/spin.h"
|
|
|
|
|
2011-01-11 21:25:28 +01:00
|
|
|
|
|
|
|
typedef enum WalSndState
|
|
|
|
{
|
|
|
|
WALSNDSTATE_STARTUP = 0,
|
|
|
|
WALSNDSTATE_BACKUP,
|
|
|
|
WALSNDSTATE_CATCHUP,
|
|
|
|
WALSNDSTATE_STREAMING
|
|
|
|
} WalSndState;
|
|
|
|
|
2010-01-15 10:19:10 +01:00
|
|
|
/*
|
|
|
|
* Each walsender has a WalSnd struct in shared memory.
|
|
|
|
*/
|
|
|
|
typedef struct WalSnd
|
|
|
|
{
|
2010-02-26 03:01:40 +01:00
|
|
|
pid_t pid; /* this walsender's process id, or 0 */
|
2011-01-11 21:25:28 +01:00
|
|
|
WalSndState state; /* this walsender's state */
|
2010-02-26 03:01:40 +01:00
|
|
|
XLogRecPtr sentPtr; /* WAL has been sent up to this point */
|
2010-01-15 10:19:10 +01:00
|
|
|
|
2011-02-10 20:00:29 +01:00
|
|
|
/*
|
|
|
|
* 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;
|
Introduce latches. A latch is a boolean variable, with the capability to
wait until it is set. Latches can be used to reliably wait until a signal
arrives, which is hard otherwise because signals don't interrupt select()
on some platforms, and even when they do, there's race conditions.
On Unix, latches use the so called self-pipe trick under the covers to
implement the sleep until the latch is set, without race conditions. On
Windows, Windows events are used.
Use the new latch abstraction to sleep in walsender, so that as soon as
a transaction finishes, walsender is woken up to immediately send the WAL
to the standby. This reduces the latency between master and standby, which
is good.
Preliminary work by Fujii Masao. The latch implementation is by me, with
helpful comments from many people.
2010-09-11 17:48:04 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Latch used by backends to wake up this walsender when it has work
|
|
|
|
* to do.
|
|
|
|
*/
|
|
|
|
Latch latch;
|
2011-03-06 23:49:16 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
2010-01-15 10:19:10 +01:00
|
|
|
} WalSnd;
|
|
|
|
|
2011-03-06 23:49:16 +01:00
|
|
|
extern WalSnd *MyWalSnd;
|
|
|
|
|
2010-01-15 10:19:10 +01:00
|
|
|
/* There is one WalSndCtl struct for the whole database cluster */
|
|
|
|
typedef struct
|
|
|
|
{
|
2011-03-06 23:49:16 +01:00
|
|
|
/*
|
|
|
|
* Synchronous replication queue. Protected by SyncRepLock.
|
|
|
|
*/
|
|
|
|
SHM_QUEUE SyncRepQueue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Current location of the head of the queue. All waiters should have
|
2011-03-10 21:00:20 +01:00
|
|
|
* a waitLSN that follows this value. Protected by SyncRepLock.
|
2011-03-06 23:49:16 +01:00
|
|
|
*/
|
|
|
|
XLogRecPtr lsn;
|
|
|
|
|
2010-02-26 03:01:40 +01:00
|
|
|
WalSnd walsnds[1]; /* VARIABLE LENGTH ARRAY */
|
2010-01-15 10:19:10 +01:00
|
|
|
} WalSndCtlData;
|
|
|
|
|
|
|
|
extern WalSndCtlData *WalSndCtl;
|
|
|
|
|
|
|
|
/* global state */
|
2010-02-26 03:01:40 +01:00
|
|
|
extern bool am_walsender;
|
2011-01-14 12:36:45 +01:00
|
|
|
extern volatile sig_atomic_t walsender_shutdown_requested;
|
|
|
|
extern volatile sig_atomic_t walsender_ready_to_stop;
|
2010-01-15 10:19:10 +01:00
|
|
|
|
|
|
|
/* user-settable parameters */
|
|
|
|
extern int WalSndDelay;
|
Introduce wal_level GUC to explicitly control if information needed for
archival or hot standby should be WAL-logged, instead of deducing that from
other options like archive_mode. This replaces recovery_connections GUC in
the primary, where it now has no effect, but it's still used in the standby
to enable/disable hot standby.
Remove the WAL-logging of "unlogged operations", like creating an index
without WAL-logging and fsyncing it at the end. Instead, we keep a copy of
the wal_mode setting and the settings that affect how much shared memory a
hot standby server needs to track master transactions (max_connections,
max_prepared_xacts, max_locks_per_xact) in pg_control. Whenever the settings
change, at server restart, write a WAL record noting the new settings and
update pg_control. This allows us to notice the change in those settings in
the standby at the right moment, they used to be included in checkpoint
records, but that meant that a changed value was not reflected in the
standby until the first checkpoint after the change.
Bump PG_CONTROL_VERSION and XLOG_PAGE_MAGIC. Whack XLOG_PAGE_MAGIC back to
the sequence it used to follow, before hot standby and subsequent patches
changed it to 0x9003.
2010-04-28 18:10:43 +02:00
|
|
|
extern int max_wal_senders;
|
2010-01-15 10:19:10 +01:00
|
|
|
|
2010-02-26 03:01:40 +01:00
|
|
|
extern int WalSenderMain(void);
|
2010-01-15 10:19:10 +01:00
|
|
|
extern void WalSndSignals(void);
|
|
|
|
extern Size WalSndShmemSize(void);
|
|
|
|
extern void WalSndShmemInit(void);
|
Introduce latches. A latch is a boolean variable, with the capability to
wait until it is set. Latches can be used to reliably wait until a signal
arrives, which is hard otherwise because signals don't interrupt select()
on some platforms, and even when they do, there's race conditions.
On Unix, latches use the so called self-pipe trick under the covers to
implement the sleep until the latch is set, without race conditions. On
Windows, Windows events are used.
Use the new latch abstraction to sleep in walsender, so that as soon as
a transaction finishes, walsender is woken up to immediately send the WAL
to the standby. This reduces the latency between master and standby, which
is good.
Preliminary work by Fujii Masao. The latch implementation is by me, with
helpful comments from many people.
2010-09-11 17:48:04 +02:00
|
|
|
extern void WalSndWakeup(void);
|
2011-01-11 21:25:28 +01:00
|
|
|
extern void WalSndSetState(WalSndState state);
|
2011-01-30 21:30:09 +01:00
|
|
|
extern void XLogRead(char *buf, XLogRecPtr recptr, Size nbytes);
|
2010-01-15 10:19:10 +01:00
|
|
|
|
2011-01-07 12:35:38 +01:00
|
|
|
extern Datum pg_stat_get_wal_senders(PG_FUNCTION_ARGS);
|
|
|
|
|
2011-01-14 16:30:33 +01:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2010-02-26 03:01:40 +01:00
|
|
|
#endif /* _WALSENDER_H */
|