PostgreSQL Source Code
git master
|
#include <netdb.h>
#include "access/xlog.h"
#include "access/xlogdefs.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, replication, logical, must_use_password, appname, err) WalReceiverFunctions->walrcv_connect(conninfo, replication, logical, must_use_password, appname, err) |
#define | walrcv_check_conninfo(conninfo, must_use_password) WalReceiverFunctions->walrcv_check_conninfo(conninfo, must_use_password) |
#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_get_dbname_from_conninfo(conninfo) WalReceiverFunctions->walrcv_get_dbname_from_conninfo(conninfo) |
#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, two_phase, failover, snapshot_action, lsn) WalReceiverFunctions->walrcv_create_slot(conn, slotname, temporary, two_phase, failover, snapshot_action, lsn) |
#define | walrcv_alter_slot(conn, slotname, failover, two_phase) WalReceiverFunctions->walrcv_alter_slot(conn, slotname, failover, two_phase) |
#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) |
Enumerations | |
enum | WalRcvState { WALRCV_STOPPED , WALRCV_STARTING , WALRCV_STREAMING , WALRCV_WAITING , WALRCV_RESTARTING , WALRCV_STOPPING } |
enum | WalRcvExecStatus { WALRCV_ERROR , WALRCV_OK_COMMAND , WALRCV_OK_TUPLES , WALRCV_OK_COPY_IN , WALRCV_OK_COPY_OUT , WALRCV_OK_COPY_BOTH } |
Functions | |
static void | walrcv_clear_result (WalRcvExecResult *walres) |
void | WalReceiverMain (char *startup_data, size_t startup_data_len) pg_attribute_noreturn() |
void | ProcessWalRcvInterrupts (void) |
void | WalRcvForceReply (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) |
#define AllowCascadeReplication | ( | ) | (EnableHotStandby && max_wal_senders > 0) |
Definition at line 41 of file walreceiver.h.
#define MAXCONNINFO 1024 |
Definition at line 38 of file walreceiver.h.
#define walrcv_alter_slot | ( | conn, | |
slotname, | |||
failover, | |||
two_phase | |||
) | WalReceiverFunctions->walrcv_alter_slot(conn, slotname, failover, two_phase) |
Definition at line 460 of file walreceiver.h.
#define walrcv_check_conninfo | ( | conninfo, | |
must_use_password | |||
) | WalReceiverFunctions->walrcv_check_conninfo(conninfo, must_use_password) |
Definition at line 436 of file walreceiver.h.
#define walrcv_connect | ( | conninfo, | |
replication, | |||
logical, | |||
must_use_password, | |||
appname, | |||
err | |||
) | WalReceiverFunctions->walrcv_connect(conninfo, replication, logical, must_use_password, appname, err) |
Definition at line 434 of file walreceiver.h.
#define walrcv_create_slot | ( | conn, | |
slotname, | |||
temporary, | |||
two_phase, | |||
failover, | |||
snapshot_action, | |||
lsn | |||
) | WalReceiverFunctions->walrcv_create_slot(conn, slotname, temporary, two_phase, failover, snapshot_action, lsn) |
Definition at line 458 of file walreceiver.h.
#define walrcv_disconnect | ( | conn | ) | WalReceiverFunctions->walrcv_disconnect(conn) |
Definition at line 466 of file walreceiver.h.
#define walrcv_endstreaming | ( | conn, | |
next_tli | |||
) | WalReceiverFunctions->walrcv_endstreaming(conn, next_tli) |
Definition at line 452 of file walreceiver.h.
#define walrcv_exec | ( | conn, | |
exec, | |||
nRetTypes, | |||
retTypes | |||
) | WalReceiverFunctions->walrcv_exec(conn, exec, nRetTypes, retTypes) |
Definition at line 464 of file walreceiver.h.
#define walrcv_get_backend_pid | ( | conn | ) | WalReceiverFunctions->walrcv_get_backend_pid(conn) |
Definition at line 462 of file walreceiver.h.
#define walrcv_get_conninfo | ( | conn | ) | WalReceiverFunctions->walrcv_get_conninfo(conn) |
Definition at line 438 of file walreceiver.h.
#define walrcv_get_dbname_from_conninfo | ( | conninfo | ) | WalReceiverFunctions->walrcv_get_dbname_from_conninfo(conninfo) |
Definition at line 444 of file walreceiver.h.
#define walrcv_get_senderinfo | ( | conn, | |
sender_host, | |||
sender_port | |||
) | WalReceiverFunctions->walrcv_get_senderinfo(conn, sender_host, sender_port) |
Definition at line 440 of file walreceiver.h.
#define walrcv_identify_system | ( | conn, | |
primary_tli | |||
) | WalReceiverFunctions->walrcv_identify_system(conn, primary_tli) |
Definition at line 442 of file walreceiver.h.
#define walrcv_readtimelinehistoryfile | ( | conn, | |
tli, | |||
filename, | |||
content, | |||
size | |||
) | WalReceiverFunctions->walrcv_readtimelinehistoryfile(conn, tli, filename, content, size) |
Definition at line 448 of file walreceiver.h.
#define walrcv_receive | ( | conn, | |
buffer, | |||
wait_fd | |||
) | WalReceiverFunctions->walrcv_receive(conn, buffer, wait_fd) |
Definition at line 454 of file walreceiver.h.
#define walrcv_send | ( | conn, | |
buffer, | |||
nbytes | |||
) | WalReceiverFunctions->walrcv_send(conn, buffer, nbytes) |
Definition at line 456 of file walreceiver.h.
#define walrcv_server_version | ( | conn | ) | WalReceiverFunctions->walrcv_server_version(conn) |
Definition at line 446 of file walreceiver.h.
#define walrcv_startstreaming | ( | conn, | |
options | |||
) | WalReceiverFunctions->walrcv_startstreaming(conn, options) |
Definition at line 450 of file walreceiver.h.
typedef void(* walrcv_alter_slot_fn) (WalReceiverConn *conn, const char *slotname, const bool *failover, const bool *two_phase) |
Definition at line 378 of file walreceiver.h.
typedef void(* walrcv_check_conninfo_fn) (const char *conninfo, bool must_use_password) |
Definition at line 253 of file walreceiver.h.
typedef WalReceiverConn*(* walrcv_connect_fn) (const char *conninfo, bool replication, bool logical, bool must_use_password, const char *appname, char **err) |
Definition at line 241 of file walreceiver.h.
typedef char*(* walrcv_create_slot_fn) (WalReceiverConn *conn, const char *slotname, bool temporary, bool two_phase, bool failover, CRSSnapshotAction snapshot_action, XLogRecPtr *lsn) |
Definition at line 364 of file walreceiver.h.
typedef void(* walrcv_disconnect_fn) (WalReceiverConn *conn) |
Definition at line 409 of file walreceiver.h.
typedef void(* walrcv_endstreaming_fn) (WalReceiverConn *conn, TimeLineID *next_tli) |
Definition at line 329 of file walreceiver.h.
typedef WalRcvExecResult*(* walrcv_exec_fn) (WalReceiverConn *conn, const char *query, const int nRetTypes, const Oid *retTypes) |
Definition at line 399 of file walreceiver.h.
typedef pid_t(* walrcv_get_backend_pid_fn) (WalReceiverConn *conn) |
Definition at line 389 of file walreceiver.h.
typedef char*(* walrcv_get_conninfo_fn) (WalReceiverConn *conn) |
Definition at line 262 of file walreceiver.h.
typedef char*(* walrcv_get_dbname_from_conninfo_fn) (const char *conninfo) |
Definition at line 290 of file walreceiver.h.
typedef void(* walrcv_get_senderinfo_fn) (WalReceiverConn *conn, char **sender_host, int *sender_port) |
Definition at line 271 of file walreceiver.h.
typedef char*(* walrcv_identify_system_fn) (WalReceiverConn *conn, TimeLineID *primary_tli) |
Definition at line 282 of file walreceiver.h.
typedef void(* walrcv_readtimelinehistoryfile_fn) (WalReceiverConn *conn, TimeLineID tli, char **filename, char **content, int *size) |
Definition at line 306 of file walreceiver.h.
typedef int(* walrcv_receive_fn) (WalReceiverConn *conn, char **buffer, pgsocket *wait_fd) |
Definition at line 340 of file walreceiver.h.
typedef void(* walrcv_send_fn) (WalReceiverConn *conn, const char *buffer, int nbytes) |
Definition at line 350 of file walreceiver.h.
typedef int(* walrcv_server_version_fn) (WalReceiverConn *conn) |
Definition at line 297 of file walreceiver.h.
typedef bool(* walrcv_startstreaming_fn) (WalReceiverConn *conn, const WalRcvStreamOptions *options) |
Definition at line 320 of file walreceiver.h.
typedef struct WalRcvExecResult WalRcvExecResult |
typedef struct WalReceiverConn WalReceiverConn |
Definition at line 164 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 201 of file walreceiver.h.
enum WalRcvState |
Enumerator | |
---|---|
WALRCV_STOPPED | |
WALRCV_STARTING | |
WALRCV_STREAMING | |
WALRCV_WAITING | |
WALRCV_RESTARTING | |
WALRCV_STOPPING |
Definition at line 46 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().
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().
XLogRecPtr GetWalRcvFlushRecPtr | ( | XLogRecPtr * | latestChunkStart, |
TimeLineID * | receiveTLI | ||
) |
Definition at line 331 of file walreceiverfuncs.c.
References WalRcvData::flushedUpto, WalRcvData::latestChunkStart, WalRcvData::mutex, WalRcvData::receivedTLI, receiveTLI, SpinLockAcquire, SpinLockRelease, and WalRcv.
Referenced by CreateRestartPoint(), GetLatestLSN(), GetStandbyFlushRecPtr(), pg_last_wal_receive_lsn(), reserve_wal_for_local_slot(), and WaitForWALToBecomeAvailable().
XLogRecPtr GetWalRcvWriteRecPtr | ( | void | ) |
Definition at line 352 of file walreceiverfuncs.c.
References pg_atomic_read_u64(), WalRcv, and WalRcvData::writtenUpto.
void ProcessWalRcvInterrupts | ( | void | ) |
Definition at line 162 of file walreceiver.c.
References CHECK_FOR_INTERRUPTS, ereport, errcode(), errmsg(), FATAL, and ShutdownRequestPending.
Referenced by libpqrcv_connect(), libpqrcv_PQgetResult(), libpqrcv_processTuples(), 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().
void ShutdownWalRcv | ( | void | ) |
Definition at line 178 of file walreceiverfuncs.c.
References ConditionVariableBroadcast(), ConditionVariableCancelSleep(), ConditionVariablePrepareToSleep(), ConditionVariableSleep(), kill, WalRcvData::mutex, WalRcvData::pid, SpinLockAcquire, SpinLockRelease, WalRcv, WALRCV_RESTARTING, WALRCV_STARTING, WALRCV_STOPPED, WALRCV_STOPPING, WALRCV_STREAMING, WALRCV_WAITING, WalRcvRunning(), WalRcvData::walRcvState, and WalRcvData::walRcvStoppedCV.
Referenced by XLogShutdownWalRcv().
|
inlinestatic |
Definition at line 470 of file walreceiver.h.
References WalRcvExecResult::err, FreeTupleDesc(), pfree(), WalRcvExecResult::tupledesc, WalRcvExecResult::tuplestore, and tuplestore_end().
Referenced by check_publications(), check_publications_origin(), copy_table(), fetch_remote_table_info(), fetch_table_list(), LogicalRepSyncTableStart(), ReplicationSlotDropAtPubNode(), synchronize_slots(), and validate_remote_info().
void WalRcvForceReply | ( | void | ) |
Definition at line 1359 of file walreceiver.c.
References WalRcvData::force_reply, WalRcvData::latch, WalRcvData::mutex, SetLatch(), SpinLockAcquire, SpinLockRelease, and WalRcv.
Referenced by ApplyWalRecord(), and WaitForWALToBecomeAvailable().
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(), and StartupRequestWalReceiverRestart().
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, WALRCV_STOPPED, WalRcvShmemSize(), WalRcvData::walRcvState, WalRcvData::walRcvStoppedCV, and WalRcvData::writtenUpto.
Referenced by CreateOrAttachShmemStructs().
Size WalRcvShmemSize | ( | void | ) |
Definition at line 43 of file walreceiverfuncs.c.
References add_size(), and size.
Referenced by CalculateShmemSize(), 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 FinishWalRecovery(), and WaitForWALToBecomeAvailable().
void WalReceiverMain | ( | char * | startup_data, |
size_t | startup_data_len | ||
) |
Definition at line 183 of file walreceiver.c.
References ARCHIVE_MODE_ALWAYS, Assert, AuxiliaryProcessMainCommon(), B_WAL_RECEIVER, buf, close, cluster_name, ConditionVariableBroadcast(), ConfigReloadPending, WalRcvData::conninfo, DEBUG1, elog, ereport, err(), errcode(), errcode_for_file_access(), errdetail(), errmsg(), ERROR, FATAL, WalRcvData::force_reply, GetCurrentTimestamp(), GetSystemIdentifier(), GetXLogReplayRecPtr(), i, initStringInfo(), WalRcvData::is_temp_slot, WalRcvData::lastMsgReceiptTime, WalRcvData::lastMsgSendTime, WalRcvData::latch, WalRcvData::latestWalEndTime, len, load_file(), LOG, LogstreamResult, LSN_FORMAT_ARGS, MAXCONNINFO, MAXFNAMELEN, Min, WalRcvData::mutex, MyBackendType, MyLatch, MyProc, MyProcPid, NAMEDATALEN, now(), NUM_WALRCV_WAKEUPS, on_shmem_exit(), options, PANIC, pfree(), pg_atomic_write_u64(), pg_memory_barrier, PGC_SIGHUP, PGINVALID_SOCKET, WalRcvData::pid, PointerGetDatum(), pqsignal(), proc_exit(), ProcessConfigFile(), ProcessWalRcvInterrupts(), PGPROC::procLatch, procsignal_sigusr1_handler(), WalRcvData::ready_to_display, WalRcvData::receiveStart, WalRcvData::receiveStartTLI, RecoveryInProgress(), recvFile, recvFileTLI, recvSegNo, reply_message, ResetLatch(), WalRcvData::sender_host, WalRcvData::sender_port, SIG_DFL, SIG_IGN, SIGALRM, SIGCHLD, SIGHUP, SignalHandlerForConfigReload(), SignalHandlerForShutdownRequest(), SIGPIPE, SIGUSR1, SIGUSR2, WalRcvData::slotname, snprintf, SpinLockAcquire, SpinLockRelease, strlcpy(), TIMESTAMP_INFINITY, TimestampDifferenceMilliseconds(), UINT64_FORMAT, UnBlockSig, WaitLatchOrSocket(), wakeup, 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, WALRCV_WAKEUP_PING, WALRCV_WAKEUP_TERMINATE, WalRcvComputeNextWakeup(), WalRcvDie(), WalRcvFetchTimeLineHistoryFiles(), WalRcvData::walRcvState, WalRcvData::walRcvStoppedCV, WalRcvWaitForStartPosition(), WalReceiverFunctions, WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, WL_SOCKET_READABLE, WL_TIMEOUT, wrconn, WalRcvData::writtenUpto, XLogArchiveForceDone(), XLogArchiveMode, XLogArchiveNotify(), XLogFileName(), XLogWalRcvFlush(), XLogWalRcvProcessMsg(), XLogWalRcvSendHSFeedback(), and XLogWalRcvSendReply().
|
extern |
Definition at line 89 of file walreceiver.c.
Referenced by slotsync_reread_config(), ValidateSlotSyncParams(), WalRcvComputeNextWakeup(), and XLogWalRcvSendHSFeedback().
|
extern |
Definition at line 87 of file walreceiver.c.
Referenced by send_feedback(), WalRcvComputeNextWakeup(), XLogWalRcvSendHSFeedback(), and XLogWalRcvSendReply().
|
extern |
Definition at line 88 of file walreceiver.c.
Referenced by logicalrep_worker_launch(), LogicalRepApplyLoop(), and WalRcvComputeNextWakeup().
|
extern |
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(), WalRcvShmemInit(), WalRcvStreaming(), WalRcvWaitForStartPosition(), WalReceiverMain(), XLogWalRcvFlush(), and XLogWalRcvWrite().
|
extern |
Definition at line 93 of file walreceiver.c.
Referenced by _PG_init(), and WalReceiverMain().