PostgreSQL Source Code
git master
|
#include "access/xlog.h"
#include "access/xlogdefs.h"
#include "getaddrinfo.h"
#include "pgtime.h"
#include "port/atomics.h"
#include "replication/logicalproto.h"
#include "replication/walsender.h"
#include "storage/condition_variable.h"
#include "storage/latch.h"
#include "storage/spin.h"
#include "utils/tuplestore.h"
Go to the source code of this file.
Data Structures | |
struct | WalRcvData |
struct | WalRcvStreamOptions |
struct | WalRcvExecResult |
struct | WalReceiverFunctionsType |
Macros | |
#define | MAXCONNINFO 1024 |
#define | AllowCascadeReplication() (EnableHotStandby && max_wal_senders > 0) |
#define | walrcv_connect(conninfo, logical, appname, err) WalReceiverFunctions->walrcv_connect(conninfo, logical, appname, err) |
#define | walrcv_check_conninfo(conninfo) WalReceiverFunctions->walrcv_check_conninfo(conninfo) |
#define | walrcv_get_conninfo(conn) WalReceiverFunctions->walrcv_get_conninfo(conn) |
#define | walrcv_get_senderinfo(conn, sender_host, sender_port) WalReceiverFunctions->walrcv_get_senderinfo(conn, sender_host, sender_port) |
#define | walrcv_identify_system(conn, primary_tli) WalReceiverFunctions->walrcv_identify_system(conn, primary_tli) |
#define | walrcv_server_version(conn) WalReceiverFunctions->walrcv_server_version(conn) |
#define | walrcv_readtimelinehistoryfile(conn, tli, filename, content, size) WalReceiverFunctions->walrcv_readtimelinehistoryfile(conn, tli, filename, content, size) |
#define | walrcv_startstreaming(conn, options) WalReceiverFunctions->walrcv_startstreaming(conn, options) |
#define | walrcv_endstreaming(conn, next_tli) WalReceiverFunctions->walrcv_endstreaming(conn, next_tli) |
#define | walrcv_receive(conn, buffer, wait_fd) WalReceiverFunctions->walrcv_receive(conn, buffer, wait_fd) |
#define | walrcv_send(conn, buffer, nbytes) WalReceiverFunctions->walrcv_send(conn, buffer, nbytes) |
#define | walrcv_create_slot(conn, slotname, temporary, snapshot_action, lsn) WalReceiverFunctions->walrcv_create_slot(conn, slotname, temporary, snapshot_action, lsn) |
#define | walrcv_get_backend_pid(conn) WalReceiverFunctions->walrcv_get_backend_pid(conn) |
#define | walrcv_exec(conn, exec, nRetTypes, retTypes) WalReceiverFunctions->walrcv_exec(conn, exec, nRetTypes, retTypes) |
#define | walrcv_disconnect(conn) WalReceiverFunctions->walrcv_disconnect(conn) |
Functions | |
static void | walrcv_clear_result (WalRcvExecResult *walres) |
void | WalReceiverMain (void) pg_attribute_noreturn() |
void | ProcessWalRcvInterrupts (void) |
Size | WalRcvShmemSize (void) |
void | WalRcvShmemInit (void) |
void | ShutdownWalRcv (void) |
bool | WalRcvStreaming (void) |
bool | WalRcvRunning (void) |
void | RequestXLogStreaming (TimeLineID tli, XLogRecPtr recptr, const char *conninfo, const char *slotname, bool create_temp_slot) |
XLogRecPtr | GetWalRcvFlushRecPtr (XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI) |
XLogRecPtr | GetWalRcvWriteRecPtr (void) |
int | GetReplicationApplyDelay (void) |
int | GetReplicationTransferLatency (void) |
void | WalRcvForceReply (void) |
Variables | |
int | wal_receiver_status_interval |
int | wal_receiver_timeout |
bool | hot_standby_feedback |
WalRcvData * | WalRcv |
PGDLLIMPORT WalReceiverFunctionsType * | WalReceiverFunctions |
#define AllowCascadeReplication | ( | ) | (EnableHotStandby && max_wal_senders > 0) |
Definition at line 40 of file walreceiver.h.
Referenced by StartupXLOG(), and XLogWalRcvFlush().
#define MAXCONNINFO 1024 |
Definition at line 37 of file walreceiver.h.
Referenced by pg_stat_get_wal_receiver(), RequestXLogStreaming(), and WalReceiverMain().
#define walrcv_check_conninfo | ( | conninfo | ) | WalReceiverFunctions->walrcv_check_conninfo(conninfo) |
Definition at line 403 of file walreceiver.h.
Referenced by AlterSubscription(), and CreateSubscription().
#define walrcv_connect | ( | conninfo, | |
logical, | |||
appname, | |||
err | |||
) | WalReceiverFunctions->walrcv_connect(conninfo, logical, appname, err) |
Definition at line 401 of file walreceiver.h.
Referenced by AlterSubscription_refresh(), ApplyWorkerMain(), CreateSubscription(), DropSubscription(), LogicalRepSyncTableStart(), and WalReceiverMain().
#define walrcv_create_slot | ( | conn, | |
slotname, | |||
temporary, | |||
snapshot_action, | |||
lsn | |||
) | WalReceiverFunctions->walrcv_create_slot(conn, slotname, temporary, snapshot_action, lsn) |
Definition at line 423 of file walreceiver.h.
Referenced by CreateSubscription(), LogicalRepSyncTableStart(), and WalReceiverMain().
#define walrcv_disconnect | ( | conn | ) | WalReceiverFunctions->walrcv_disconnect(conn) |
Definition at line 429 of file walreceiver.h.
Referenced by AlterSubscription_refresh(), CreateSubscription(), DropSubscription(), logicalrep_worker_onexit(), and WalRcvDie().
#define walrcv_endstreaming | ( | conn, | |
next_tli | |||
) | WalReceiverFunctions->walrcv_endstreaming(conn, next_tli) |
Definition at line 417 of file walreceiver.h.
Referenced by LogicalRepApplyLoop(), process_syncing_tables_for_sync(), and WalReceiverMain().
#define walrcv_exec | ( | conn, | |
exec, | |||
nRetTypes, | |||
retTypes | |||
) | WalReceiverFunctions->walrcv_exec(conn, exec, nRetTypes, retTypes) |
Definition at line 427 of file walreceiver.h.
Referenced by copy_table(), fetch_remote_table_info(), fetch_table_list(), LogicalRepSyncTableStart(), and ReplicationSlotDropAtPubNode().
#define walrcv_get_backend_pid | ( | conn | ) | WalReceiverFunctions->walrcv_get_backend_pid(conn) |
Definition at line 425 of file walreceiver.h.
Referenced by WalReceiverMain().
#define walrcv_get_conninfo | ( | conn | ) | WalReceiverFunctions->walrcv_get_conninfo(conn) |
Definition at line 405 of file walreceiver.h.
Referenced by WalReceiverMain().
#define walrcv_get_senderinfo | ( | conn, | |
sender_host, | |||
sender_port | |||
) | WalReceiverFunctions->walrcv_get_senderinfo(conn, sender_host, sender_port) |
Definition at line 407 of file walreceiver.h.
Referenced by WalReceiverMain().
#define walrcv_identify_system | ( | conn, | |
primary_tli | |||
) | WalReceiverFunctions->walrcv_identify_system(conn, primary_tli) |
Definition at line 409 of file walreceiver.h.
Referenced by ApplyWorkerMain(), and WalReceiverMain().
#define walrcv_readtimelinehistoryfile | ( | conn, | |
tli, | |||
filename, | |||
content, | |||
size | |||
) | WalReceiverFunctions->walrcv_readtimelinehistoryfile(conn, tli, filename, content, size) |
Definition at line 413 of file walreceiver.h.
Referenced by WalRcvFetchTimeLineHistoryFiles().
#define walrcv_receive | ( | conn, | |
buffer, | |||
wait_fd | |||
) | WalReceiverFunctions->walrcv_receive(conn, buffer, wait_fd) |
Definition at line 419 of file walreceiver.h.
Referenced by copy_read_data(), LogicalRepApplyLoop(), and WalReceiverMain().
#define walrcv_send | ( | conn, | |
buffer, | |||
nbytes | |||
) | WalReceiverFunctions->walrcv_send(conn, buffer, nbytes) |
Definition at line 421 of file walreceiver.h.
Referenced by send_feedback(), XLogWalRcvSendHSFeedback(), and XLogWalRcvSendReply().
#define walrcv_server_version | ( | conn | ) | WalReceiverFunctions->walrcv_server_version(conn) |
Definition at line 411 of file walreceiver.h.
Referenced by ApplyWorkerMain(), and fetch_remote_table_info().
#define walrcv_startstreaming | ( | conn, | |
options | |||
) | WalReceiverFunctions->walrcv_startstreaming(conn, options) |
Definition at line 415 of file walreceiver.h.
Referenced by ApplyWorkerMain(), and WalReceiverMain().
typedef void(* walrcv_check_conninfo_fn) (const char *conninfo) |
Definition at line 244 of file walreceiver.h.
typedef WalReceiverConn*(* walrcv_connect_fn) (const char *conninfo, bool logical, const char *appname, char **err) |
Definition at line 234 of file walreceiver.h.
typedef char*(* walrcv_create_slot_fn) (WalReceiverConn *conn, const char *slotname, bool temporary, CRSSnapshotAction snapshot_action, XLogRecPtr *lsn) |
Definition at line 347 of file walreceiver.h.
typedef void(* walrcv_disconnect_fn) (WalReceiverConn *conn) |
Definition at line 378 of file walreceiver.h.
typedef void(* walrcv_endstreaming_fn) (WalReceiverConn *conn, TimeLineID *next_tli) |
Definition at line 312 of file walreceiver.h.
typedef WalRcvExecResult*(* walrcv_exec_fn) (WalReceiverConn *conn, const char *query, const int nRetTypes, const Oid *retTypes) |
Definition at line 368 of file walreceiver.h.
typedef pid_t(* walrcv_get_backend_pid_fn) (WalReceiverConn *conn) |
Definition at line 358 of file walreceiver.h.
typedef char*(* walrcv_get_conninfo_fn) (WalReceiverConn *conn) |
Definition at line 252 of file walreceiver.h.
typedef void(* walrcv_get_senderinfo_fn) (WalReceiverConn *conn, char **sender_host, int *sender_port) |
Definition at line 261 of file walreceiver.h.
typedef char*(* walrcv_identify_system_fn) (WalReceiverConn *conn, TimeLineID *primary_tli) |
Definition at line 272 of file walreceiver.h.
typedef void(* walrcv_readtimelinehistoryfile_fn) (WalReceiverConn *conn, TimeLineID tli, char **filename, char **content, int *size) |
Definition at line 289 of file walreceiver.h.
typedef int(* walrcv_receive_fn) (WalReceiverConn *conn, char **buffer, pgsocket *wait_fd) |
Definition at line 323 of file walreceiver.h.
typedef void(* walrcv_send_fn) (WalReceiverConn *conn, const char *buffer, int nbytes) |
Definition at line 333 of file walreceiver.h.
typedef int(* walrcv_server_version_fn) (WalReceiverConn *conn) |
Definition at line 280 of file walreceiver.h.
typedef bool(* walrcv_startstreaming_fn) (WalReceiverConn *conn, const WalRcvStreamOptions *options) |
Definition at line 303 of file walreceiver.h.
typedef struct WalRcvExecResult WalRcvExecResult |
typedef struct WalReceiverConn WalReceiverConn |
Definition at line 189 of file walreceiver.h.
typedef struct WalReceiverFunctionsType WalReceiverFunctionsType |
enum WalRcvExecStatus |
Enumerator | |
---|---|
WALRCV_ERROR | |
WALRCV_OK_COMMAND | |
WALRCV_OK_TUPLES | |
WALRCV_OK_COPY_IN | |
WALRCV_OK_COPY_OUT | |
WALRCV_OK_COPY_BOTH |
Definition at line 196 of file walreceiver.h.
enum WalRcvState |
Enumerator | |
---|---|
WALRCV_STOPPED | |
WALRCV_STARTING | |
WALRCV_STREAMING | |
WALRCV_WAITING | |
WALRCV_RESTARTING | |
WALRCV_STOPPING |
Definition at line 45 of file walreceiver.h.
int GetReplicationApplyDelay | ( | void | ) |
Definition at line 364 of file walreceiverfuncs.c.
References WalRcvData::flushedUpto, GetCurrentChunkReplayStartTime(), GetCurrentTimestamp(), GetXLogReplayRecPtr(), WalRcvData::mutex, SpinLockAcquire, SpinLockRelease, TimestampDifferenceMilliseconds(), and WalRcv.
Referenced by ProcessWalSndrMessage(), and walrcv_clear_result().
int GetReplicationTransferLatency | ( | void | ) |
Definition at line 394 of file walreceiverfuncs.c.
References WalRcvData::lastMsgReceiptTime, WalRcvData::lastMsgSendTime, WalRcvData::mutex, SpinLockAcquire, SpinLockRelease, TimestampDifferenceMilliseconds(), and WalRcv.
Referenced by ProcessWalSndrMessage(), and walrcv_clear_result().
XLogRecPtr GetWalRcvFlushRecPtr | ( | XLogRecPtr * | latestChunkStart, |
TimeLineID * | receiveTLI | ||
) |
Definition at line 331 of file walreceiverfuncs.c.
References WalRcvData::flushedUpto, WalRcvData::latestChunkStart, WalRcvData::mutex, WalRcvData::receivedTLI, SpinLockAcquire, SpinLockRelease, and WalRcv.
Referenced by CreateRestartPoint(), GetStandbyFlushRecPtr(), pg_last_wal_receive_lsn(), WaitForWALToBecomeAvailable(), and walrcv_clear_result().
XLogRecPtr GetWalRcvWriteRecPtr | ( | void | ) |
Definition at line 352 of file walreceiverfuncs.c.
References pg_atomic_read_u64(), WalRcv, and WalRcvData::writtenUpto.
Referenced by walrcv_clear_result().
void ProcessWalRcvInterrupts | ( | void | ) |
Definition at line 146 of file walreceiver.c.
References CHECK_FOR_INTERRUPTS, ereport, errcode(), errmsg(), FATAL, and ShutdownRequestPending.
Referenced by libpqrcv_connect(), libpqrcv_PQgetResult(), libpqrcv_processTuples(), walrcv_clear_result(), WalRcvWaitForStartPosition(), and WalReceiverMain().
void RequestXLogStreaming | ( | TimeLineID | tli, |
XLogRecPtr | recptr, | ||
const char * | conninfo, | ||
const char * | slotname, | ||
bool | create_temp_slot | ||
) |
Definition at line 245 of file walreceiverfuncs.c.
References Assert, WalRcvData::conninfo, WalRcvData::flushedUpto, WalRcvData::is_temp_slot, WalRcvData::latch, WalRcvData::latestChunkStart, MAXCONNINFO, WalRcvData::mutex, NAMEDATALEN, now(), PMSIGNAL_START_WALRECEIVER, WalRcvData::receivedTLI, WalRcvData::receiveStart, WalRcvData::receiveStartTLI, SendPostmasterSignal(), SetLatch(), WalRcvData::slotname, SpinLockAcquire, SpinLockRelease, WalRcvData::startTime, strlcpy(), wal_segment_size, WalRcv, WALRCV_RESTARTING, WALRCV_STARTING, WALRCV_STOPPED, WALRCV_WAITING, WalRcvData::walRcvState, and XLogSegmentOffset.
Referenced by WaitForWALToBecomeAvailable(), and walrcv_clear_result().
void ShutdownWalRcv | ( | void | ) |
Definition at line 178 of file walreceiverfuncs.c.
References ConditionVariableBroadcast(), ConditionVariableCancelSleep(), ConditionVariablePrepareToSleep(), ConditionVariableSleep(), kill, WalRcvData::mutex, WalRcvData::pid, SpinLockAcquire, SpinLockRelease, WAIT_EVENT_WAL_RECEIVER_EXIT, WalRcv, WALRCV_RESTARTING, WALRCV_STARTING, WALRCV_STOPPED, WALRCV_STOPPING, WALRCV_STREAMING, WALRCV_WAITING, WalRcvRunning(), WalRcvData::walRcvState, and WalRcvData::walRcvStoppedCV.
Referenced by StartupXLOG(), WaitForWALToBecomeAvailable(), and walrcv_clear_result().
|
inlinestatic |
Definition at line 433 of file walreceiver.h.
References WalRcvExecResult::err, FreeTupleDesc(), GetReplicationApplyDelay(), GetReplicationTransferLatency(), GetWalRcvFlushRecPtr(), GetWalRcvWriteRecPtr(), pfree(), pg_attribute_noreturn, ProcessWalRcvInterrupts(), receiveTLI, RequestXLogStreaming(), ShutdownWalRcv(), WalRcvExecResult::tupledesc, WalRcvExecResult::tuplestore, tuplestore_end(), WalRcvForceReply(), WalRcvRunning(), WalRcvShmemInit(), WalRcvShmemSize(), WalRcvStreaming(), and WalReceiverMain().
Referenced by copy_table(), fetch_remote_table_info(), fetch_table_list(), LogicalRepSyncTableStart(), and ReplicationSlotDropAtPubNode().
void WalRcvForceReply | ( | void | ) |
Definition at line 1256 of file walreceiver.c.
References WalRcvData::force_reply, WalRcvData::latch, WalRcvData::mutex, SetLatch(), SpinLockAcquire, SpinLockRelease, and WalRcv.
Referenced by StartupXLOG(), WaitForWALToBecomeAvailable(), and walrcv_clear_result().
bool WalRcvRunning | ( | void | ) |
Definition at line 75 of file walreceiverfuncs.c.
References ConditionVariableBroadcast(), WalRcvData::mutex, now(), SpinLockAcquire, SpinLockRelease, WalRcvData::startTime, WalRcv, WALRCV_STARTING, WALRCV_STARTUP_TIMEOUT, WALRCV_STOPPED, WalRcvData::walRcvState, and WalRcvData::walRcvStoppedCV.
Referenced by ShutdownWalRcv(), StartupRequestWalReceiverRestart(), and walrcv_clear_result().
void WalRcvShmemInit | ( | void | ) |
Definition at line 54 of file walreceiverfuncs.c.
References ConditionVariableInit(), WalRcvData::latch, MemSet, WalRcvData::mutex, pg_atomic_init_u64(), ShmemInitStruct(), SpinLockInit, WALRCV_STOPPED, WalRcvShmemSize(), WalRcvData::walRcvState, WalRcvData::walRcvStoppedCV, and WalRcvData::writtenUpto.
Referenced by CreateSharedMemoryAndSemaphores(), and walrcv_clear_result().
Size WalRcvShmemSize | ( | void | ) |
Definition at line 43 of file walreceiverfuncs.c.
References add_size().
Referenced by CreateSharedMemoryAndSemaphores(), walrcv_clear_result(), and WalRcvShmemInit().
bool WalRcvStreaming | ( | void | ) |
Definition at line 126 of file walreceiverfuncs.c.
References ConditionVariableBroadcast(), WalRcvData::mutex, now(), SpinLockAcquire, SpinLockRelease, WalRcvData::startTime, WalRcv, WALRCV_RESTARTING, WALRCV_STARTING, WALRCV_STARTUP_TIMEOUT, WALRCV_STOPPED, WALRCV_STREAMING, WalRcvData::walRcvState, and WalRcvData::walRcvStoppedCV.
Referenced by StartupXLOG(), WaitForWALToBecomeAvailable(), and walrcv_clear_result().
void WalReceiverMain | ( | void | ) |
Definition at line 167 of file walreceiver.c.
References ARCHIVE_MODE_ALWAYS, Assert, buf, close, cluster_name, ConditionVariableBroadcast(), ConfigReloadPending, WalRcvData::conninfo, DEBUG1, elog, ereport, errcode_for_file_access(), errdetail(), errmsg(), ERROR, FATAL, WalRcvData::force_reply, GetCurrentTimestamp(), GetSystemIdentifier(), GetXLogReplayRecPtr(), initStringInfo(), WalRcvData::is_temp_slot, WalRcvData::lastMsgReceiptTime, WalRcvData::lastMsgSendTime, WalRcvData::latch, WalRcvData::latestWalEndTime, load_file(), LOG, WalRcvStreamOptions::logical, LogstreamResult, LSN_FORMAT_ARGS, MAXCONNINFO, MAXFNAMELEN, WalRcvData::mutex, MyLatch, MyProc, MyProcPid, NAMEDATALEN, NAPTIME_PER_CYCLE, NI_MAXHOST, now(), on_shmem_exit(), options, PANIC, pfree(), pg_atomic_write_u64(), pg_memory_barrier, PG_SETMASK, PGC_SIGHUP, PGINVALID_SOCKET, WalRcvStreamOptions::physical, WalRcvData::pid, pqsignal(), proc_exit(), ProcessConfigFile(), ProcessWalRcvInterrupts(), PGPROC::procLatch, procsignal_sigusr1_handler(), WalRcvStreamOptions::proto, WalRcvData::ready_to_display, WalRcvData::receiveStart, WalRcvData::receiveStartTLI, RecoveryInProgress(), recvFile, recvFileTLI, recvSegNo, ResetLatch(), WalRcvData::sender_host, WalRcvData::sender_port, SIG_DFL, SIG_IGN, SIGALRM, SIGCHLD, SIGHUP, SignalHandlerForConfigReload(), SignalHandlerForShutdownRequest(), SIGPIPE, SIGUSR1, SIGUSR2, WalRcvData::slotname, WalRcvStreamOptions::slotname, snprintf, SpinLockAcquire, SpinLockRelease, WalRcvStreamOptions::startpoint, strlcpy(), ThisTimeLineID, TimestampTzPlusMilliseconds, UINT64_FORMAT, UnBlockSig, WAIT_EVENT_WAL_RECEIVER_MAIN, WaitLatchOrSocket(), wal_receiver_timeout, wal_segment_size, WalRcv, walrcv_connect, walrcv_create_slot, walrcv_endstreaming, walrcv_get_backend_pid, walrcv_get_conninfo, walrcv_get_senderinfo, walrcv_identify_system, walrcv_receive, WALRCV_RESTARTING, WALRCV_STARTING, walrcv_startstreaming, WALRCV_STOPPED, WALRCV_STOPPING, WALRCV_STREAMING, WALRCV_WAITING, WalRcvDie(), WalRcvFetchTimeLineHistoryFiles(), WalRcvData::walRcvState, WalRcvData::walRcvStoppedCV, WalRcvWaitForStartPosition(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_SOCKET_READABLE, WL_TIMEOUT, WalRcvData::writtenUpto, XLogArchiveForceDone(), XLogArchiveMode, XLogArchiveNotify(), XLogFileName, XLogWalRcvFlush(), XLogWalRcvProcessMsg(), XLogWalRcvSendHSFeedback(), and XLogWalRcvSendReply().
Referenced by AuxiliaryProcessMain(), and walrcv_clear_result().
bool hot_standby_feedback |
Definition at line 91 of file walreceiver.c.
Referenced by XLogWalRcvSendHSFeedback().
int wal_receiver_status_interval |
Definition at line 89 of file walreceiver.c.
Referenced by send_feedback(), XLogWalRcvSendHSFeedback(), and XLogWalRcvSendReply().
int wal_receiver_timeout |
Definition at line 90 of file walreceiver.c.
Referenced by logicalrep_worker_launch(), LogicalRepApplyLoop(), and WalReceiverMain().
WalRcvData* WalRcv |
Definition at line 33 of file walreceiverfuncs.c.
Referenced by GetReplicationApplyDelay(), GetReplicationTransferLatency(), GetWalRcvFlushRecPtr(), GetWalRcvWriteRecPtr(), pg_stat_get_wal_receiver(), ProcessWalSndrMessage(), RequestXLogStreaming(), ShutdownWalRcv(), WalRcvDie(), WalRcvForceReply(), WalRcvRunning(), WalRcvStreaming(), WalRcvWaitForStartPosition(), WalReceiverMain(), XLogWalRcvFlush(), and XLogWalRcvWrite().
PGDLLIMPORT WalReceiverFunctionsType* WalReceiverFunctions |
Definition at line 95 of file walreceiver.c.
Referenced by _PG_init().