PostgreSQL Source Code
git master
|
#include "access/xlog.h"
#include "access/xlogreader.h"
#include "storage/condition_variable.h"
#include "storage/lwlock.h"
#include "storage/shmem.h"
#include "storage/spin.h"
#include "replication/walreceiver.h"
Go to the source code of this file.
Data Structures | |
struct | ReplicationSlotPersistentData |
struct | ReplicationSlot |
struct | ReplicationSlotCtlData |
Macros | |
#define | SlotIsPhysical(slot) ((slot)->data.database == InvalidOid) |
#define | SlotIsLogical(slot) ((slot)->data.database != InvalidOid) |
Typedefs | |
typedef enum ReplicationSlotPersistency | ReplicationSlotPersistency |
typedef enum ReplicationSlotInvalidationCause | ReplicationSlotInvalidationCause |
typedef struct ReplicationSlotPersistentData | ReplicationSlotPersistentData |
typedef struct ReplicationSlot | ReplicationSlot |
typedef struct ReplicationSlotCtlData | ReplicationSlotCtlData |
Enumerations | |
enum | ReplicationSlotPersistency { RS_PERSISTENT , RS_EPHEMERAL , RS_TEMPORARY } |
enum | ReplicationSlotInvalidationCause { RS_INVAL_NONE , RS_INVAL_WAL_REMOVED , RS_INVAL_HORIZON , RS_INVAL_WAL_LEVEL } |
Variables | |
PGDLLIMPORT ReplicationSlotCtlData * | ReplicationSlotCtl |
PGDLLIMPORT ReplicationSlot * | MyReplicationSlot |
PGDLLIMPORT int | max_replication_slots |
#define SlotIsLogical | ( | slot | ) | ((slot)->data.database != InvalidOid) |
#define SlotIsPhysical | ( | slot | ) | ((slot)->data.database == InvalidOid) |
typedef struct ReplicationSlot ReplicationSlot |
typedef struct ReplicationSlotCtlData ReplicationSlotCtlData |
typedef enum ReplicationSlotPersistency ReplicationSlotPersistency |
typedef struct ReplicationSlotPersistentData ReplicationSlotPersistentData |
void CheckPointReplicationSlots | ( | void | ) |
Definition at line 1572 of file slot.c.
References ReplicationSlot::data, DEBUG1, elog(), i, ReplicationSlot::in_use, LOG, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, MAXPGPATH, ReplicationSlotPersistentData::name, NameStr, ReplicationSlotCtlData::replication_slots, ReplicationSlotCtl, SaveSlotToPath(), and sprintf.
Referenced by CheckPointGuts().
void CheckSlotPermissions | ( | void | ) |
Definition at line 1157 of file slot.c.
References ereport, errcode(), errdetail(), errmsg(), ERROR, GetUserId(), and has_rolreplication().
Referenced by copy_replication_slot(), pg_create_logical_replication_slot(), pg_create_physical_replication_slot(), pg_drop_replication_slot(), pg_logical_slot_get_changes_guts(), and pg_replication_slot_advance().
void CheckSlotRequirements | ( | void | ) |
Definition at line 1135 of file slot.c.
References ereport, errcode(), errmsg(), ERROR, max_replication_slots, wal_level, and WAL_LEVEL_REPLICA.
Referenced by CheckLogicalDecodingRequirements(), copy_replication_slot(), pg_create_physical_replication_slot(), and pg_drop_replication_slot().
bool InvalidateObsoleteReplicationSlots | ( | ReplicationSlotInvalidationCause | cause, |
XLogSegNo | oldestSegno, | ||
Oid | dboid, | ||
TransactionId | snapshotConflictHorizon | ||
) |
Definition at line 1518 of file slot.c.
References Assert(), i, ReplicationSlot::in_use, InvalidatePossiblyObsoleteSlot(), LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, ReplicationSlotCtlData::replication_slots, ReplicationSlotCtl, ReplicationSlotsComputeRequiredLSN(), ReplicationSlotsComputeRequiredXmin(), RS_INVAL_HORIZON, RS_INVAL_NONE, RS_INVAL_WAL_REMOVED, TransactionIdIsValid, wal_segment_size, and XLogSegNoOffsetToRecPtr.
Referenced by CreateCheckPoint(), CreateRestartPoint(), ResolveRecoveryConflictWithSnapshot(), and xlog_redo().
void ReplicationSlotAcquire | ( | const char * | name, |
bool | nowait | ||
) |
Definition at line 451 of file slot.c.
References ReplicationSlot::active_cv, ReplicationSlot::active_pid, Assert(), ConditionVariableBroadcast(), ConditionVariableCancelSleep(), ConditionVariablePrepareToSleep(), ConditionVariableSleep(), ReplicationSlot::data, ereport, errcode(), errmsg(), ERROR, ReplicationSlot::in_use, IsUnderPostmaster, LW_SHARED, LWLockAcquire(), LWLockRelease(), ReplicationSlot::mutex, MyProcPid, MyReplicationSlot, name, ReplicationSlotPersistentData::name, NameStr, pgstat_acquire_replslot(), SearchNamedReplicationSlot(), SlotIsLogical, SpinLockAcquire, SpinLockRelease, and WAIT_EVENT_REPLICATION_SLOT_DROP.
Referenced by pg_logical_slot_get_changes_guts(), pg_replication_slot_advance(), ReplicationSlotDrop(), StartLogicalReplication(), and StartReplication().
void ReplicationSlotCleanup | ( | void | ) |
Definition at line 604 of file slot.c.
References ReplicationSlot::active_cv, ReplicationSlot::active_pid, Assert(), ConditionVariableBroadcast(), ReplicationSlot::data, i, ReplicationSlot::in_use, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, ReplicationSlot::mutex, MyProcPid, MyReplicationSlot, ReplicationSlotPersistentData::persistency, ReplicationSlotCtlData::replication_slots, ReplicationSlotCtl, ReplicationSlotDropPtr(), RS_TEMPORARY, SpinLockAcquire, and SpinLockRelease.
Referenced by PostgresMain(), ReplicationSlotShmemExit(), and WalSndErrorCleanup().
void ReplicationSlotCreate | ( | const char * | name, |
bool | db_specific, | ||
ReplicationSlotPersistency | persistency, | ||
bool | two_phase | ||
) |
Definition at line 253 of file slot.c.
References ReplicationSlot::active_cv, ReplicationSlot::active_pid, Assert(), ReplicationSlot::candidate_catalog_xmin, ReplicationSlot::candidate_restart_lsn, ReplicationSlot::candidate_restart_valid, ReplicationSlot::candidate_xmin_lsn, ConditionVariableBroadcast(), CreateSlotOnDisk(), ReplicationSlot::data, ReplicationSlotPersistentData::database, ReplicationSlot::dirty, ReplicationSlot::effective_catalog_xmin, ReplicationSlot::effective_xmin, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errhint(), errmsg(), ERROR, i, ReplicationSlot::in_use, InvalidOid, InvalidTransactionId, InvalidXLogRecPtr, ReplicationSlot::just_dirtied, LW_EXCLUSIVE, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, ReplicationSlot::mutex, MyDatabaseId, MyProcPid, MyReplicationSlot, name, ReplicationSlotPersistentData::name, NameStr, namestrcpy(), ReplicationSlotPersistentData::persistency, pgstat_create_replslot(), ReplicationSlotCtlData::replication_slots, ReplicationSlotCtl, ReplicationSlotValidateName(), SlotIsLogical, SpinLockAcquire, SpinLockRelease, two_phase, ReplicationSlotPersistentData::two_phase, and ReplicationSlotPersistentData::two_phase_at.
Referenced by create_logical_replication_slot(), create_physical_replication_slot(), and CreateReplicationSlot().
void ReplicationSlotDrop | ( | const char * | name, |
bool | nowait | ||
) |
Definition at line 642 of file slot.c.
References Assert(), MyReplicationSlot, name, ReplicationSlotAcquire(), and ReplicationSlotDropAcquired().
Referenced by DropReplicationSlot(), and pg_drop_replication_slot().
void ReplicationSlotDropAtPubNode | ( | WalReceiverConn * | wrconn, |
char * | slotname, | ||
bool | missing_ok | ||
) |
Definition at line 1754 of file subscriptioncmds.c.
References appendStringInfo(), Assert(), StringInfoData::data, ereport, errcode(), errmsg(), ERROR, initStringInfo(), load_file(), LOG, NOTICE, pfree(), PG_END_TRY, PG_FINALLY, PG_TRY, quote_identifier(), res, walrcv_clear_result(), WALRCV_ERROR, walrcv_exec, WALRCV_OK_COMMAND, and wrconn.
Referenced by AlterSubscription_refresh(), DropSubscription(), LogicalRepSyncTableStart(), and process_syncing_tables_for_sync().
int ReplicationSlotIndex | ( | ReplicationSlot * | slot | ) |
Definition at line 408 of file slot.c.
References Assert(), max_replication_slots, ReplicationSlotCtlData::replication_slots, and ReplicationSlotCtl.
Referenced by get_replslot_index(), pgstat_acquire_replslot(), pgstat_create_replslot(), pgstat_drop_replslot(), pgstat_report_replslot(), and pgstat_reset_replslot().
void ReplicationSlotInitialize | ( | void | ) |
Definition at line 171 of file slot.c.
References before_shmem_exit(), and ReplicationSlotShmemExit().
Referenced by BaseInit().
void ReplicationSlotMarkDirty | ( | void | ) |
Definition at line 797 of file slot.c.
References Assert(), ReplicationSlot::dirty, ReplicationSlot::just_dirtied, ReplicationSlot::mutex, MyReplicationSlot, SpinLockAcquire, and SpinLockRelease.
Referenced by copy_replication_slot(), create_physical_replication_slot(), CreateDecodingContext(), CreateInitDecodingContext(), CreateReplicationSlot(), InvalidatePossiblyObsoleteSlot(), LogicalConfirmReceivedLocation(), pg_logical_replication_slot_advance(), pg_logical_slot_get_changes_guts(), pg_physical_replication_slot_advance(), PhysicalConfirmReceivedLocation(), PhysicalReplicationSlotNewXmin(), and ReplicationSlotPersist().
Definition at line 424 of file slot.c.
References ReplicationSlot::data, ReplicationSlot::in_use, LW_SHARED, LWLockAcquire(), LWLockRelease(), name, ReplicationSlotPersistentData::name, NameStr, namestrcpy(), ReplicationSlotCtlData::replication_slots, and ReplicationSlotCtl.
Referenced by pgstat_replslot_to_serialized_name_cb().
Definition at line 1228 of file tablesync.c.
References GetSystemIdentifier(), snprintf, and UINT64_FORMAT.
Referenced by AlterSubscription_refresh(), DropSubscription(), LogicalRepSyncTableStart(), process_syncing_tables_for_sync(), and ReportSlotConnectionError().
void ReplicationSlotPersist | ( | void | ) |
Definition at line 814 of file slot.c.
References Assert(), ReplicationSlot::data, ReplicationSlot::mutex, MyReplicationSlot, ReplicationSlotPersistentData::persistency, ReplicationSlotMarkDirty(), ReplicationSlotSave(), RS_PERSISTENT, SpinLockAcquire, and SpinLockRelease.
Referenced by copy_replication_slot(), CreateReplicationSlot(), and pg_create_logical_replication_slot().
void ReplicationSlotRelease | ( | void | ) |
Definition at line 548 of file slot.c.
References ReplicationSlot::active_cv, ReplicationSlot::active_pid, Assert(), ConditionVariableBroadcast(), ReplicationSlot::data, ReplicationSlot::effective_xmin, InvalidTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), ReplicationSlot::mutex, MyProc, MyReplicationSlot, ReplicationSlotPersistentData::persistency, PGPROC::pgxactoff, PROC_IN_LOGICAL_DECODING, ProcGlobal, ReplicationSlotDropAcquired(), ReplicationSlotsComputeRequiredXmin(), RS_EPHEMERAL, RS_PERSISTENT, SpinLockAcquire, SpinLockRelease, PGPROC::statusFlags, PROC_HDR::statusFlags, TransactionIdIsValid, and ReplicationSlotPersistentData::xmin.
Referenced by copy_replication_slot(), CreateReplicationSlot(), InvalidatePossiblyObsoleteSlot(), pg_create_logical_replication_slot(), pg_create_physical_replication_slot(), pg_logical_slot_get_changes_guts(), pg_replication_slot_advance(), PostgresMain(), ReplicationSlotShmemExit(), StartLogicalReplication(), StartReplication(), and WalSndErrorCleanup().
void ReplicationSlotReserveWal | ( | void | ) |
Definition at line 1174 of file slot.c.
References Assert(), ReplicationSlot::data, GetRedoRecPtr(), GetXLogInsertRecPtr(), GetXLogReplayRecPtr(), InvalidXLogRecPtr, LogStandbySnapshot(), ReplicationSlot::mutex, MyReplicationSlot, RecoveryInProgress(), ReplicationSlotsComputeRequiredLSN(), ReplicationSlotPersistentData::restart_lsn, SlotIsLogical, SlotIsPhysical, SpinLockAcquire, SpinLockRelease, wal_segment_size, XLByteToSeg, XLogFlush(), and XLogGetLastRemovedSegno().
Referenced by create_physical_replication_slot(), CreateInitDecodingContext(), and CreateReplicationSlot().
void ReplicationSlotSave | ( | void | ) |
Definition at line 779 of file slot.c.
References Assert(), ReplicationSlot::data, ERROR, MAXPGPATH, MyReplicationSlot, ReplicationSlotPersistentData::name, NameStr, SaveSlotToPath(), and sprintf.
Referenced by copy_replication_slot(), create_physical_replication_slot(), CreateDecodingContext(), CreateInitDecodingContext(), CreateReplicationSlot(), InvalidatePossiblyObsoleteSlot(), LogicalConfirmReceivedLocation(), and ReplicationSlotPersist().
XLogRecPtr ReplicationSlotsComputeLogicalRestartLSN | ( | void | ) |
Definition at line 941 of file slot.c.
References ReplicationSlot::data, i, ReplicationSlot::in_use, ReplicationSlotPersistentData::invalidated, InvalidXLogRecPtr, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, ReplicationSlot::mutex, ReplicationSlotCtlData::replication_slots, ReplicationSlotCtl, ReplicationSlotPersistentData::restart_lsn, RS_INVAL_NONE, SlotIsLogical, SpinLockAcquire, and SpinLockRelease.
Referenced by CheckPointLogicalRewriteHeap(), and CheckPointSnapBuild().
void ReplicationSlotsComputeRequiredLSN | ( | void | ) |
Definition at line 892 of file slot.c.
References Assert(), ReplicationSlot::data, i, ReplicationSlot::in_use, ReplicationSlotPersistentData::invalidated, InvalidXLogRecPtr, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, ReplicationSlot::mutex, ReplicationSlotCtlData::replication_slots, ReplicationSlotCtl, ReplicationSlotPersistentData::restart_lsn, RS_INVAL_NONE, SpinLockAcquire, SpinLockRelease, and XLogSetReplicationSlotMinimumLSN().
Referenced by copy_replication_slot(), InvalidateObsoleteReplicationSlots(), LogicalConfirmReceivedLocation(), pg_replication_slot_advance(), PhysicalConfirmReceivedLocation(), ReplicationSlotDropPtr(), ReplicationSlotReserveWal(), and StartupReplicationSlots().
void ReplicationSlotsComputeRequiredXmin | ( | bool | already_locked | ) |
Definition at line 836 of file slot.c.
References Assert(), ReplicationSlot::data, ReplicationSlot::effective_catalog_xmin, ReplicationSlot::effective_xmin, i, ReplicationSlot::in_use, ReplicationSlotPersistentData::invalidated, InvalidTransactionId, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, ReplicationSlot::mutex, ProcArraySetReplicationSlotXmin(), ReplicationSlotCtlData::replication_slots, ReplicationSlotCtl, RS_INVAL_NONE, SpinLockAcquire, SpinLockRelease, TransactionIdIsValid, and TransactionIdPrecedes().
Referenced by copy_replication_slot(), CreateInitDecodingContext(), InvalidateObsoleteReplicationSlots(), LogicalConfirmReceivedLocation(), pg_replication_slot_advance(), PhysicalReplicationSlotNewXmin(), ReplicationSlotDropPtr(), ReplicationSlotRelease(), and StartupReplicationSlots().
Definition at line 999 of file slot.c.
References ReplicationSlot::active_pid, ReplicationSlot::data, ReplicationSlotPersistentData::database, i, ReplicationSlot::in_use, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, ReplicationSlot::mutex, ReplicationSlotCtlData::replication_slots, ReplicationSlotCtl, SlotIsLogical, SpinLockAcquire, and SpinLockRelease.
Referenced by dropdb().
void ReplicationSlotsDropDBSlots | ( | Oid | dboid | ) |
Definition at line 1057 of file slot.c.
References ReplicationSlot::active_pid, ReplicationSlot::data, ReplicationSlotPersistentData::database, ereport, errcode(), errmsg(), ERROR, i, ReplicationSlot::in_use, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, ReplicationSlot::mutex, MyProcPid, MyReplicationSlot, ReplicationSlotPersistentData::name, NameStr, ReplicationSlotCtlData::replication_slots, ReplicationSlotCtl, ReplicationSlotDropAcquired(), SlotIsLogical, SpinLockAcquire, and SpinLockRelease.
Referenced by dbase_redo(), and dropdb().
void ReplicationSlotsShmemInit | ( | void | ) |
Definition at line 136 of file slot.c.
References ReplicationSlot::active_cv, ConditionVariableInit(), i, ReplicationSlot::io_in_progress_lock, LWLockInitialize(), LWTRANCHE_REPLICATION_SLOT_IO, max_replication_slots, MemSet, ReplicationSlot::mutex, ReplicationSlotCtlData::replication_slots, ReplicationSlotCtl, ReplicationSlotsShmemSize(), ShmemInitStruct(), and SpinLockInit.
Referenced by CreateSharedMemoryAndSemaphores().
Size ReplicationSlotsShmemSize | ( | void | ) |
Definition at line 118 of file slot.c.
References add_size(), max_replication_slots, and mul_size().
Referenced by CalculateShmemSize(), and ReplicationSlotsShmemInit().
bool ReplicationSlotValidateName | ( | const char * | name, |
int | elevel | ||
) |
Definition at line 199 of file slot.c.
References ereport, errcode(), errhint(), errmsg(), name, and NAMEDATALEN.
Referenced by check_primary_slot_name(), parse_subscription_options(), ReplicationSlotCreate(), and StartupReorderBuffer().
ReplicationSlot* SearchNamedReplicationSlot | ( | const char * | name, |
bool | need_lock | ||
) |
Definition at line 375 of file slot.c.
References ReplicationSlot::data, i, ReplicationSlot::in_use, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, name, ReplicationSlotPersistentData::name, NameStr, ReplicationSlotCtlData::replication_slots, and ReplicationSlotCtl.
Referenced by get_replslot_index(), pg_ls_replslotdir(), pgstat_reset_replslot(), ReadReplicationSlot(), and ReplicationSlotAcquire().
void StartupReplicationSlots | ( | void | ) |
Definition at line 1607 of file slot.c.
References AllocateDir(), dirent::d_name, DEBUG1, elog(), ereport, errmsg(), FreeDir(), fsync_fname(), get_dirent_type(), max_replication_slots, MAXPGPATH, pg_str_endswith(), PGFILETYPE_DIR, PGFILETYPE_ERROR, ReadDir(), ReplicationSlotsComputeRequiredLSN(), ReplicationSlotsComputeRequiredXmin(), RestoreSlotFromDisk(), rmtree(), snprintf, and WARNING.
Referenced by StartupXLOG().
|
extern |
Definition at line 102 of file slot.c.
Referenced by CheckPointReplicationOrigin(), CheckPointReplicationSlots(), CheckSlotRequirements(), copy_replication_slot(), InvalidateObsoleteReplicationSlots(), logicalrep_worker_launch(), pg_get_replication_slots(), pg_show_replication_origin_status(), ReplicationOriginShmemInit(), ReplicationOriginShmemSize(), ReplicationSlotCleanup(), ReplicationSlotCreate(), ReplicationSlotIndex(), ReplicationSlotsComputeLogicalRestartLSN(), ReplicationSlotsComputeRequiredLSN(), ReplicationSlotsComputeRequiredXmin(), ReplicationSlotsCountDBSlots(), ReplicationSlotsDropDBSlots(), ReplicationSlotsShmemInit(), ReplicationSlotsShmemSize(), replorigin_advance(), replorigin_check_prerequisites(), replorigin_get_progress(), replorigin_redo(), replorigin_session_reset(), replorigin_session_setup(), replorigin_state_clear(), RestoreSlotFromDisk(), SearchNamedReplicationSlot(), StartupReplicationOrigin(), and StartupReplicationSlots().
|
extern |
Definition at line 99 of file slot.c.
Referenced by copy_replication_slot(), create_logical_replication_slot(), create_physical_replication_slot(), CreateDecodingContext(), CreateInitDecodingContext(), CreateReplicationSlot(), InvalidatePossiblyObsoleteSlot(), LogicalConfirmReceivedLocation(), LogicalIncreaseRestartDecodingForSlot(), LogicalIncreaseXminForSlot(), pg_create_logical_replication_slot(), pg_create_physical_replication_slot(), pg_logical_replication_slot_advance(), pg_logical_slot_get_changes_guts(), pg_physical_replication_slot_advance(), pg_replication_slot_advance(), PhysicalConfirmReceivedLocation(), PhysicalReplicationSlotNewXmin(), PostgresMain(), ProcessStandbyHSFeedbackMessage(), ProcessStandbyReplyMessage(), ReorderBufferAllocate(), ReorderBufferFree(), ReorderBufferRestoreChanges(), ReorderBufferRestoreCleanup(), ReorderBufferSerializedPath(), ReorderBufferSerializeTXN(), ReplicationSlotAcquire(), ReplicationSlotCleanup(), ReplicationSlotCreate(), ReplicationSlotDrop(), ReplicationSlotDropAcquired(), ReplicationSlotMarkDirty(), ReplicationSlotPersist(), ReplicationSlotRelease(), ReplicationSlotReserveWal(), ReplicationSlotSave(), ReplicationSlotsDropDBSlots(), ReplicationSlotShmemExit(), StartLogicalReplication(), StartReplication(), StartupDecodingContext(), and WalSndErrorCleanup().
|
extern |
Definition at line 96 of file slot.c.
Referenced by CheckPointReplicationSlots(), copy_replication_slot(), InvalidateObsoleteReplicationSlots(), pg_get_replication_slots(), ReplicationSlotCleanup(), ReplicationSlotCreate(), ReplicationSlotIndex(), ReplicationSlotName(), ReplicationSlotsComputeLogicalRestartLSN(), ReplicationSlotsComputeRequiredLSN(), ReplicationSlotsComputeRequiredXmin(), ReplicationSlotsCountDBSlots(), ReplicationSlotsDropDBSlots(), ReplicationSlotsShmemInit(), RestoreSlotFromDisk(), and SearchNamedReplicationSlot().