PostgreSQL Source Code git master
|
#include "postgres.h"
#include "access/transam.h"
#include "access/twophase.h"
#include "access/xact.h"
#include "access/xloginsert.h"
#include "access/xlogrecovery.h"
#include "access/xlogutils.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "replication/slot.h"
#include "storage/bufmgr.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "storage/sinvaladt.h"
#include "storage/standby.h"
#include "utils/hsearch.h"
#include "utils/ps_status.h"
#include "utils/timeout.h"
#include "utils/timestamp.h"
Go to the source code of this file.
Data Structures | |
struct | RecoveryLockEntry |
struct | RecoveryLockXidEntry |
Macros | |
#define | STANDBY_INITIAL_WAIT_US 1000 |
Typedefs | |
typedef struct RecoveryLockEntry | RecoveryLockEntry |
typedef struct RecoveryLockXidEntry | RecoveryLockXidEntry |
Variables | |
int | max_standby_archive_delay = 30 * 1000 |
int | max_standby_streaming_delay = 30 * 1000 |
bool | log_recovery_conflict_waits = false |
static HTAB * | RecoveryLockHash = NULL |
static HTAB * | RecoveryLockXidHash = NULL |
static volatile sig_atomic_t | got_standby_deadlock_timeout = false |
static volatile sig_atomic_t | got_standby_delay_timeout = false |
static volatile sig_atomic_t | got_standby_lock_timeout = false |
static int | standbyWait_us = STANDBY_INITIAL_WAIT_US |
typedef struct RecoveryLockEntry RecoveryLockEntry |
typedef struct RecoveryLockXidEntry RecoveryLockXidEntry |
void CheckRecoveryConflictDeadlock | ( | void | ) |
Definition at line 904 of file standby.c.
References Assert, ereport, errcode(), ERRCODE_T_R_DEADLOCK_DETECTED, errdetail(), errmsg(), ERROR, HoldingBufferPinThatDelaysRecovery(), and InRecovery.
Referenced by ProcSleep().
|
static |
Definition at line 1480 of file standby.c.
References _, PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, PROCSIG_RECOVERY_CONFLICT_DATABASE, PROCSIG_RECOVERY_CONFLICT_LOCK, PROCSIG_RECOVERY_CONFLICT_LOGICALSLOT, PROCSIG_RECOVERY_CONFLICT_SNAPSHOT, PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK, and PROCSIG_RECOVERY_CONFLICT_TABLESPACE.
Referenced by LogRecoveryConflict().
|
static |
Definition at line 200 of file standby.c.
References GetXLogReceiptTime(), max_standby_archive_delay, max_standby_streaming_delay, and TimestampTzPlusMilliseconds.
Referenced by ResolveRecoveryConflictWithBufferPin(), ResolveRecoveryConflictWithLock(), and WaitExceedsMaxStandbyDelay().
void InitRecoveryTransactionEnvironment | ( | void | ) |
Definition at line 94 of file standby.c.
References Assert, HASHCTL::entrysize, GetNextLocalTransactionId(), HASH_BLOBS, hash_create(), HASH_ELEM, HASHCTL::keysize, VirtualTransactionId::localTransactionId, MyProc, MyProcNumber, VirtualTransactionId::procNumber, PGPROC::procNumber, RecoveryLockHash, RecoveryLockXidHash, SharedInvalBackendInit(), STANDBY_INITIALIZED, standbyState, VirtualXactLockTableInsert(), and PGPROC::vxid.
Referenced by StartupXLOG().
Definition at line 1419 of file standby.c.
References xl_standby_lock::dbOid, GetCurrentTransactionId(), LogAccessExclusiveLocks(), MyXactFlags, xl_standby_lock::relOid, XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK, and xl_standby_lock::xid.
Referenced by LockAcquireExtended().
void LogAccessExclusiveLockPrepare | ( | void | ) |
Definition at line 1436 of file standby.c.
References GetCurrentTransactionId().
Referenced by LockAcquireExtended().
|
static |
Definition at line 1401 of file standby.c.
References xl_standby_locks::nlocks, XLOG_MARK_UNIMPORTANT, XLOG_STANDBY_LOCK, XLogBeginInsert(), XLogInsert(), XLogRegisterData(), and XLogSetRecordFlags().
Referenced by LogAccessExclusiveLock(), and LogStandbySnapshot().
|
static |
Definition at line 1341 of file standby.c.
References DEBUG2, elog, RunningTransactionsData::latestCompletedXid, xl_running_xacts::latestCompletedXid, LSN_FORMAT_ARGS, MinSizeOfXactRunningXacts, RunningTransactionsData::nextXid, xl_running_xacts::nextXid, RunningTransactionsData::oldestRunningXid, xl_running_xacts::oldestRunningXid, RunningTransactionsData::subxcnt, xl_running_xacts::subxcnt, xl_running_xacts::subxid_overflow, RunningTransactionsData::subxid_status, SUBXIDS_IN_ARRAY, RunningTransactionsData::xcnt, xl_running_xacts::xcnt, RunningTransactionsData::xids, XLOG_MARK_UNIMPORTANT, XLOG_RUNNING_XACTS, XLogBeginInsert(), XLogInsert(), XLogRegisterData(), XLogSetAsyncXactLSN(), and XLogSetRecordFlags().
Referenced by LogStandbySnapshot().
void LogRecoveryConflict | ( | ProcSignalReason | reason, |
TimestampTz | wait_start, | ||
TimestampTz | now, | ||
VirtualTransactionId * | wait_list, | ||
bool | still_waiting | ||
) |
Definition at line 273 of file standby.c.
References appendStringInfo(), Assert, buf, ereport, errdetail_log_plural(), errmsg(), get_recovery_conflict_desc(), initStringInfo(), LOG, now(), pfree(), PGPROC::pid, VirtualTransactionId::procNumber, ProcNumberGetProc(), TimestampDifference(), and VirtualTransactionIdIsValid.
Referenced by LockBufferForCleanup(), ProcSleep(), and ResolveRecoveryConflictWithVirtualXIDs().
void LogStandbyInvalidations | ( | int | nmsgs, |
SharedInvalidationMessage * | msgs, | ||
bool | relcacheInitFileInval | ||
) |
Definition at line 1458 of file standby.c.
References xl_invalidations::dbId, MinSizeOfInvalidations, MyDatabaseId, MyDatabaseTableSpace, xl_invalidations::nmsgs, xl_invalidations::relcacheInitFileInval, xl_invalidations::tsId, XLOG_INVALIDATIONS, XLogBeginInsert(), XLogInsert(), and XLogRegisterData().
Referenced by RecordTransactionCommit().
XLogRecPtr LogStandbySnapshot | ( | void | ) |
Definition at line 1281 of file standby.c.
References Assert, GetRunningTransactionData(), GetRunningTransactionLocks(), LogAccessExclusiveLocks(), LogCurrentRunningXacts(), LWLockRelease(), pfree(), wal_level, WAL_LEVEL_LOGICAL, and XLogStandbyInfoActive.
Referenced by BackgroundWriterMain(), CreateCheckPoint(), pg_log_standby_snapshot(), ReplicationSlotReserveWal(), and SnapBuildWaitSnapshot().
void ResolveRecoveryConflictWithBufferPin | ( | void | ) |
Definition at line 792 of file standby.c.
References Assert, DeadlockTimeout, EnableTimeoutParams::delay_ms, disable_all_timeouts(), enable_timeouts(), EnableTimeoutParams::fin_time, GetCurrentTimestamp(), GetStandbyLimitTime(), got_standby_deadlock_timeout, got_standby_delay_timeout, EnableTimeoutParams::id, InHotStandby, PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK, ProcWaitForSignal(), SendRecoveryConflictWithBufferPin(), STANDBY_DEADLOCK_TIMEOUT, STANDBY_TIMEOUT, TMPARAM_AFTER, TMPARAM_AT, and EnableTimeoutParams::type.
Referenced by LockBufferForCleanup().
void ResolveRecoveryConflictWithDatabase | ( | Oid | dbid | ) |
Definition at line 568 of file standby.c.
References CancelDBBackends(), CountDBBackends(), pg_usleep(), and PROCSIG_RECOVERY_CONFLICT_DATABASE.
Referenced by dbase_redo().
void ResolveRecoveryConflictWithLock | ( | LOCKTAG | locktag, |
bool | logging_conflict | ||
) |
Definition at line 622 of file standby.c.
References AccessExclusiveLock, Assert, cleanup(), DeadlockTimeout, EnableTimeoutParams::delay_ms, disable_all_timeouts(), enable_timeouts(), EnableTimeoutParams::fin_time, GetCurrentTimestamp(), GetLockConflicts(), GetStandbyLimitTime(), got_standby_deadlock_timeout, got_standby_lock_timeout, EnableTimeoutParams::id, InHotStandby, LOCKTAG::locktag_type, MyProc, now(), pg_atomic_read_u64(), pg_atomic_write_u64(), PG_WAIT_LOCK, PROCSIG_RECOVERY_CONFLICT_LOCK, PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK, ProcWaitForSignal(), ResolveRecoveryConflictWithVirtualXIDs(), SignalVirtualTransaction(), STANDBY_DEADLOCK_TIMEOUT, STANDBY_LOCK_TIMEOUT, TMPARAM_AFTER, TMPARAM_AT, EnableTimeoutParams::type, VirtualTransactionIdIsValid, and PGPROC::waitStart.
Referenced by ProcSleep().
void ResolveRecoveryConflictWithSnapshot | ( | TransactionId | snapshotConflictHorizon, |
bool | isCatalogRel, | ||
RelFileLocator | locator | ||
) |
Definition at line 467 of file standby.c.
References Assert, RelFileLocator::dbOid, GetConflictingVirtualXIDs(), InvalidateObsoleteReplicationSlots(), PROCSIG_RECOVERY_CONFLICT_SNAPSHOT, ResolveRecoveryConflictWithVirtualXIDs(), RS_INVAL_HORIZON, TransactionIdIsNormal, TransactionIdIsValid, wal_level, and WAL_LEVEL_LOGICAL.
Referenced by btree_xlog_delete(), gistRedoDeleteRecord(), hash_xlog_vacuum_one_page(), heap_xlog_prune_freeze(), heap_xlog_visible(), ResolveRecoveryConflictWithSnapshotFullXid(), and spgRedoVacuumRedirect().
void ResolveRecoveryConflictWithSnapshotFullXid | ( | FullTransactionId | snapshotConflictHorizon, |
bool | isCatalogRel, | ||
RelFileLocator | locator | ||
) |
Definition at line 511 of file standby.c.
References MaxTransactionId, ReadNextFullTransactionId(), ResolveRecoveryConflictWithSnapshot(), U64FromFullTransactionId, and XidFromFullTransactionId.
Referenced by btree_xlog_reuse_page(), and gistRedoPageReuse().
void ResolveRecoveryConflictWithTablespace | ( | Oid | tsid | ) |
Definition at line 538 of file standby.c.
References GetConflictingVirtualXIDs(), InvalidOid, InvalidTransactionId, PROCSIG_RECOVERY_CONFLICT_TABLESPACE, and ResolveRecoveryConflictWithVirtualXIDs().
Referenced by tblspc_redo().
|
static |
Definition at line 359 of file standby.c.
References Assert, CancelVirtualTransaction(), DeadlockTimeout, GetCurrentTimestamp(), log_recovery_conflict_waits, LogRecoveryConflict(), now(), pg_usleep(), set_ps_display_remove_suffix(), set_ps_display_suffix(), STANDBY_INITIAL_WAIT_US, standbyWait_us, TimestampDifferenceExceeds(), update_process_title, VirtualTransactionIdIsValid, VirtualXactLock(), WaitExceedsMaxStandbyDelay(), and waiting.
Referenced by ResolveRecoveryConflictWithLock(), ResolveRecoveryConflictWithSnapshot(), and ResolveRecoveryConflictWithTablespace().
|
static |
Definition at line 876 of file standby.c.
References Assert, CancelDBBackends(), InvalidOid, PROCSIG_RECOVERY_CONFLICT_BUFFERPIN, and PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK.
Referenced by ResolveRecoveryConflictWithBufferPin().
void ShutdownRecoveryTransactionEnvironment | ( | void | ) |
Definition at line 160 of file standby.c.
References ExpireAllKnownAssignedTransactionIds(), hash_destroy(), RecoveryLockHash, RecoveryLockXidHash, StandbyReleaseAllLocks(), and VirtualXactLockTableCleanup().
Referenced by StartupProcExit(), and StartupXLOG().
void standby_redo | ( | XLogReaderState * | record | ) |
Definition at line 1162 of file standby.c.
References Assert, xl_invalidations::dbId, xl_standby_lock::dbOid, elog, i, RunningTransactionsData::latestCompletedXid, xl_running_xacts::latestCompletedXid, xl_standby_locks::locks, xl_invalidations::msgs, RunningTransactionsData::nextXid, xl_running_xacts::nextXid, xl_standby_locks::nlocks, xl_invalidations::nmsgs, RunningTransactionsData::oldestRunningXid, xl_running_xacts::oldestRunningXid, PANIC, pgstat_report_stat(), ProcArrayApplyRecoveryInfo(), ProcessCommittedInvalidationMessages(), xl_invalidations::relcacheInitFileInval, xl_standby_lock::relOid, STANDBY_DISABLED, StandbyAcquireAccessExclusiveLock(), standbyState, RunningTransactionsData::subxcnt, xl_running_xacts::subxcnt, xl_running_xacts::subxid_overflow, RunningTransactionsData::subxid_status, SUBXIDS_IN_ARRAY, SUBXIDS_MISSING, xl_invalidations::tsId, RunningTransactionsData::xcnt, xl_running_xacts::xcnt, xl_standby_lock::xid, RunningTransactionsData::xids, xl_running_xacts::xids, XLOG_INVALIDATIONS, XLOG_RUNNING_XACTS, XLOG_STANDBY_LOCK, XLogRecGetData, XLogRecGetInfo, and XLogRecHasAnyBlockRefs.
void StandbyAcquireAccessExclusiveLock | ( | TransactionId | xid, |
Oid | dbOid, | ||
Oid | relOid | ||
) |
Definition at line 985 of file standby.c.
References AccessExclusiveLock, Assert, DEBUG4, elog, HASH_ENTER, hash_search(), RecoveryLockXidEntry::head, sort-test::key, LockAcquire(), RecoveryLockEntry::next, OidIsValid, RecoveryLockHash, RecoveryLockXidHash, SET_LOCKTAG_RELATION, TransactionIdDidAbort(), TransactionIdDidCommit(), TransactionIdIsValid, and RecoveryLockXidEntry::xid.
Referenced by lock_twophase_standby_recover(), and standby_redo().
void StandbyDeadLockHandler | ( | void | ) |
Definition at line 935 of file standby.c.
References got_standby_deadlock_timeout.
Referenced by StartupProcessMain().
void StandbyLockTimeoutHandler | ( | void | ) |
Definition at line 953 of file standby.c.
References got_standby_lock_timeout.
Referenced by StartupProcessMain().
void StandbyReleaseAllLocks | ( | void | ) |
Definition at line 1105 of file standby.c.
References DEBUG2, elog, HASH_REMOVE, hash_search(), hash_seq_init(), hash_seq_search(), RecoveryLockXidHash, and StandbyReleaseXidEntryLocks().
Referenced by ShutdownRecoveryTransactionEnvironment(), and StandbyReleaseLocks().
|
static |
Definition at line 1067 of file standby.c.
References HASH_FIND, HASH_REMOVE, hash_search(), RecoveryLockXidHash, StandbyReleaseAllLocks(), StandbyReleaseXidEntryLocks(), and TransactionIdIsValid.
Referenced by StandbyReleaseLockTree().
void StandbyReleaseLockTree | ( | TransactionId | xid, |
int | nsubxids, | ||
TransactionId * | subxids | ||
) |
Definition at line 1091 of file standby.c.
References i, and StandbyReleaseLocks().
Referenced by RecoverPreparedTransactions(), xact_redo_abort(), and xact_redo_commit().
void StandbyReleaseOldLocks | ( | TransactionId | oldxid | ) |
Definition at line 1129 of file standby.c.
References Assert, HASH_REMOVE, hash_search(), hash_seq_init(), hash_seq_search(), RecoveryLockXidHash, StandbyReleaseXidEntryLocks(), StandbyTransactionIdIsPrepared(), TransactionIdIsValid, TransactionIdPrecedes(), and RecoveryLockXidEntry::xid.
Referenced by ProcArrayApplyRecoveryInfo().
|
static |
Definition at line 1034 of file standby.c.
References AccessExclusiveLock, Assert, xl_standby_lock::dbOid, DEBUG4, elog, HASH_REMOVE, hash_search(), RecoveryLockXidEntry::head, RecoveryLockEntry::key, LockRelease(), LOG, next, RecoveryLockEntry::next, RecoveryLockHash, xl_standby_lock::relOid, SET_LOCKTAG_RELATION, and xl_standby_lock::xid.
Referenced by StandbyReleaseAllLocks(), StandbyReleaseLocks(), and StandbyReleaseOldLocks().
void StandbyTimeoutHandler | ( | void | ) |
Definition at line 944 of file standby.c.
References got_standby_delay_timeout.
Referenced by StartupProcessMain().
|
static |
Definition at line 233 of file standby.c.
References CHECK_FOR_INTERRUPTS, GetCurrentTimestamp(), GetStandbyLimitTime(), pg_usleep(), pgstat_report_wait_end(), pgstat_report_wait_start(), and standbyWait_us.
Referenced by ResolveRecoveryConflictWithVirtualXIDs().
|
static |
Definition at line 68 of file standby.c.
Referenced by ResolveRecoveryConflictWithBufferPin(), ResolveRecoveryConflictWithLock(), and StandbyDeadLockHandler().
|
static |
Definition at line 69 of file standby.c.
Referenced by ResolveRecoveryConflictWithBufferPin(), and StandbyTimeoutHandler().
|
static |
Definition at line 70 of file standby.c.
Referenced by ResolveRecoveryConflictWithLock(), and StandbyLockTimeoutHandler().
bool log_recovery_conflict_waits = false |
Definition at line 41 of file standby.c.
Referenced by LockBufferForCleanup(), ProcSleep(), and ResolveRecoveryConflictWithVirtualXIDs().
int max_standby_archive_delay = 30 * 1000 |
Definition at line 39 of file standby.c.
Referenced by GetStandbyLimitTime().
int max_standby_streaming_delay = 30 * 1000 |
Definition at line 40 of file standby.c.
Referenced by GetStandbyLimitTime().
|
static |
Definition at line 64 of file standby.c.
Referenced by InitRecoveryTransactionEnvironment(), ShutdownRecoveryTransactionEnvironment(), StandbyAcquireAccessExclusiveLock(), and StandbyReleaseXidEntryLocks().
|
static |
Definition at line 65 of file standby.c.
Referenced by InitRecoveryTransactionEnvironment(), ShutdownRecoveryTransactionEnvironment(), StandbyAcquireAccessExclusiveLock(), StandbyReleaseAllLocks(), StandbyReleaseLocks(), and StandbyReleaseOldLocks().
|
static |
Definition at line 225 of file standby.c.
Referenced by ResolveRecoveryConflictWithVirtualXIDs(), and WaitExceedsMaxStandbyDelay().