PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <time.h>
#include "access/xlog_internal.h"
#include "access/xlogrecovery.h"
#include "catalog/pg_database.h"
#include "commands/dbcommands.h"
#include "libpq/pqsignal.h"
#include "pgstat.h"
#include "postmaster/fork_process.h"
#include "postmaster/interrupt.h"
#include "postmaster/postmaster.h"
#include "replication/logical.h"
#include "replication/slotsync.h"
#include "replication/snapbuild.h"
#include "storage/ipc.h"
#include "storage/lmgr.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
#include "utils/pg_lsn.h"
#include "utils/ps_status.h"
#include "utils/timeout.h"
Go to the source code of this file.
Data Structures | |
struct | SlotSyncCtxStruct |
struct | RemoteSlot |
Macros | |
#define | MIN_SLOTSYNC_WORKER_NAPTIME_MS 200 |
#define | MAX_SLOTSYNC_WORKER_NAPTIME_MS 30000 /* 30s */ |
#define | SLOTSYNC_RESTART_INTERVAL_SEC 10 |
#define | SLOTSYNC_COLUMN_COUNT 9 |
#define | PRIMARY_INFO_OUTPUT_COL_COUNT 2 |
Typedefs | |
typedef struct SlotSyncCtxStruct | SlotSyncCtxStruct |
typedef struct RemoteSlot | RemoteSlot |
Variables | |
static SlotSyncCtxStruct * | SlotSyncCtx = NULL |
bool | sync_replication_slots = false |
static long | sleep_ms = MIN_SLOTSYNC_WORKER_NAPTIME_MS |
static bool | syncing_slots = false |
#define MAX_SLOTSYNC_WORKER_NAPTIME_MS 30000 /* 30s */ |
Definition at line 117 of file slotsync.c.
#define MIN_SLOTSYNC_WORKER_NAPTIME_MS 200 |
Definition at line 116 of file slotsync.c.
#define PRIMARY_INFO_OUTPUT_COL_COUNT 2 |
#define SLOTSYNC_COLUMN_COUNT 9 |
#define SLOTSYNC_RESTART_INTERVAL_SEC 10 |
Definition at line 122 of file slotsync.c.
typedef struct RemoteSlot RemoteSlot |
typedef struct SlotSyncCtxStruct SlotSyncCtxStruct |
|
static |
Definition at line 1271 of file slotsync.c.
References Assert, ereport, errcode(), errmsg(), ERROR, InvalidPid, SlotSyncCtxStruct::mutex, SlotSyncCtxStruct::pid, SlotSyncCtx, SpinLockAcquire, SpinLockRelease, SlotSyncCtxStruct::stopSignaled, SlotSyncCtxStruct::syncing, and syncing_slots.
Referenced by ReplSlotSyncWorkerMain(), and SyncReplicationSlots().
char* CheckAndGetDbnameFromConninfo | ( | void | ) |
Definition at line 1012 of file slotsync.c.
References dbname, ereport, errcode(), errmsg(), ERROR, PrimaryConnInfo, and walrcv_get_dbname_from_conninfo.
Referenced by pg_sync_replication_slots(), and ReplSlotSyncWorkerMain().
|
static |
Definition at line 417 of file slotsync.c.
References AccessShareLock, ereport, errmsg(), foreach_ptr, get_local_synced_slots(), local_sync_slot_required(), LockSharedObject(), LOG, NameStr, ReplicationSlotAcquire(), ReplicationSlotDropAcquired(), SpinLockAcquire, SpinLockRelease, and UnlockSharedObject().
Referenced by synchronize_slots().
|
static |
Definition at line 333 of file slotsync.c.
References Assert, ReplicationSlot::data, i, ReplicationSlot::in_use, lappend(), LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, NIL, ReplicationSlotCtlData::replication_slots, ReplicationSlotCtl, SlotIsLogical, and ReplicationSlotPersistentData::synced.
Referenced by drop_local_obsolete_slots().
bool IsSyncingReplicationSlots | ( | void | ) |
Definition at line 1651 of file slotsync.c.
References syncing_slots.
Referenced by CreateDecodingContext(), GetStandbyFlushRecPtr(), and ReplicationSlotCreate().
|
static |
Definition at line 364 of file slotsync.c.
References ReplicationSlot::data, foreach_ptr, ReplicationSlotPersistentData::invalidated, ReplicationSlot::mutex, ReplicationSlotPersistentData::name, NameStr, RS_INVAL_NONE, SpinLockAcquire, and SpinLockRelease.
Referenced by drop_local_obsolete_slots().
|
static |
Definition at line 1155 of file slotsync.c.
References CHECK_FOR_INTERRUPTS, ConfigReloadPending, ereport, errmsg(), LOG, proc_exit(), ShutdownRequestPending, and slotsync_reread_config().
Referenced by ReplSlotSyncWorkerMain().
void ReplSlotSyncWorkerMain | ( | char * | startup_data, |
size_t | startup_data_len | ||
) |
Definition at line 1331 of file slotsync.c.
References appendStringInfo(), appendStringInfoString(), Assert, B_SLOTSYNC_WORKER, BaseInit(), before_shmem_exit(), check_and_set_sync_info(), CheckAndGetDbnameFromConninfo(), cluster_name, StringInfoData::data, dbname, die, EmitErrorReport(), ereport, err(), errcode(), errmsg(), ERROR, error_context_stack, FloatExceptionHandler(), GetProcessingMode, HOLD_INTERRUPTS, init_ps_display(), InitializeTimeouts(), InitPostgres(), InitProcess(), InitProcessing, initStringInfo(), InvalidOid, load_file(), LOG, MyBackendType, MyProcPid, NormalProcessing, pfree(), PG_exception_stack, PGC_S_OVERRIDE, PGC_SUSET, PointerGetDatum(), pqsignal(), PrimaryConnInfo, proc_exit(), ProcessSlotSyncInterrupts(), procsignal_sigusr1_handler(), SetConfigOption(), SetProcessingMode, SIG_DFL, SIG_IGN, SIGCHLD, SIGHUP, SignalHandlerForConfigReload(), SignalHandlerForShutdownRequest(), SIGPIPE, SIGUSR1, SIGUSR2, slotsync_worker_disconnect(), slotsync_worker_onexit(), SlotSyncCtx, synchronize_slots(), UnBlockSig, validate_remote_info(), wait_for_slot_activity(), walrcv_connect, and wrconn.
|
static |
Definition at line 474 of file slotsync.c.
References Assert, ReplicationSlot::data, DEBUG1, elog, GetWalRcvFlushRecPtr(), ReplicationSlot::mutex, MyReplicationSlot, ReplicationSlotsComputeRequiredLSN(), ReplicationSlotPersistentData::restart_lsn, SpinLockAcquire, SpinLockRelease, UINT64_FORMAT, wal_segment_size, XLByteToSeg, XLogGetLastRemovedSegno(), XLogGetOldestSegno(), XLogRecPtrIsInvalid, and XLogSegNoOffsetToRecPtr.
Referenced by synchronize_one_slot().
|
static |
Definition at line 1315 of file slotsync.c.
References SlotSyncCtxStruct::mutex, SlotSyncCtx, SpinLockAcquire, SpinLockRelease, SlotSyncCtxStruct::syncing, and syncing_slots.
Referenced by slotsync_failure_callback(), and SyncReplicationSlots().
void ShutDownSlotSync | ( | void | ) |
Definition at line 1563 of file slotsync.c.
References CHECK_FOR_INTERRUPTS, InvalidPid, kill, SlotSyncCtxStruct::mutex, MyLatch, SlotSyncCtxStruct::pid, ResetLatch(), SlotSyncCtx, SpinLockAcquire, SpinLockRelease, SlotSyncCtxStruct::stopSignaled, SlotSyncCtxStruct::syncing, update_synced_slots_inactive_since(), WaitLatch(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, and WL_TIMEOUT.
Referenced by FinishWalRecovery().
|
static |
Definition at line 1689 of file slotsync.c.
References arg, DatumGetPointer(), MyReplicationSlot, ReplicationSlotCleanup(), ReplicationSlotRelease(), reset_syncing_flag(), syncing_slots, walrcv_disconnect, and wrconn.
Referenced by SyncReplicationSlots().
|
static |
Definition at line 1106 of file slotsync.c.
References Assert, ConfigReloadPending, ereport, errmsg(), hot_standby_feedback, SlotSyncCtxStruct::last_start_time, LOG, pfree(), PGC_SIGHUP, PrimaryConnInfo, PrimarySlotName, proc_exit(), ProcessConfigFile(), pstrdup(), SlotSyncCtx, and sync_replication_slots.
Referenced by ProcessSlotSyncInterrupts().
|
static |
Definition at line 1177 of file slotsync.c.
References arg, DatumGetPointer(), walrcv_disconnect, and wrconn.
Referenced by ReplSlotSyncWorkerMain().
|
static |
Definition at line 1190 of file slotsync.c.
References InvalidPid, SlotSyncCtxStruct::mutex, MyReplicationSlot, SlotSyncCtxStruct::pid, ReplicationSlotCleanup(), ReplicationSlotRelease(), SlotSyncCtx, SpinLockAcquire, SpinLockRelease, SlotSyncCtxStruct::syncing, and syncing_slots.
Referenced by ReplSlotSyncWorkerMain().
void SlotSyncShmemInit | ( | void | ) |
Definition at line 1669 of file slotsync.c.
References InvalidPid, SlotSyncCtxStruct::mutex, SlotSyncCtxStruct::pid, ShmemInitStruct(), size, SlotSyncCtx, SlotSyncShmemSize(), and SpinLockInit.
Referenced by CreateOrAttachShmemStructs().
Size SlotSyncShmemSize | ( | void | ) |
Definition at line 1660 of file slotsync.c.
Referenced by CalculateShmemSize(), and SlotSyncShmemInit().
bool SlotSyncWorkerCanRestart | ( | void | ) |
Definition at line 1631 of file slotsync.c.
References SlotSyncCtxStruct::last_start_time, SLOTSYNC_RESTART_INTERVAL_SEC, and SlotSyncCtx.
Referenced by LaunchMissingBackgroundProcesses().
|
static |
Definition at line 609 of file slotsync.c.
References AmLogicalSlotSyncWorkerProcess, Assert, ReplicationSlotPersistentData::catalog_xmin, ReplicationSlotPersistentData::confirmed_flush, RemoteSlot::confirmed_lsn, ReplicationSlot::data, ReplicationSlotPersistentData::database, ReplicationSlot::effective_catalog_xmin, ereport, errcode(), errdetail_internal(), errmsg(), errmsg_internal(), ERROR, RemoteSlot::failover, GetOldestSafeDecodingTransactionId(), GetStandbyFlushRecPtr(), RemoteSlot::invalidated, ReplicationSlotPersistentData::invalidated, InvalidTransactionId, LOG, LSN_FORMAT_ARGS, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), ReplicationSlot::mutex, MyReplicationSlot, RemoteSlot::name, namestrcpy(), ReplicationSlotPersistentData::persistency, RemoteSlot::plugin, ReplicationSlotPersistentData::plugin, ReplicationSlotAcquire(), ReplicationSlotCreate(), ReplicationSlotMarkDirty(), ReplicationSlotRelease(), ReplicationSlotSave(), ReplicationSlotsComputeRequiredXmin(), reserve_wal_for_local_slot(), RemoteSlot::restart_lsn, RS_INVAL_NONE, RS_TEMPORARY, SearchNamedReplicationSlot(), SpinLockAcquire, SpinLockRelease, ReplicationSlotPersistentData::synced, RemoteSlot::two_phase, update_and_persist_local_synced_slot(), and update_local_synced_slot().
Referenced by synchronize_slots().
|
static |
Definition at line 791 of file slotsync.c.
References AccessShareLock, Assert, RemoteSlot::catalog_xmin, CommitTransactionCommand(), RemoteSlot::confirmed_lsn, RemoteSlot::database, DatumGetBool(), DatumGetLSN(), DatumGetTransactionId(), drop_local_obsolete_slots(), ereport, errmsg(), ERROR, ExecClearTuple(), RemoteSlot::failover, foreach_ptr, get_database_oid(), GetSlotInvalidationCause(), RemoteSlot::invalidated, InvalidTransactionId, InvalidXLogRecPtr, IsTransactionState(), lappend(), list_free_deep(), LockSharedObject(), MakeSingleTupleTableSlot(), RemoteSlot::name, NIL, palloc0(), pfree(), RemoteSlot::plugin, res, RemoteSlot::restart_lsn, RS_INVAL_NONE, slot_getattr(), SLOTSYNC_COLUMN_COUNT, StartTransactionCommand(), synchronize_one_slot(), TextDatumGetCString, TransactionIdIsValid, TTSOpsMinimalTuple, tuplestore_gettupleslot(), RemoteSlot::two_phase, UnlockSharedObject(), walrcv_clear_result(), walrcv_exec, WALRCV_OK_TUPLES, wrconn, and XLogRecPtrIsInvalid.
Referenced by ReplSlotSyncWorkerMain(), and SyncReplicationSlots().
void SyncReplicationSlots | ( | WalReceiverConn * | wrconn | ) |
Definition at line 1726 of file slotsync.c.
References check_and_set_sync_info(), InvalidPid, PG_END_ENSURE_ERROR_CLEANUP, PG_ENSURE_ERROR_CLEANUP, PointerGetDatum(), ReplicationSlotCleanup(), reset_syncing_flag(), slotsync_failure_callback(), synchronize_slots(), validate_remote_info(), and wrconn.
Referenced by pg_sync_replication_slots().
|
static |
Definition at line 545 of file slotsync.c.
References ReplicationSlot::data, ereport, errdetail(), errmsg(), LOG, LSN_FORMAT_ARGS, MyReplicationSlot, RemoteSlot::name, ReplicationSlotPersist(), ReplicationSlotPersistentData::restart_lsn, and update_local_synced_slot().
Referenced by synchronize_one_slot().
|
static |
Definition at line 168 of file slotsync.c.
References Assert, RemoteSlot::catalog_xmin, ReplicationSlotPersistentData::catalog_xmin, ReplicationSlotPersistentData::confirmed_flush, RemoteSlot::confirmed_lsn, ReplicationSlot::data, ReplicationSlotPersistentData::database, DEBUG1, ReplicationSlot::effective_catalog_xmin, ereport, errdetail(), errdetail_internal(), errmsg(), errmsg_internal(), ERROR, RemoteSlot::failover, ReplicationSlotPersistentData::failover, ReplicationSlotPersistentData::invalidated, LOG, LogicalSlotAdvanceAndCheckSnapState(), LSN_FORMAT_ARGS, ReplicationSlot::mutex, MyReplicationSlot, RemoteSlot::name, NameStr, namestrcpy(), ReplicationSlotPersistentData::persistency, RemoteSlot::plugin, ReplicationSlotPersistentData::plugin, ReplicationSlotMarkDirty(), ReplicationSlotSave(), ReplicationSlotsComputeRequiredLSN(), ReplicationSlotsComputeRequiredXmin(), RemoteSlot::restart_lsn, ReplicationSlotPersistentData::restart_lsn, RS_INVAL_NONE, RS_TEMPORARY, SnapBuildSnapshotExists(), SpinLockAcquire, SpinLockRelease, TransactionIdFollows(), TransactionIdPrecedes(), RemoteSlot::two_phase, and ReplicationSlotPersistentData::two_phase.
Referenced by synchronize_one_slot(), and update_and_persist_local_synced_slot().
|
static |
Definition at line 1511 of file slotsync.c.
References ReplicationSlot::active_pid, Assert, ReplicationSlot::data, GetCurrentTimestamp(), i, ReplicationSlot::in_use, ReplicationSlot::inactive_since, InvalidPid, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, ReplicationSlot::mutex, now(), SlotSyncCtxStruct::pid, ReplicationSlotCtlData::replication_slots, ReplicationSlotCtl, SlotIsLogical, SlotSyncCtx, SpinLockAcquire, SpinLockRelease, StandbyMode, ReplicationSlotPersistentData::synced, and SlotSyncCtxStruct::syncing.
Referenced by ShutDownSlotSync().
|
static |
Definition at line 934 of file slotsync.c.
References appendStringInfo(), Assert, CommitTransactionCommand(), StringInfoData::data, DatumGetBool(), elog, ereport, errcode(), errhint(), errmsg(), ERROR, ExecClearTuple(), initStringInfo(), IsTransactionState(), MakeSingleTupleTableSlot(), pfree(), PRIMARY_INFO_OUTPUT_COL_COUNT, PrimarySlotName, quote_literal_cstr(), res, slot_getattr(), StartTransactionCommand(), TTSOpsMinimalTuple, tuplestore_gettupleslot(), walrcv_clear_result(), walrcv_exec, WALRCV_OK_TUPLES, and wrconn.
Referenced by ReplSlotSyncWorkerMain(), and SyncReplicationSlots().
bool ValidateSlotSyncParams | ( | int | elevel | ) |
Definition at line 1039 of file slotsync.c.
References ereport, errcode(), errmsg(), ERROR, hot_standby_feedback, PrimaryConnInfo, PrimarySlotName, wal_level, and WAL_LEVEL_LOGICAL.
Referenced by LaunchMissingBackgroundProcesses(), and pg_sync_replication_slots().
|
static |
Definition at line 1236 of file slotsync.c.
References MAX_SLOTSYNC_WORKER_NAPTIME_MS, Min, MIN_SLOTSYNC_WORKER_NAPTIME_MS, MyLatch, ResetLatch(), sleep_ms, WaitLatch(), WL_EXIT_ON_PM_DEATH, WL_LATCH_SET, and WL_TIMEOUT.
Referenced by ReplSlotSyncWorkerMain().
|
static |
Definition at line 119 of file slotsync.c.
Referenced by do_watch(), and wait_for_slot_activity().
|
static |
Definition at line 106 of file slotsync.c.
Referenced by check_and_set_sync_info(), ReplSlotSyncWorkerMain(), reset_syncing_flag(), ShutDownSlotSync(), slotsync_reread_config(), slotsync_worker_onexit(), SlotSyncShmemInit(), SlotSyncWorkerCanRestart(), and update_synced_slots_inactive_since().
Definition at line 109 of file slotsync.c.
Referenced by LaunchMissingBackgroundProcesses(), and slotsync_reread_config().
Definition at line 129 of file slotsync.c.
Referenced by check_and_set_sync_info(), IsSyncingReplicationSlots(), reset_syncing_flag(), slotsync_failure_callback(), and slotsync_worker_onexit().