PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <sys/stat.h>
#include <unistd.h>
#include "access/heapam_xlog.h"
#include "access/transam.h"
#include "access/xact.h"
#include "common/file_utils.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "replication/logical.h"
#include "replication/reorderbuffer.h"
#include "replication/snapbuild.h"
#include "replication/snapbuild_internal.h"
#include "storage/fd.h"
#include "storage/lmgr.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "storage/standby.h"
#include "utils/builtins.h"
#include "utils/memutils.h"
#include "utils/snapmgr.h"
#include "utils/snapshot.h"
Go to the source code of this file.
Macros | |
#define | SnapBuildOnDiskConstantSize offsetof(SnapBuildOnDisk, builder) |
#define | SnapBuildOnDiskNotChecksummedSize offsetof(SnapBuildOnDisk, version) |
#define | SNAPBUILD_MAGIC 0x51A1E001 |
#define | SNAPBUILD_VERSION 6 |
Variables | |
static ResourceOwner | SavedResourceOwnerDuringExport = NULL |
static bool | ExportInProgress = false |
#define SNAPBUILD_MAGIC 0x51A1E001 |
Definition at line 1426 of file snapbuild.c.
#define SNAPBUILD_VERSION 6 |
Definition at line 1427 of file snapbuild.c.
#define SnapBuildOnDiskConstantSize offsetof(SnapBuildOnDisk, builder) |
Definition at line 1421 of file snapbuild.c.
#define SnapBuildOnDiskNotChecksummedSize offsetof(SnapBuildOnDisk, version) |
Definition at line 1423 of file snapbuild.c.
SnapBuild* AllocateSnapshotBuilder | ( | ReorderBuffer * | reorder, |
TransactionId | xmin_horizon, | ||
XLogRecPtr | start_lsn, | ||
bool | need_full_snapshot, | ||
bool | in_slot_creation, | ||
XLogRecPtr | two_phase_at | ||
) |
Definition at line 185 of file snapbuild.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, SnapBuild::building_full_snapshot, SnapBuild::catchange, SnapBuild::committed, context, SnapBuild::context, CurrentMemoryContext, SnapBuild::in_slot_creation, SnapBuild::includes_all_transactions, SnapBuild::initial_xmin_horizon, MemoryContextSwitchTo(), palloc0(), SnapBuild::reorder, SNAPBUILD_START, SnapBuild::start_decoding_at, SnapBuild::state, SnapBuild::two_phase_at, SnapBuild::xcnt, SnapBuild::xcnt_space, and SnapBuild::xip.
Referenced by StartupDecodingContext().
void CheckPointSnapBuild | ( | void | ) |
Definition at line 1922 of file snapbuild.c.
References AllocateDir(), dirent::d_name, DEBUG1, elog, ereport, errcode_for_file_access(), errmsg(), FreeDir(), get_dirent_type(), GetRedoRecPtr(), InvalidXLogRecPtr, LOG, MAXPGPATH, PG_LOGICAL_SNAPSHOTS_DIR, PGFILETYPE_ERROR, PGFILETYPE_REG, ReadDir(), ReplicationSlotsComputeLogicalRestartLSN(), and snprintf.
Referenced by CheckPointGuts().
void FreeSnapshotBuilder | ( | SnapBuild * | builder | ) |
Definition at line 233 of file snapbuild.c.
References context, SnapBuild::context, MemoryContextDelete(), SnapBuildSnapDecRefcount(), and SnapBuild::snapshot.
Referenced by FreeDecodingContext().
|
static |
Definition at line 784 of file snapbuild.c.
References Assert, SnapBuild::committed, DEBUG1, elog, repalloc(), TransactionIdIsValid, SnapBuild::xcnt, SnapBuild::xcnt_space, and SnapBuild::xip.
Referenced by SnapBuildCommitTxn().
Definition at line 360 of file snapbuild.c.
References SnapshotData::active_count, Assert, SnapBuild::committed, SnapBuild::context, SnapshotData::copied, SnapshotData::curcid, FirstCommandId, MemoryContextAllocZero(), qsort, SnapshotData::regd_count, SNAPBUILD_FULL_SNAPSHOT, SNAPSHOT_HISTORIC_MVCC, SnapshotData::snapshot_type, SnapshotData::snapXactCompletionCount, SnapBuild::state, SnapshotData::suboverflowed, SnapshotData::subxcnt, SnapshotData::subxip, SnapshotData::takenDuringRecovery, TransactionIdIsNormal, SnapBuild::xcnt, SnapshotData::xcnt, xidComparator(), SnapBuild::xip, SnapshotData::xip, SnapBuild::xmax, SnapshotData::xmax, SnapBuild::xmin, and SnapshotData::xmin.
Referenced by SnapBuildCommitTxn(), SnapBuildGetOrBuildSnapshot(), SnapBuildInitialSnapshot(), SnapBuildProcessChange(), and SnapBuildRestore().
void SnapBuildClearExportedSnapshot | ( | void | ) |
Definition at line 600 of file snapbuild.c.
References AbortCurrentTransaction(), CurrentResourceOwner, elog, ERROR, ExportInProgress, IsTransactionState(), and SavedResourceOwnerDuringExport.
Referenced by exec_replication_command().
void SnapBuildCommitTxn | ( | SnapBuild * | builder, |
XLogRecPtr | lsn, | ||
TransactionId | xid, | ||
int | nsubxacts, | ||
TransactionId * | subxacts, | ||
uint32 | xinfo | ||
) |
Definition at line 895 of file snapbuild.c.
References Assert, SnapBuild::building_full_snapshot, SnapBuild::committed, DEBUG1, DEBUG2, elog, SnapBuild::includes_all_transactions, SnapBuild::next_phase_at, NormalTransactionIdFollows, SnapBuild::reorder, ReorderBufferSetBaseSnapshot(), ReorderBufferXidHasBaseSnapshot(), SNAPBUILD_BUILDING_SNAPSHOT, SNAPBUILD_CONSISTENT, SNAPBUILD_FULL_SNAPSHOT, SNAPBUILD_START, SnapBuildAddCommittedTxn(), SnapBuildBuildSnapshot(), SnapBuildDistributeNewCatalogSnapshot(), SnapBuildSnapDecRefcount(), SnapBuildSnapIncRefcount(), SnapBuildXidHasCatalogChanges(), SnapBuild::snapshot, SnapBuild::start_decoding_at, SnapBuild::state, TransactionIdAdvance, TransactionIdFollowsOrEquals(), TransactionIdIsValid, TransactionIdPrecedes(), and SnapBuild::xmax.
Referenced by DecodeCommit().
SnapBuildState SnapBuildCurrentState | ( | SnapBuild * | builder | ) |
Definition at line 277 of file snapbuild.c.
References SnapBuild::state.
Referenced by DecodePrepare(), DecodingContextReady(), heap2_decode(), heap_decode(), logicalmsg_decode(), ReorderBufferCanStartStreaming(), and xact_decode().
|
static |
Definition at line 731 of file snapbuild.c.
References Assert, dlist_iter::cur, DEBUG2, dlist_container, dlist_foreach, elog, LSN_FORMAT_ARGS, rbtxn_prepared, rbtxn_skip_prepared, SnapBuild::reorder, ReorderBufferAddSnapshot(), ReorderBufferXidHasBaseSnapshot(), SnapBuildSnapIncRefcount(), SnapBuild::snapshot, ReorderBuffer::toplevel_by_lsn, TransactionIdIsValid, and ReorderBufferTXN::xid.
Referenced by SnapBuildCommitTxn().
const char* SnapBuildExportSnapshot | ( | SnapBuild * | builder | ) |
Definition at line 539 of file snapbuild.c.
References CurrentResourceOwner, elog, ereport, errmsg_plural(), ERROR, ExportInProgress, ExportSnapshot(), IsTransactionOrTransactionBlock(), LOG, SavedResourceOwnerDuringExport, SnapBuildInitialSnapshot(), StartTransactionCommand(), XACT_REPEATABLE_READ, XactIsoLevel, XactReadOnly, and SnapshotData::xcnt.
Referenced by CreateReplicationSlot().
|
static |
Definition at line 1190 of file snapbuild.c.
References Assert, SnapBuild::building_full_snapshot, DEBUG1, ereport, errdetail(), errdetail_internal(), errmsg(), errmsg_internal(), SnapBuild::in_slot_creation, SnapBuild::initial_xmin_horizon, InvalidTransactionId, InvalidXLogRecPtr, LOG, LSN_FORMAT_ARGS, SnapBuild::next_phase_at, xl_running_xacts::nextXid, NormalTransactionIdPrecedes, xl_running_xacts::oldestRunningXid, SNAPBUILD_BUILDING_SNAPSHOT, SNAPBUILD_CONSISTENT, SNAPBUILD_FULL_SNAPSHOT, SNAPBUILD_START, SnapBuildRestore(), SnapBuildWaitSnapshot(), SnapBuild::start_decoding_at, SnapBuild::state, TransactionIdIsNormal, TransactionIdPrecedesOrEquals(), xl_running_xacts::xcnt, SnapBuild::xmax, and SnapBuild::xmin.
Referenced by SnapBuildProcessRunningXacts().
|
static |
Definition at line 252 of file snapbuild.c.
References SnapshotData::active_count, Assert, SnapshotData::copied, SnapshotData::curcid, elog, ERROR, FirstCommandId, pfree(), SnapshotData::regd_count, SNAPSHOT_HISTORIC_MVCC, SnapshotData::snapshot_type, SnapshotData::suboverflowed, and SnapshotData::takenDuringRecovery.
Referenced by SnapBuildSnapDecRefcount().
Definition at line 579 of file snapbuild.c.
References Assert, SNAPBUILD_CONSISTENT, SnapBuildBuildSnapshot(), SnapBuildSnapIncRefcount(), SnapBuild::snapshot, and SnapBuild::state.
Referenced by logicalmsg_decode().
XLogRecPtr SnapBuildGetTwoPhaseAt | ( | SnapBuild * | builder | ) |
Definition at line 286 of file snapbuild.c.
References SnapBuild::two_phase_at.
Referenced by DecodeCommit().
Definition at line 440 of file snapbuild.c.
References Assert, SnapBuild::building_full_snapshot, SnapBuild::committed, elog, ereport, errcode(), ERRCODE_T_R_SERIALIZATION_FAILURE, errmsg(), ERROR, GetMaxSnapshotXidCount(), GetOldestSafeDecodingTransactionId(), HaveRegisteredOrActiveSnapshot(), HistoricSnapshotActive(), SnapBuild::includes_all_transactions, InvalidateCatalogSnapshot(), LW_SHARED, LWLockAcquire(), LWLockRelease(), MyProc, NormalTransactionIdPrecedes, palloc(), SNAPBUILD_CONSISTENT, SnapBuildBuildSnapshot(), SNAPSHOT_MVCC, SnapshotData::snapshot_type, SnapBuild::state, test(), TransactionIdAdvance, TransactionIdFollows(), TransactionIdIsValid, XACT_REPEATABLE_READ, XactIsoLevel, SnapshotData::xcnt, xidComparator(), SnapshotData::xip, SnapshotData::xmax, PGPROC::xmin, and SnapshotData::xmin.
Referenced by CreateReplicationSlot(), and SnapBuildExportSnapshot().
bool SnapBuildProcessChange | ( | SnapBuild * | builder, |
TransactionId | xid, | ||
XLogRecPtr | lsn | ||
) |
Definition at line 639 of file snapbuild.c.
References SnapBuild::next_phase_at, SnapBuild::reorder, ReorderBufferSetBaseSnapshot(), ReorderBufferXidHasBaseSnapshot(), SNAPBUILD_CONSISTENT, SNAPBUILD_FULL_SNAPSHOT, SnapBuildBuildSnapshot(), SnapBuildSnapIncRefcount(), SnapBuild::snapshot, SnapBuild::state, and TransactionIdPrecedes().
Referenced by heap2_decode(), heap_decode(), and logicalmsg_decode().
void SnapBuildProcessNewCid | ( | SnapBuild * | builder, |
TransactionId | xid, | ||
XLogRecPtr | lsn, | ||
xl_heap_new_cid * | xlrec | ||
) |
Definition at line 689 of file snapbuild.c.
References xl_heap_new_cid::cmax, xl_heap_new_cid::cmin, xl_heap_new_cid::combocid, elog, ERROR, InvalidCommandId, Max, SnapBuild::reorder, ReorderBufferAddNewCommandId(), ReorderBufferAddNewTupleCids(), ReorderBufferXidSetCatalogChanges(), xl_heap_new_cid::target_locator, xl_heap_new_cid::target_tid, and xl_heap_new_cid::top_xid.
Referenced by heap2_decode().
void SnapBuildProcessRunningXacts | ( | SnapBuild * | builder, |
XLogRecPtr | lsn, | ||
xl_running_xacts * | running | ||
) |
Definition at line 1088 of file snapbuild.c.
References ReorderBuffer::current_restart_decoding_lsn, DEBUG3, elog, InvalidTransactionId, InvalidXLogRecPtr, SnapBuild::last_serialized_snapshot, LogicalIncreaseRestartDecodingForSlot(), LogicalIncreaseXminForSlot(), xl_running_xacts::oldestRunningXid, SnapBuild::reorder, ReorderBufferGetOldestTXN(), ReorderBufferGetOldestXmin(), ReorderBufferTXN::restart_decoding_lsn, SNAPBUILD_CONSISTENT, SnapBuildFindSnapshot(), SnapBuildPurgeOlderTxn(), SnapBuildSerialize(), SnapBuild::state, SnapBuild::xmax, and SnapBuild::xmin.
Referenced by standby_decode().
|
static |
Definition at line 818 of file snapbuild.c.
References SnapBuild::catchange, SnapBuild::committed, SnapBuild::context, DEBUG3, elog, MemoryContextAlloc(), NormalTransactionIdPrecedes, pfree(), TransactionIdFollowsOrEquals(), TransactionIdIsNormal, SnapBuild::xcnt, SnapBuild::xip, SnapBuild::xmax, and SnapBuild::xmin.
Referenced by SnapBuildProcessRunningXacts().
void SnapBuildResetExportedSnapshotState | ( | void | ) |
Definition at line 627 of file snapbuild.c.
References ExportInProgress, and SavedResourceOwnerDuringExport.
Referenced by AbortTransaction().
|
static |
Definition at line 1788 of file snapbuild.c.
References Assert, SnapBuildOnDisk::builder, SnapBuild::catchange, SnapBuild::committed, SnapBuild::context, ereport, errdetail(), errmsg(), SnapBuild::initial_xmin_horizon, InvalidTransactionId, LOG, LSN_FORMAT_ARGS, MAXPGPATH, SnapBuild::next_phase_at, pfree(), PG_LOGICAL_SNAPSHOTS_DIR, SnapBuild::reorder, ReorderBufferSetRestartPoint(), SNAPBUILD_CONSISTENT, SnapBuildBuildSnapshot(), SnapBuildRestoreSnapshot(), SnapBuildSnapDecRefcount(), SnapBuildSnapIncRefcount(), SnapBuild::snapshot, sprintf, SnapBuild::state, TransactionIdPrecedes(), SnapBuild::xcnt, SnapBuild::xcnt_space, SnapBuild::xip, SnapBuild::xmax, and SnapBuild::xmin.
Referenced by SnapBuildFindSnapshot(), and SnapBuildSerializationPoint().
|
static |
Definition at line 1885 of file snapbuild.c.
References CloseTransientFile(), generate_unaccent_rules::dest, ereport, errcode(), ERRCODE_DATA_CORRUPTED, errcode_for_file_access(), errmsg(), ERROR, fd(), pgstat_report_wait_end(), pgstat_report_wait_start(), read, and size.
Referenced by SnapBuildRestoreSnapshot().
bool SnapBuildRestoreSnapshot | ( | SnapBuildOnDisk * | ondisk, |
const char * | path, | ||
MemoryContext | context, | ||
bool | missing_ok | ||
) |
Definition at line 1694 of file snapbuild.c.
References SnapBuildOnDisk::builder, SnapBuild::catchange, SnapBuildOnDisk::checksum, CloseTransientFile(), SnapBuild::committed, COMP_CRC32C, context, EQ_CRC32C, ereport, errcode(), ERRCODE_DATA_CORRUPTED, errcode_for_file_access(), errmsg(), ERROR, fd(), FIN_CRC32C, fsync_fname(), INIT_CRC32C, SnapBuildOnDisk::magic, MemoryContextAllocZero(), OpenTransientFile(), PG_BINARY, PG_LOGICAL_SNAPSHOTS_DIR, SNAPBUILD_MAGIC, SNAPBUILD_VERSION, SnapBuildOnDiskConstantSize, SnapBuildOnDiskNotChecksummedSize, SnapBuildRestoreContents(), SnapBuildOnDisk::version, SnapBuild::xcnt, and SnapBuild::xip.
Referenced by pg_get_logical_snapshot_info(), pg_get_logical_snapshot_meta(), and SnapBuildRestore().
void SnapBuildSerializationPoint | ( | SnapBuild * | builder, |
XLogRecPtr | lsn | ||
) |
Definition at line 1436 of file snapbuild.c.
References SNAPBUILD_CONSISTENT, SnapBuildRestore(), SnapBuildSerialize(), and SnapBuild::state.
Referenced by xlog_decode().
|
static |
Definition at line 1449 of file snapbuild.c.
References Assert, SnapBuildOnDisk::builder, SnapBuild::catchange, ReorderBuffer::catchange_txns, SnapBuildOnDisk::checksum, CloseTransientFile(), SnapBuild::committed, COMP_CRC32C, SnapBuild::context, dclist_count(), DEBUG1, elog, ereport, errcode_for_file_access(), errmsg(), ERROR, fd(), FIN_CRC32C, fsync_fname(), INIT_CRC32C, InvalidTransactionId, InvalidXLogRecPtr, SnapBuild::last_serialized_snapshot, SnapBuildOnDisk::length, LSN_FORMAT_ARGS, SnapBuildOnDisk::magic, MAXPGPATH, MemoryContextSwitchTo(), MyProcPid, SnapBuild::next_phase_at, old_ctx, OpenTransientFile(), palloc0(), pfree(), PG_BINARY, pg_fsync(), PG_LOGICAL_SNAPSHOTS_DIR, pgstat_report_wait_end(), pgstat_report_wait_start(), SnapBuild::reorder, ReorderBufferGetCatalogChangesXacts(), ReorderBufferSetRestartPoint(), SNAPBUILD_CONSISTENT, SNAPBUILD_MAGIC, SNAPBUILD_VERSION, SnapBuildOnDiskConstantSize, SnapBuildOnDiskNotChecksummedSize, SnapBuild::snapshot, sprintf, stat, SnapBuild::state, SnapBuildOnDisk::version, write, SnapBuild::xcnt, and SnapBuild::xip.
Referenced by SnapBuildProcessRunningXacts(), and SnapBuildSerializationPoint().
void SnapBuildSetTwoPhaseAt | ( | SnapBuild * | builder, |
XLogRecPtr | ptr | ||
) |
Definition at line 295 of file snapbuild.c.
References SnapBuild::two_phase_at.
Referenced by CreateDecodingContext().
void SnapBuildSnapDecRefcount | ( | Snapshot | snap | ) |
Definition at line 328 of file snapbuild.c.
References SnapshotData::active_count, Assert, SnapshotData::copied, SnapshotData::curcid, elog, ERROR, FirstCommandId, SnapshotData::regd_count, SnapBuildFreeSnapshot(), SNAPSHOT_HISTORIC_MVCC, SnapshotData::snapshot_type, SnapshotData::suboverflowed, and SnapshotData::takenDuringRecovery.
Referenced by FreeSnapshotBuilder(), ReorderBufferCleanupTXN(), ReorderBufferFreeSnap(), ReorderBufferTransferSnapToParent(), SnapBuildCommitTxn(), and SnapBuildRestore().
|
static |
Definition at line 316 of file snapbuild.c.
References SnapshotData::active_count.
Referenced by SnapBuildCommitTxn(), SnapBuildDistributeNewCatalogSnapshot(), SnapBuildGetOrBuildSnapshot(), SnapBuildProcessChange(), and SnapBuildRestore().
bool SnapBuildSnapshotExists | ( | XLogRecPtr | lsn | ) |
Definition at line 2010 of file snapbuild.c.
References ereport, errcode_for_file_access(), errmsg(), ERROR, LSN_FORMAT_ARGS, MAXPGPATH, PG_LOGICAL_SNAPSHOTS_DIR, sprintf, and stat.
Referenced by update_local_synced_slot().
|
static |
Definition at line 1387 of file snapbuild.c.
References elog, ERROR, LogStandbySnapshot(), RecoveryInProgress(), TransactionIdFollows(), TransactionIdIsCurrentTransactionId(), XactLockTableWait(), xl_running_xacts::xcnt, xl_running_xacts::xids, and XLTW_None.
Referenced by SnapBuildFindSnapshot().
bool SnapBuildXactNeedsSkip | ( | SnapBuild * | builder, |
XLogRecPtr | ptr | ||
) |
Definition at line 304 of file snapbuild.c.
References SnapBuild::start_decoding_at.
Referenced by AssertTXNLsnOrder(), DecodeTXNNeedSkip(), logicalmsg_decode(), and ReorderBufferCanStartStreaming().
|
inlinestatic |
Definition at line 1058 of file snapbuild.c.
References SnapBuild::catchange, SnapBuild::reorder, ReorderBufferXidHasCatalogChanges(), XACT_XINFO_HAS_INVALS, SnapBuild::xcnt, xidComparator(), and SnapBuild::xip.
Referenced by SnapBuildCommitTxn().
Definition at line 152 of file snapbuild.c.
Referenced by SnapBuildClearExportedSnapshot(), SnapBuildExportSnapshot(), and SnapBuildResetExportedSnapshotState().
|
static |
Definition at line 151 of file snapbuild.c.
Referenced by SnapBuildClearExportedSnapshot(), SnapBuildExportSnapshot(), and SnapBuildResetExportedSnapshotState().