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 SlotAcquireBehavior | SlotAcquireBehavior |
typedef struct ReplicationSlotPersistentData | ReplicationSlotPersistentData |
typedef struct ReplicationSlot | ReplicationSlot |
typedef struct ReplicationSlotCtlData | ReplicationSlotCtlData |
Enumerations | |
enum | ReplicationSlotPersistency { RS_PERSISTENT, RS_EPHEMERAL, RS_TEMPORARY } |
enum | SlotAcquireBehavior { SAB_Error, SAB_Block, SAB_Inquire } |
Variables | |
PGDLLIMPORT ReplicationSlotCtlData * | ReplicationSlotCtl |
PGDLLIMPORT ReplicationSlot * | MyReplicationSlot |
PGDLLIMPORT int | max_replication_slots |
#define SlotIsLogical | ( | slot | ) | ((slot)->data.database != InvalidOid) |
Definition at line 166 of file slot.h.
Referenced by copy_replication_slot(), ProcessStandbyReplyMessage(), ReplicationSlotCreate(), ReplicationSlotDropPtr(), ReplicationSlotReserveWal(), ReplicationSlotsComputeLogicalRestartLSN(), ReplicationSlotsCountDBSlots(), ReplicationSlotsDropDBSlots(), and StartReplication().
#define SlotIsPhysical | ( | slot | ) | ((slot)->data.database == InvalidOid) |
Definition at line 165 of file slot.h.
Referenced by CreateDecodingContext(), CreateInitDecodingContext(), and pgstat_reset_replslot_counter().
typedef struct ReplicationSlot ReplicationSlot |
typedef struct ReplicationSlotCtlData ReplicationSlotCtlData |
typedef enum ReplicationSlotPersistency ReplicationSlotPersistency |
typedef struct ReplicationSlotPersistentData ReplicationSlotPersistentData |
typedef enum SlotAcquireBehavior SlotAcquireBehavior |
enum SlotAcquireBehavior |
void CheckPointReplicationSlots | ( | void | ) |
Definition at line 1270 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, SaveSlotToPath(), and sprintf.
Referenced by CheckPointGuts().
void CheckSlotRequirements | ( | void | ) |
Definition at line 1053 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().
void InvalidateObsoleteReplicationSlots | ( | XLogSegNo | oldestSegno | ) |
Definition at line 1155 of file slot.c.
References ReplicationSlot::active_cv, CHECK_FOR_INTERRUPTS, ConditionVariableCancelSleep(), ConditionVariablePrepareToSleep(), ConditionVariableTimedSleep(), ReplicationSlot::data, ereport, errmsg(), i, ReplicationSlot::in_use, ReplicationSlotPersistentData::invalidated_at, InvalidXLogRecPtr, kill, LOG, LSN_FORMAT_ARGS, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, ReplicationSlot::mutex, ReplicationSlotPersistentData::name, NameStr, ReplicationSlotCtlData::replication_slots, ReplicationSlotAcquireInternal(), ReplicationSlotMarkDirty(), ReplicationSlotRelease(), ReplicationSlotSave(), ReplicationSlotPersistentData::restart_lsn, SAB_Inquire, SpinLockAcquire, SpinLockRelease, WAIT_EVENT_REPLICATION_SLOT_DROP, wal_segment_size, XLogRecPtrIsInvalid, and XLogSegNoOffsetToRecPtr.
Referenced by CreateCheckPoint(), and CreateRestartPoint().
int ReplicationSlotAcquire | ( | const char * | name, |
SlotAcquireBehavior | behavior | ||
) |
Definition at line 375 of file slot.c.
References ReplicationSlotAcquireInternal().
Referenced by pg_logical_slot_get_changes_guts(), pg_replication_slot_advance(), ReplicationSlotDrop(), StartLogicalReplication(), and StartReplication().
void ReplicationSlotCleanup | ( | void | ) |
Definition at line 540 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, ReplicationSlotPersistentData::persistency, ReplicationSlotCtlData::replication_slots, ReplicationSlotDropPtr(), RS_TEMPORARY, SpinLockAcquire, and SpinLockRelease.
Referenced by PostgresMain(), ProcKill(), and WalSndErrorCleanup().
void ReplicationSlotCreate | ( | const char * | name, |
bool | db_specific, | ||
ReplicationSlotPersistency | p | ||
) |
Definition at line 221 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, ReplicationSlotPersistentData::name, NameStr, namestrcpy(), ReplicationSlotPersistentData::persistency, pgstat_report_replslot(), ReplicationSlotCtlData::replication_slots, ReplicationSlotValidateName(), SlotIsLogical, SpinLockAcquire, and SpinLockRelease.
Referenced by create_logical_replication_slot(), create_physical_replication_slot(), and CreateReplicationSlot().
void ReplicationSlotDrop | ( | const char * | name, |
bool | nowait | ||
) |
Definition at line 578 of file slot.c.
References Assert, ReplicationSlotAcquire(), ReplicationSlotDropAcquired(), SAB_Block, and SAB_Error.
Referenced by DropReplicationSlot(), and pg_drop_replication_slot().
void ReplicationSlotDropAtPubNode | ( | WalReceiverConn * | wrconn, |
char * | slotname, | ||
bool | missing_ok | ||
) |
Definition at line 1293 of file subscriptioncmds.c.
References appendStringInfo(), Assert, StringInfoData::data, ereport, WalRcvExecResult::err, errdetail(), errmsg(), ERROR, initStringInfo(), load_file(), LOG, NOTICE, pfree(), PG_END_TRY, PG_FINALLY, PG_TRY, quote_identifier(), WalRcvExecResult::sqlstate, WalRcvExecResult::status, walrcv_clear_result(), WALRCV_ERROR, walrcv_exec, and WALRCV_OK_COMMAND.
Referenced by AlterSubscription_refresh(), DropSubscription(), LogicalRepSyncTableStart(), and process_syncing_tables_for_sync().
void ReplicationSlotMarkDirty | ( | void | ) |
Definition at line 737 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(), CreateInitDecodingContext(), CreateReplicationSlot(), InvalidateObsoleteReplicationSlots(), LogicalConfirmReceivedLocation(), pg_logical_replication_slot_advance(), pg_logical_slot_get_changes_guts(), pg_physical_replication_slot_advance(), PhysicalConfirmReceivedLocation(), PhysicalReplicationSlotNewXmin(), and ReplicationSlotPersist().
Definition at line 885 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 754 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 484 of file slot.c.
References ReplicationSlot::active_cv, ReplicationSlot::active_pid, Assert, ConditionVariableBroadcast(), ReplicationSlot::data, ReplicationSlot::effective_xmin, InvalidTransactionId, LW_SHARED, 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(), InvalidateObsoleteReplicationSlots(), pg_create_logical_replication_slot(), pg_create_physical_replication_slot(), pg_logical_slot_get_changes_guts(), pg_replication_slot_advance(), PostgresMain(), ProcKill(), StartLogicalReplication(), StartReplication(), and WalSndErrorCleanup().
void ReplicationSlotReserveWal | ( | void | ) |
Definition at line 1078 of file slot.c.
References Assert, ReplicationSlot::data, GetRedoRecPtr(), GetXLogInsertRecPtr(), InvalidXLogRecPtr, LogStandbySnapshot(), ReplicationSlot::mutex, MyReplicationSlot, RecoveryInProgress(), ReplicationSlotsComputeRequiredLSN(), ReplicationSlotPersistentData::restart_lsn, SlotIsLogical, SpinLockAcquire, SpinLockRelease, wal_segment_size, XLByteToSeg, XLogFlush(), and XLogGetLastRemovedSegno().
Referenced by create_physical_replication_slot(), CreateInitDecodingContext(), and CreateReplicationSlot().
void ReplicationSlotSave | ( | void | ) |
Definition at line 719 of file slot.c.
References Assert, ReplicationSlot::data, ERROR, MAXPGPATH, ReplicationSlotPersistentData::name, NameStr, SaveSlotToPath(), and sprintf.
Referenced by copy_replication_slot(), create_physical_replication_slot(), CreateInitDecodingContext(), CreateReplicationSlot(), InvalidateObsoleteReplicationSlots(), LogicalConfirmReceivedLocation(), and ReplicationSlotPersist().
XLogRecPtr ReplicationSlotsComputeLogicalRestartLSN | ( | void | ) |
Definition at line 869 of file slot.c.
References ReplicationSlot::data, i, ReplicationSlot::in_use, InvalidXLogRecPtr, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, ReplicationSlot::mutex, ReplicationSlotCtlData::replication_slots, ReplicationSlotPersistentData::restart_lsn, SlotIsLogical, SpinLockAcquire, and SpinLockRelease.
Referenced by CheckPointLogicalRewriteHeap(), and CheckPointSnapBuild().
void ReplicationSlotsComputeRequiredLSN | ( | void | ) |
Definition at line 826 of file slot.c.
References Assert, ReplicationSlot::data, i, ReplicationSlot::in_use, InvalidXLogRecPtr, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, ReplicationSlot::mutex, ReplicationSlotCtlData::replication_slots, ReplicationSlotPersistentData::restart_lsn, SpinLockAcquire, SpinLockRelease, and XLogSetReplicationSlotMinimumLSN().
Referenced by copy_replication_slot(), LogicalConfirmReceivedLocation(), pg_replication_slot_advance(), PhysicalConfirmReceivedLocation(), ReplicationSlotDropPtr(), ReplicationSlotReserveWal(), and StartupReplicationSlots().
void ReplicationSlotsComputeRequiredXmin | ( | bool | already_locked | ) |
Definition at line 776 of file slot.c.
References Assert, ReplicationSlot::effective_catalog_xmin, ReplicationSlot::effective_xmin, i, ReplicationSlot::in_use, InvalidTransactionId, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_replication_slots, ReplicationSlot::mutex, ProcArraySetReplicationSlotXmin(), ReplicationSlotCtlData::replication_slots, SpinLockAcquire, SpinLockRelease, TransactionIdIsValid, and TransactionIdPrecedes().
Referenced by copy_replication_slot(), CreateInitDecodingContext(), LogicalConfirmReceivedLocation(), pg_replication_slot_advance(), PhysicalReplicationSlotNewXmin(), ReplicationSlotDropPtr(), ReplicationSlotRelease(), and StartupReplicationSlots().
Definition at line 921 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, SlotIsLogical, SpinLockAcquire, and SpinLockRelease.
Referenced by dropdb().
void ReplicationSlotsDropDBSlots | ( | Oid | dboid | ) |
Definition at line 977 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, ReplicationSlotPersistentData::name, NameStr, ReplicationSlotCtlData::replication_slots, ReplicationSlotDropAcquired(), SlotIsLogical, SpinLockAcquire, and SpinLockRelease.
Referenced by dbase_redo(), and dropdb().
void ReplicationSlotsShmemInit | ( | void | ) |
Definition at line 134 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, ReplicationSlotsShmemSize(), ShmemInitStruct(), and SpinLockInit.
Referenced by CreateSharedMemoryAndSemaphores().
Size ReplicationSlotsShmemSize | ( | void | ) |
Definition at line 116 of file slot.c.
References add_size(), max_replication_slots, mul_size(), and offsetof.
Referenced by CreateSharedMemoryAndSemaphores(), and ReplicationSlotsShmemInit().
bool ReplicationSlotValidateName | ( | const char * | name, |
int | elevel | ||
) |
Definition at line 174 of file slot.c.
References ereport, errcode(), errhint(), errmsg(), and NAMEDATALEN.
Referenced by check_primary_slot_name(), ReplicationSlotCreate(), and StartupReorderBuffer().
ReplicationSlot* SearchNamedReplicationSlot | ( | const char * | name | ) |
Definition at line 343 of file slot.c.
References Assert, ReplicationSlot::data, i, ReplicationSlot::in_use, LW_SHARED, LWLockHeldByMeInMode(), max_replication_slots, ReplicationSlotPersistentData::name, NameStr, and ReplicationSlotCtlData::replication_slots.
Referenced by pgstat_reset_replslot_counter(), and ReplicationSlotAcquireInternal().
void StartupReplicationSlots | ( | void | ) |
Definition at line 1305 of file slot.c.
References AllocateDir(), dirent::d_name, DEBUG1, elog, ereport, errmsg(), FreeDir(), fsync_fname(), lstat, max_replication_slots, MAXPGPATH, pg_str_endswith(), ReadDir(), ReplicationSlotsComputeRequiredLSN(), ReplicationSlotsComputeRequiredXmin(), RestoreSlotFromDisk(), rmtree(), S_ISDIR, snprintf, stat::st_mode, and WARNING.
Referenced by StartupXLOG().
PGDLLIMPORT int max_replication_slots |
Definition at line 99 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(), pgstat_read_statsfiles(), pgstat_replslot_index(), ReplicationOriginShmemInit(), ReplicationOriginShmemSize(), ReplicationSlotCleanup(), ReplicationSlotCreate(), ReplicationSlotsComputeLogicalRestartLSN(), ReplicationSlotsComputeRequiredLSN(), ReplicationSlotsComputeRequiredXmin(), ReplicationSlotsCountDBSlots(), ReplicationSlotsDropDBSlots(), ReplicationSlotsShmemInit(), ReplicationSlotsShmemSize(), replorigin_advance(), replorigin_check_prerequisites(), replorigin_drop_guts(), replorigin_get_progress(), replorigin_redo(), replorigin_session_reset(), replorigin_session_setup(), RestoreSlotFromDisk(), SearchNamedReplicationSlot(), StartupReplicationOrigin(), and StartupReplicationSlots().
PGDLLIMPORT ReplicationSlot* MyReplicationSlot |
Definition at line 96 of file slot.c.
Referenced by copy_replication_slot(), create_logical_replication_slot(), create_physical_replication_slot(), CreateDecodingContext(), CreateInitDecodingContext(), CreateReplicationSlot(), 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(), ProcKill(), ReorderBufferAllocate(), ReorderBufferFree(), ReorderBufferRestoreChanges(), ReorderBufferRestoreCleanup(), ReorderBufferSerializedPath(), ReorderBufferSerializeTXN(), ReplicationSlotDropAcquired(), ReplicationSlotMarkDirty(), ReplicationSlotPersist(), ReplicationSlotRelease(), ReplicationSlotReserveWal(), StartLogicalReplication(), StartReplication(), StartupDecodingContext(), and WalSndErrorCleanup().
PGDLLIMPORT ReplicationSlotCtlData* ReplicationSlotCtl |
Definition at line 93 of file slot.c.
Referenced by copy_replication_slot(), and pg_get_replication_slots().