Thanks to visit codestin.com
Credit goes to doxygen.postgresql.org

PostgreSQL Source Code git master
xact.h File Reference
#include "access/transam.h"
#include "access/xlogreader.h"
#include "datatype/timestamp.h"
#include "lib/stringinfo.h"
#include "nodes/pg_list.h"
#include "storage/relfilelocator.h"
#include "storage/sinval.h"
Include dependency graph for xact.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SavedTransactionCharacteristics
 
struct  xl_xact_assignment
 
struct  xl_xact_xinfo
 
struct  xl_xact_dbinfo
 
struct  xl_xact_subxacts
 
struct  xl_xact_relfilelocators
 
struct  xl_xact_stats_item
 
struct  xl_xact_stats_items
 
struct  xl_xact_invals
 
struct  xl_xact_twophase
 
struct  xl_xact_origin
 
struct  xl_xact_commit
 
struct  xl_xact_abort
 
struct  xl_xact_prepare
 
struct  xl_xact_parsed_commit
 
struct  xl_xact_parsed_abort
 

Macros

#define GIDSIZE   200
 
#define XACT_READ_UNCOMMITTED   0
 
#define XACT_READ_COMMITTED   1
 
#define XACT_REPEATABLE_READ   2
 
#define XACT_SERIALIZABLE   3
 
#define IsolationUsesXactSnapshot()   (XactIsoLevel >= XACT_REPEATABLE_READ)
 
#define IsolationIsSerializable()   (XactIsoLevel == XACT_SERIALIZABLE)
 
#define SYNCHRONOUS_COMMIT_ON   SYNCHRONOUS_COMMIT_REMOTE_FLUSH
 
#define XACT_FLAGS_ACCESSEDTEMPNAMESPACE   (1U << 0)
 
#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK   (1U << 1)
 
#define XACT_FLAGS_NEEDIMMEDIATECOMMIT   (1U << 2)
 
#define XACT_FLAGS_PIPELINING   (1U << 3)
 
#define XLOG_XACT_COMMIT   0x00
 
#define XLOG_XACT_PREPARE   0x10
 
#define XLOG_XACT_ABORT   0x20
 
#define XLOG_XACT_COMMIT_PREPARED   0x30
 
#define XLOG_XACT_ABORT_PREPARED   0x40
 
#define XLOG_XACT_ASSIGNMENT   0x50
 
#define XLOG_XACT_INVALIDATIONS   0x60
 
#define XLOG_XACT_OPMASK   0x70
 
#define XLOG_XACT_HAS_INFO   0x80
 
#define XACT_XINFO_HAS_DBINFO   (1U << 0)
 
#define XACT_XINFO_HAS_SUBXACTS   (1U << 1)
 
#define XACT_XINFO_HAS_RELFILELOCATORS   (1U << 2)
 
#define XACT_XINFO_HAS_INVALS   (1U << 3)
 
#define XACT_XINFO_HAS_TWOPHASE   (1U << 4)
 
#define XACT_XINFO_HAS_ORIGIN   (1U << 5)
 
#define XACT_XINFO_HAS_AE_LOCKS   (1U << 6)
 
#define XACT_XINFO_HAS_GID   (1U << 7)
 
#define XACT_XINFO_HAS_DROPPED_STATS   (1U << 8)
 
#define XACT_COMPLETION_APPLY_FEEDBACK   (1U << 29)
 
#define XACT_COMPLETION_UPDATE_RELCACHE_FILE   (1U << 30)
 
#define XACT_COMPLETION_FORCE_SYNC_COMMIT   (1U << 31)
 
#define XactCompletionApplyFeedback(xinfo)    ((xinfo & XACT_COMPLETION_APPLY_FEEDBACK) != 0)
 
#define XactCompletionRelcacheInitFileInval(xinfo)    ((xinfo & XACT_COMPLETION_UPDATE_RELCACHE_FILE) != 0)
 
#define XactCompletionForceSyncCommit(xinfo)    ((xinfo & XACT_COMPLETION_FORCE_SYNC_COMMIT) != 0)
 
#define MinSizeOfXactAssignment   offsetof(xl_xact_assignment, xsub)
 
#define MinSizeOfXactSubxacts   offsetof(xl_xact_subxacts, subxacts)
 
#define MinSizeOfXactRelfileLocators   offsetof(xl_xact_relfilelocators, xlocators)
 
#define MinSizeOfXactStatsItems   offsetof(xl_xact_stats_items, items)
 
#define MinSizeOfXactInvals   offsetof(xl_xact_invals, msgs)
 
#define MinSizeOfXactCommit   (offsetof(xl_xact_commit, xact_time) + sizeof(TimestampTz))
 
#define MinSizeOfXactAbort   sizeof(xl_xact_abort)
 

Typedefs

typedef void(* XactCallback) (XactEvent event, void *arg)
 
typedef void(* SubXactCallback) (SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg)
 
typedef struct SavedTransactionCharacteristics SavedTransactionCharacteristics
 
typedef struct xl_xact_assignment xl_xact_assignment
 
typedef struct xl_xact_xinfo xl_xact_xinfo
 
typedef struct xl_xact_dbinfo xl_xact_dbinfo
 
typedef struct xl_xact_subxacts xl_xact_subxacts
 
typedef struct xl_xact_relfilelocators xl_xact_relfilelocators
 
typedef struct xl_xact_stats_item xl_xact_stats_item
 
typedef struct xl_xact_stats_items xl_xact_stats_items
 
typedef struct xl_xact_invals xl_xact_invals
 
typedef struct xl_xact_twophase xl_xact_twophase
 
typedef struct xl_xact_origin xl_xact_origin
 
typedef struct xl_xact_commit xl_xact_commit
 
typedef struct xl_xact_abort xl_xact_abort
 
typedef struct xl_xact_prepare xl_xact_prepare
 
typedef struct xl_xact_parsed_commit xl_xact_parsed_commit
 
typedef xl_xact_parsed_commit xl_xact_parsed_prepare
 
typedef struct xl_xact_parsed_abort xl_xact_parsed_abort
 

Enumerations

enum  SyncCommitLevel {
  SYNCHRONOUS_COMMIT_OFF , SYNCHRONOUS_COMMIT_LOCAL_FLUSH , SYNCHRONOUS_COMMIT_REMOTE_WRITE , SYNCHRONOUS_COMMIT_REMOTE_FLUSH ,
  SYNCHRONOUS_COMMIT_REMOTE_APPLY
}
 
enum  XactEvent {
  XACT_EVENT_COMMIT , XACT_EVENT_PARALLEL_COMMIT , XACT_EVENT_ABORT , XACT_EVENT_PARALLEL_ABORT ,
  XACT_EVENT_PREPARE , XACT_EVENT_PRE_COMMIT , XACT_EVENT_PARALLEL_PRE_COMMIT , XACT_EVENT_PRE_PREPARE
}
 
enum  SubXactEvent { SUBXACT_EVENT_START_SUB , SUBXACT_EVENT_COMMIT_SUB , SUBXACT_EVENT_ABORT_SUB , SUBXACT_EVENT_PRE_COMMIT_SUB }
 

Functions

bool IsTransactionState (void)
 
bool IsAbortedTransactionBlockState (void)
 
TransactionId GetTopTransactionId (void)
 
TransactionId GetTopTransactionIdIfAny (void)
 
TransactionId GetCurrentTransactionId (void)
 
TransactionId GetCurrentTransactionIdIfAny (void)
 
TransactionId GetStableLatestTransactionId (void)
 
SubTransactionId GetCurrentSubTransactionId (void)
 
FullTransactionId GetTopFullTransactionId (void)
 
FullTransactionId GetTopFullTransactionIdIfAny (void)
 
FullTransactionId GetCurrentFullTransactionId (void)
 
FullTransactionId GetCurrentFullTransactionIdIfAny (void)
 
void MarkCurrentTransactionIdLoggedIfAny (void)
 
bool SubTransactionIsActive (SubTransactionId subxid)
 
CommandId GetCurrentCommandId (bool used)
 
void SetParallelStartTimestamps (TimestampTz xact_ts, TimestampTz stmt_ts)
 
TimestampTz GetCurrentTransactionStartTimestamp (void)
 
TimestampTz GetCurrentStatementStartTimestamp (void)
 
TimestampTz GetCurrentTransactionStopTimestamp (void)
 
void SetCurrentStatementStartTimestamp (void)
 
int GetCurrentTransactionNestLevel (void)
 
bool TransactionIdIsCurrentTransactionId (TransactionId xid)
 
void CommandCounterIncrement (void)
 
void ForceSyncCommit (void)
 
void StartTransactionCommand (void)
 
void SaveTransactionCharacteristics (SavedTransactionCharacteristics *s)
 
void RestoreTransactionCharacteristics (const SavedTransactionCharacteristics *s)
 
void CommitTransactionCommand (void)
 
void AbortCurrentTransaction (void)
 
void BeginTransactionBlock (void)
 
bool EndTransactionBlock (bool chain)
 
bool PrepareTransactionBlock (const char *gid)
 
void UserAbortTransactionBlock (bool chain)
 
void BeginImplicitTransactionBlock (void)
 
void EndImplicitTransactionBlock (void)
 
void ReleaseSavepoint (const char *name)
 
void DefineSavepoint (const char *name)
 
void RollbackToSavepoint (const char *name)
 
void BeginInternalSubTransaction (const char *name)
 
void ReleaseCurrentSubTransaction (void)
 
void RollbackAndReleaseCurrentSubTransaction (void)
 
bool IsSubTransaction (void)
 
Size EstimateTransactionStateSpace (void)
 
void SerializeTransactionState (Size maxsize, char *start_address)
 
void StartParallelWorkerTransaction (char *tstatespace)
 
void EndParallelWorkerTransaction (void)
 
bool IsTransactionBlock (void)
 
bool IsTransactionOrTransactionBlock (void)
 
char TransactionBlockStatusCode (void)
 
void AbortOutOfAnyTransaction (void)
 
void PreventInTransactionBlock (bool isTopLevel, const char *stmtType)
 
void RequireTransactionBlock (bool isTopLevel, const char *stmtType)
 
void WarnNoTransactionBlock (bool isTopLevel, const char *stmtType)
 
bool IsInTransactionBlock (bool isTopLevel)
 
void RegisterXactCallback (XactCallback callback, void *arg)
 
void UnregisterXactCallback (XactCallback callback, void *arg)
 
void RegisterSubXactCallback (SubXactCallback callback, void *arg)
 
void UnregisterSubXactCallback (SubXactCallback callback, void *arg)
 
bool IsSubxactTopXidLogPending (void)
 
void MarkSubxactTopXidLogged (void)
 
int xactGetCommittedChildren (TransactionId **ptr)
 
XLogRecPtr XactLogCommitRecord (TimestampTz commit_time, int nsubxacts, TransactionId *subxacts, int nrels, RelFileLocator *rels, int ndroppedstats, xl_xact_stats_item *droppedstats, int nmsgs, SharedInvalidationMessage *msgs, bool relcacheInval, int xactflags, TransactionId twophase_xid, const char *twophase_gid)
 
XLogRecPtr XactLogAbortRecord (TimestampTz abort_time, int nsubxacts, TransactionId *subxacts, int nrels, RelFileLocator *rels, int ndroppedstats, xl_xact_stats_item *droppedstats, int xactflags, TransactionId twophase_xid, const char *twophase_gid)
 
void xact_redo (XLogReaderState *record)
 
void xact_desc (StringInfo buf, XLogReaderState *record)
 
const char * xact_identify (uint8 info)
 
void ParseCommitRecord (uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *parsed)
 
void ParseAbortRecord (uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
 
void ParsePrepareRecord (uint8 info, xl_xact_prepare *xlrec, xl_xact_parsed_prepare *parsed)
 
void EnterParallelMode (void)
 
void ExitParallelMode (void)
 
bool IsInParallelMode (void)
 

Variables

PGDLLIMPORT int DefaultXactIsoLevel
 
PGDLLIMPORT int XactIsoLevel
 
PGDLLIMPORT bool DefaultXactReadOnly
 
PGDLLIMPORT bool XactReadOnly
 
PGDLLIMPORT bool xact_is_sampled
 
PGDLLIMPORT bool DefaultXactDeferrable
 
PGDLLIMPORT bool XactDeferrable
 
PGDLLIMPORT int synchronous_commit
 
PGDLLIMPORT TransactionId CheckXidAlive
 
PGDLLIMPORT bool bsysscan
 
PGDLLIMPORT int MyXactFlags
 

Macro Definition Documentation

◆ GIDSIZE

#define GIDSIZE   200

Definition at line 31 of file xact.h.

◆ IsolationIsSerializable

#define IsolationIsSerializable ( )    (XactIsoLevel == XACT_SERIALIZABLE)

Definition at line 53 of file xact.h.

◆ IsolationUsesXactSnapshot

#define IsolationUsesXactSnapshot ( )    (XactIsoLevel >= XACT_REPEATABLE_READ)

Definition at line 52 of file xact.h.

◆ MinSizeOfXactAbort

#define MinSizeOfXactAbort   sizeof(xl_xact_abort)

Definition at line 351 of file xact.h.

◆ MinSizeOfXactAssignment

#define MinSizeOfXactAssignment   offsetof(xl_xact_assignment, xsub)

Definition at line 226 of file xact.h.

◆ MinSizeOfXactCommit

#define MinSizeOfXactCommit   (offsetof(xl_xact_commit, xact_time) + sizeof(TimestampTz))

Definition at line 335 of file xact.h.

◆ MinSizeOfXactInvals

#define MinSizeOfXactInvals   offsetof(xl_xact_invals, msgs)

Definition at line 308 of file xact.h.

◆ MinSizeOfXactRelfileLocators

#define MinSizeOfXactRelfileLocators   offsetof(xl_xact_relfilelocators, xlocators)

Definition at line 274 of file xact.h.

◆ MinSizeOfXactStatsItems

#define MinSizeOfXactStatsItems   offsetof(xl_xact_stats_items, items)

Definition at line 301 of file xact.h.

◆ MinSizeOfXactSubxacts

#define MinSizeOfXactSubxacts   offsetof(xl_xact_subxacts, subxacts)

Definition at line 267 of file xact.h.

◆ SYNCHRONOUS_COMMIT_ON

#define SYNCHRONOUS_COMMIT_ON   SYNCHRONOUS_COMMIT_REMOTE_FLUSH

Definition at line 81 of file xact.h.

◆ XACT_COMPLETION_APPLY_FEEDBACK

#define XACT_COMPLETION_APPLY_FEEDBACK   (1U << 29)

Definition at line 207 of file xact.h.

◆ XACT_COMPLETION_FORCE_SYNC_COMMIT

#define XACT_COMPLETION_FORCE_SYNC_COMMIT   (1U << 31)

Definition at line 209 of file xact.h.

◆ XACT_COMPLETION_UPDATE_RELCACHE_FILE

#define XACT_COMPLETION_UPDATE_RELCACHE_FILE   (1U << 30)

Definition at line 208 of file xact.h.

◆ XACT_FLAGS_ACCESSEDTEMPNAMESPACE

#define XACT_FLAGS_ACCESSEDTEMPNAMESPACE   (1U << 0)

Definition at line 103 of file xact.h.

◆ XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK

#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK   (1U << 1)

Definition at line 109 of file xact.h.

◆ XACT_FLAGS_NEEDIMMEDIATECOMMIT

#define XACT_FLAGS_NEEDIMMEDIATECOMMIT   (1U << 2)

Definition at line 115 of file xact.h.

◆ XACT_FLAGS_PIPELINING

#define XACT_FLAGS_PIPELINING   (1U << 3)

Definition at line 122 of file xact.h.

◆ XACT_READ_COMMITTED

#define XACT_READ_COMMITTED   1

Definition at line 37 of file xact.h.

◆ XACT_READ_UNCOMMITTED

#define XACT_READ_UNCOMMITTED   0

Definition at line 36 of file xact.h.

◆ XACT_REPEATABLE_READ

#define XACT_REPEATABLE_READ   2

Definition at line 38 of file xact.h.

◆ XACT_SERIALIZABLE

#define XACT_SERIALIZABLE   3

Definition at line 39 of file xact.h.

◆ XACT_XINFO_HAS_AE_LOCKS

#define XACT_XINFO_HAS_AE_LOCKS   (1U << 6)

Definition at line 195 of file xact.h.

◆ XACT_XINFO_HAS_DBINFO

#define XACT_XINFO_HAS_DBINFO   (1U << 0)

Definition at line 189 of file xact.h.

◆ XACT_XINFO_HAS_DROPPED_STATS

#define XACT_XINFO_HAS_DROPPED_STATS   (1U << 8)

Definition at line 197 of file xact.h.

◆ XACT_XINFO_HAS_GID

#define XACT_XINFO_HAS_GID   (1U << 7)

Definition at line 196 of file xact.h.

◆ XACT_XINFO_HAS_INVALS

#define XACT_XINFO_HAS_INVALS   (1U << 3)

Definition at line 192 of file xact.h.

◆ XACT_XINFO_HAS_ORIGIN

#define XACT_XINFO_HAS_ORIGIN   (1U << 5)

Definition at line 194 of file xact.h.

◆ XACT_XINFO_HAS_RELFILELOCATORS

#define XACT_XINFO_HAS_RELFILELOCATORS   (1U << 2)

Definition at line 191 of file xact.h.

◆ XACT_XINFO_HAS_SUBXACTS

#define XACT_XINFO_HAS_SUBXACTS   (1U << 1)

Definition at line 190 of file xact.h.

◆ XACT_XINFO_HAS_TWOPHASE

#define XACT_XINFO_HAS_TWOPHASE   (1U << 4)

Definition at line 193 of file xact.h.

◆ XactCompletionApplyFeedback

#define XactCompletionApplyFeedback (   xinfo)     ((xinfo & XACT_COMPLETION_APPLY_FEEDBACK) != 0)

Definition at line 212 of file xact.h.

◆ XactCompletionForceSyncCommit

#define XactCompletionForceSyncCommit (   xinfo)     ((xinfo & XACT_COMPLETION_FORCE_SYNC_COMMIT) != 0)

Definition at line 216 of file xact.h.

◆ XactCompletionRelcacheInitFileInval

#define XactCompletionRelcacheInitFileInval (   xinfo)     ((xinfo & XACT_COMPLETION_UPDATE_RELCACHE_FILE) != 0)

Definition at line 214 of file xact.h.

◆ XLOG_XACT_ABORT

#define XLOG_XACT_ABORT   0x20

Definition at line 172 of file xact.h.

◆ XLOG_XACT_ABORT_PREPARED

#define XLOG_XACT_ABORT_PREPARED   0x40

Definition at line 174 of file xact.h.

◆ XLOG_XACT_ASSIGNMENT

#define XLOG_XACT_ASSIGNMENT   0x50

Definition at line 175 of file xact.h.

◆ XLOG_XACT_COMMIT

#define XLOG_XACT_COMMIT   0x00

Definition at line 170 of file xact.h.

◆ XLOG_XACT_COMMIT_PREPARED

#define XLOG_XACT_COMMIT_PREPARED   0x30

Definition at line 173 of file xact.h.

◆ XLOG_XACT_HAS_INFO

#define XLOG_XACT_HAS_INFO   0x80

Definition at line 183 of file xact.h.

◆ XLOG_XACT_INVALIDATIONS

#define XLOG_XACT_INVALIDATIONS   0x60

Definition at line 176 of file xact.h.

◆ XLOG_XACT_OPMASK

#define XLOG_XACT_OPMASK   0x70

Definition at line 180 of file xact.h.

◆ XLOG_XACT_PREPARE

#define XLOG_XACT_PREPARE   0x10

Definition at line 171 of file xact.h.

Typedef Documentation

◆ SavedTransactionCharacteristics

◆ SubXactCallback

typedef void(* SubXactCallback) (SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg)

Definition at line 149 of file xact.h.

◆ XactCallback

typedef void(* XactCallback) (XactEvent event, void *arg)

Definition at line 139 of file xact.h.

◆ xl_xact_abort

typedef struct xl_xact_abort xl_xact_abort

◆ xl_xact_assignment

◆ xl_xact_commit

◆ xl_xact_dbinfo

◆ xl_xact_invals

◆ xl_xact_origin

◆ xl_xact_parsed_abort

◆ xl_xact_parsed_commit

◆ xl_xact_parsed_prepare

Definition at line 409 of file xact.h.

◆ xl_xact_prepare

◆ xl_xact_relfilelocators

◆ xl_xact_stats_item

◆ xl_xact_stats_items

◆ xl_xact_subxacts

◆ xl_xact_twophase

◆ xl_xact_xinfo

typedef struct xl_xact_xinfo xl_xact_xinfo

Enumeration Type Documentation

◆ SubXactEvent

Enumerator
SUBXACT_EVENT_START_SUB 
SUBXACT_EVENT_COMMIT_SUB 
SUBXACT_EVENT_ABORT_SUB 
SUBXACT_EVENT_PRE_COMMIT_SUB 

Definition at line 141 of file xact.h.

142{
SubXactEvent
Definition: xact.h:142
@ SUBXACT_EVENT_PRE_COMMIT_SUB
Definition: xact.h:146
@ SUBXACT_EVENT_START_SUB
Definition: xact.h:143
@ SUBXACT_EVENT_ABORT_SUB
Definition: xact.h:145
@ SUBXACT_EVENT_COMMIT_SUB
Definition: xact.h:144

◆ SyncCommitLevel

Enumerator
SYNCHRONOUS_COMMIT_OFF 
SYNCHRONOUS_COMMIT_LOCAL_FLUSH 
SYNCHRONOUS_COMMIT_REMOTE_WRITE 
SYNCHRONOUS_COMMIT_REMOTE_FLUSH 
SYNCHRONOUS_COMMIT_REMOTE_APPLY 

Definition at line 69 of file xact.h.

70{
71 SYNCHRONOUS_COMMIT_OFF, /* asynchronous commit */
72 SYNCHRONOUS_COMMIT_LOCAL_FLUSH, /* wait for local flush only */
73 SYNCHRONOUS_COMMIT_REMOTE_WRITE, /* wait for local flush and remote
74 * write */
75 SYNCHRONOUS_COMMIT_REMOTE_FLUSH, /* wait for local and remote flush */
76 SYNCHRONOUS_COMMIT_REMOTE_APPLY, /* wait for local and remote flush and
77 * remote apply */
SyncCommitLevel
Definition: xact.h:70
@ SYNCHRONOUS_COMMIT_LOCAL_FLUSH
Definition: xact.h:72
@ SYNCHRONOUS_COMMIT_REMOTE_WRITE
Definition: xact.h:73
@ SYNCHRONOUS_COMMIT_REMOTE_APPLY
Definition: xact.h:76
@ SYNCHRONOUS_COMMIT_REMOTE_FLUSH
Definition: xact.h:75
@ SYNCHRONOUS_COMMIT_OFF
Definition: xact.h:71

◆ XactEvent

enum XactEvent
Enumerator
XACT_EVENT_COMMIT 
XACT_EVENT_PARALLEL_COMMIT 
XACT_EVENT_ABORT 
XACT_EVENT_PARALLEL_ABORT 
XACT_EVENT_PREPARE 
XACT_EVENT_PRE_COMMIT 
XACT_EVENT_PARALLEL_PRE_COMMIT 
XACT_EVENT_PRE_PREPARE 

Definition at line 127 of file xact.h.

128{
137} XactEvent;
XactEvent
Definition: xact.h:128
@ XACT_EVENT_PRE_PREPARE
Definition: xact.h:136
@ XACT_EVENT_COMMIT
Definition: xact.h:129
@ XACT_EVENT_PARALLEL_PRE_COMMIT
Definition: xact.h:135
@ XACT_EVENT_PARALLEL_COMMIT
Definition: xact.h:130
@ XACT_EVENT_ABORT
Definition: xact.h:131
@ XACT_EVENT_PRE_COMMIT
Definition: xact.h:134
@ XACT_EVENT_PARALLEL_ABORT
Definition: xact.h:132
@ XACT_EVENT_PREPARE
Definition: xact.h:133

Function Documentation

◆ AbortCurrentTransaction()

void AbortCurrentTransaction ( void  )

Definition at line 3463 of file xact.c.

3464{
3465 /*
3466 * Repeatedly call AbortCurrentTransactionInternal() until all the work is
3467 * done.
3468 */
3470 {
3471 }
3472}
static bool AbortCurrentTransactionInternal(void)
Definition: xact.c:3481

References AbortCurrentTransactionInternal().

Referenced by _SPI_commit(), _SPI_rollback(), AutoVacLauncherMain(), pa_stream_abort(), PostgresMain(), ReorderBufferImmediateInvalidation(), ReorderBufferProcessTXN(), and SnapBuildClearExportedSnapshot().

◆ AbortOutOfAnyTransaction()

void AbortOutOfAnyTransaction ( void  )

Definition at line 4874 of file xact.c.

4875{
4877
4878 /* Ensure we're not running in a doomed memory context */
4880
4881 /*
4882 * Get out of any transaction or nested transaction
4883 */
4884 do
4885 {
4886 switch (s->blockState)
4887 {
4888 case TBLOCK_DEFAULT:
4889 if (s->state == TRANS_DEFAULT)
4890 {
4891 /* Not in a transaction, do nothing */
4892 }
4893 else
4894 {
4895 /*
4896 * We can get here after an error during transaction start
4897 * (state will be TRANS_START). Need to clean up the
4898 * incompletely started transaction. First, adjust the
4899 * low-level state to suppress warning message from
4900 * AbortTransaction.
4901 */
4902 if (s->state == TRANS_START)
4906 }
4907 break;
4908 case TBLOCK_STARTED:
4909 case TBLOCK_BEGIN:
4910 case TBLOCK_INPROGRESS:
4913 case TBLOCK_END:
4915 case TBLOCK_PREPARE:
4916 /* In a transaction, so clean up */
4920 break;
4921 case TBLOCK_ABORT:
4922 case TBLOCK_ABORT_END:
4923
4924 /*
4925 * AbortTransaction is already done, still need Cleanup.
4926 * However, if we failed partway through running ROLLBACK,
4927 * there will be an active portal running that command, which
4928 * we need to shut down before doing CleanupTransaction.
4929 */
4933 break;
4934
4935 /*
4936 * In a subtransaction, so clean it up and abort parent too
4937 */
4938 case TBLOCK_SUBBEGIN:
4940 case TBLOCK_SUBRELEASE:
4941 case TBLOCK_SUBCOMMIT:
4943 case TBLOCK_SUBRESTART:
4946 s = CurrentTransactionState; /* changed by pop */
4947 break;
4948
4949 case TBLOCK_SUBABORT:
4952 /* As above, but AbortSubTransaction already done */
4953 if (s->curTransactionOwner)
4954 {
4955 /* As in TBLOCK_ABORT, might have a live portal to zap */
4960 }
4962 s = CurrentTransactionState; /* changed by pop */
4963 break;
4964 }
4965 } while (s->blockState != TBLOCK_DEFAULT);
4966
4967 /* Should be out of all subxacts now */
4968 Assert(s->parent == NULL);
4969
4970 /*
4971 * Revert to TopMemoryContext, to ensure we exit in a well-defined state
4972 * whether there were any transactions to close or not. (Callers that
4973 * don't intend to exit soon should switch to some other context to avoid
4974 * long-term memory leaks.)
4975 */
4977}
Assert(PointerIsAligned(start, uint64))
MemoryContext TopMemoryContext
Definition: mcxt.c:166
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
void AtAbort_Portals(void)
Definition: portalmem.c:781
void AtSubAbort_Portals(SubTransactionId mySubid, SubTransactionId parentSubid, ResourceOwner myXactOwner, ResourceOwner parentXactOwner)
Definition: portalmem.c:979
TransState state
Definition: xact.c:199
SubTransactionId subTransactionId
Definition: xact.c:196
struct TransactionStateData * parent
Definition: xact.c:218
TBlockState blockState
Definition: xact.c:200
ResourceOwner curTransactionOwner
Definition: xact.c:204
static void CleanupSubTransaction(void)
Definition: xact.c:5395
static void CleanupTransaction(void)
Definition: xact.c:3021
@ TRANS_INPROGRESS
Definition: xact.c:145
@ TRANS_START
Definition: xact.c:144
@ TRANS_DEFAULT
Definition: xact.c:143
static void AbortSubTransaction(void)
Definition: xact.c:5231
static void AtAbort_Memory(void)
Definition: xact.c:1896
@ TBLOCK_DEFAULT
Definition: xact.c:160
@ TBLOCK_SUBABORT_END
Definition: xact.c:180
@ TBLOCK_STARTED
Definition: xact.c:161
@ TBLOCK_SUBCOMMIT
Definition: xact.c:178
@ TBLOCK_IMPLICIT_INPROGRESS
Definition: xact.c:166
@ TBLOCK_ABORT_END
Definition: xact.c:170
@ TBLOCK_PREPARE
Definition: xact.c:172
@ TBLOCK_ABORT_PENDING
Definition: xact.c:171
@ TBLOCK_ABORT
Definition: xact.c:169
@ TBLOCK_SUBRELEASE
Definition: xact.c:177
@ TBLOCK_SUBBEGIN
Definition: xact.c:175
@ TBLOCK_SUBABORT
Definition: xact.c:179
@ TBLOCK_SUBRESTART
Definition: xact.c:182
@ TBLOCK_INPROGRESS
Definition: xact.c:165
@ TBLOCK_END
Definition: xact.c:168
@ TBLOCK_PARALLEL_INPROGRESS
Definition: xact.c:167
@ TBLOCK_SUBABORT_RESTART
Definition: xact.c:183
@ TBLOCK_SUBABORT_PENDING
Definition: xact.c:181
@ TBLOCK_BEGIN
Definition: xact.c:164
@ TBLOCK_SUBINPROGRESS
Definition: xact.c:176
static void AbortTransaction(void)
Definition: xact.c:2821
static TransactionState CurrentTransactionState
Definition: xact.c:260

References AbortSubTransaction(), AbortTransaction(), Assert(), AtAbort_Memory(), AtAbort_Portals(), AtSubAbort_Portals(), TransactionStateData::blockState, CleanupSubTransaction(), CleanupTransaction(), CurrentTransactionState, TransactionStateData::curTransactionOwner, MemoryContextSwitchTo(), TransactionStateData::parent, TransactionStateData::state, TransactionStateData::subTransactionId, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, TBLOCK_SUBRESTART, TopMemoryContext, TRANS_DEFAULT, TRANS_INPROGRESS, and TRANS_START.

Referenced by DisableSubscriptionAndExit(), do_autovacuum(), perform_work_item(), RemoveTempRelationsCallback(), ShutdownPostgres(), start_apply(), and start_table_sync().

◆ BeginImplicitTransactionBlock()

void BeginImplicitTransactionBlock ( void  )

Definition at line 4338 of file xact.c.

4339{
4341
4342 /*
4343 * If we are in STARTED state (that is, no transaction block is open),
4344 * switch to IMPLICIT_INPROGRESS state, creating an implicit transaction
4345 * block.
4346 *
4347 * For caller convenience, we consider all other transaction states as
4348 * legal here; otherwise the caller would need its own state check, which
4349 * seems rather pointless.
4350 */
4351 if (s->blockState == TBLOCK_STARTED)
4353}

References TransactionStateData::blockState, CurrentTransactionState, TBLOCK_IMPLICIT_INPROGRESS, and TBLOCK_STARTED.

Referenced by exec_simple_query(), and start_xact_command().

◆ BeginInternalSubTransaction()

void BeginInternalSubTransaction ( const char *  name)

Definition at line 4706 of file xact.c.

4707{
4709 bool save_ExitOnAnyError = ExitOnAnyError;
4710
4711 /*
4712 * Errors within this function are improbable, but if one does happen we
4713 * force a FATAL exit. Callers generally aren't prepared to handle losing
4714 * control, and moreover our transaction state is probably corrupted if we
4715 * fail partway through; so an ordinary ERROR longjmp isn't okay.
4716 */
4717 ExitOnAnyError = true;
4718
4719 /*
4720 * We do not check for parallel mode here. It's permissible to start and
4721 * end "internal" subtransactions while in parallel mode, so long as no
4722 * new XIDs or command IDs are assigned. Enforcement of that occurs in
4723 * AssignTransactionId() and CommandCounterIncrement().
4724 */
4725
4726 switch (s->blockState)
4727 {
4728 case TBLOCK_STARTED:
4729 case TBLOCK_INPROGRESS:
4732 case TBLOCK_END:
4733 case TBLOCK_PREPARE:
4735 /* Normal subtransaction start */
4737 s = CurrentTransactionState; /* changed by push */
4738
4739 /*
4740 * Savepoint names, like the TransactionState block itself, live
4741 * in TopTransactionContext.
4742 */
4743 if (name)
4745 break;
4746
4747 /* These cases are invalid. */
4748 case TBLOCK_DEFAULT:
4749 case TBLOCK_BEGIN:
4750 case TBLOCK_SUBBEGIN:
4751 case TBLOCK_SUBRELEASE:
4752 case TBLOCK_SUBCOMMIT:
4753 case TBLOCK_ABORT:
4754 case TBLOCK_SUBABORT:
4755 case TBLOCK_ABORT_END:
4759 case TBLOCK_SUBRESTART:
4761 elog(FATAL, "BeginInternalSubTransaction: unexpected state %s",
4763 break;
4764 }
4765
4768
4769 ExitOnAnyError = save_ExitOnAnyError;
4770}
#define FATAL
Definition: elog.h:41
#define elog(elevel,...)
Definition: elog.h:226
bool ExitOnAnyError
Definition: globals.c:123
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1746
MemoryContext TopTransactionContext
Definition: mcxt.c:171
const char * name
static void PushTransaction(void)
Definition: xact.c:5428
void StartTransactionCommand(void)
Definition: xact.c:3071
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5719
void CommitTransactionCommand(void)
Definition: xact.c:3169

References TransactionStateData::blockState, BlockStateAsString(), CommitTransactionCommand(), CurrentTransactionState, elog, ExitOnAnyError, FATAL, MemoryContextStrdup(), TransactionStateData::name, name, PushTransaction(), StartTransactionCommand(), TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, TBLOCK_SUBRESTART, and TopTransactionContext.

Referenced by exec_stmt_block(), plperl_spi_exec(), plperl_spi_exec_prepared(), plperl_spi_fetchrow(), plperl_spi_prepare(), plperl_spi_query(), plperl_spi_query_prepared(), pltcl_returnnext(), pltcl_subtrans_begin(), pltcl_subtransaction(), PLy_spi_subtransaction_begin(), PLy_subtransaction_enter(), ReorderBufferImmediateInvalidation(), and ReorderBufferProcessTXN().

◆ BeginTransactionBlock()

void BeginTransactionBlock ( void  )

Definition at line 3936 of file xact.c.

3937{
3939
3940 switch (s->blockState)
3941 {
3942 /*
3943 * We are not inside a transaction block, so allow one to begin.
3944 */
3945 case TBLOCK_STARTED:
3947 break;
3948
3949 /*
3950 * BEGIN converts an implicit transaction block to a regular one.
3951 * (Note that we allow this even if we've already done some
3952 * commands, which is a bit odd but matches historical practice.)
3953 */
3956 break;
3957
3958 /*
3959 * Already a transaction block in progress.
3960 */
3961 case TBLOCK_INPROGRESS:
3964 case TBLOCK_ABORT:
3965 case TBLOCK_SUBABORT:
3967 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3968 errmsg("there is already a transaction in progress")));
3969 break;
3970
3971 /* These cases are invalid. */
3972 case TBLOCK_DEFAULT:
3973 case TBLOCK_BEGIN:
3974 case TBLOCK_SUBBEGIN:
3975 case TBLOCK_END:
3976 case TBLOCK_SUBRELEASE:
3977 case TBLOCK_SUBCOMMIT:
3978 case TBLOCK_ABORT_END:
3982 case TBLOCK_SUBRESTART:
3984 case TBLOCK_PREPARE:
3985 elog(FATAL, "BeginTransactionBlock: unexpected state %s",
3987 break;
3988 }
3989}
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define WARNING
Definition: elog.h:36
#define ereport(elevel,...)
Definition: elog.h:150

References TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg(), FATAL, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, TBLOCK_SUBRESTART, and WARNING.

Referenced by apply_handle_prepare_internal(), pa_start_subtrans(), and standard_ProcessUtility().

◆ CommandCounterIncrement()

void CommandCounterIncrement ( void  )

Definition at line 1100 of file xact.c.

1101{
1102 /*
1103 * If the current value of the command counter hasn't been "used" to mark
1104 * tuples, we need not increment it, since there's no need to distinguish
1105 * a read-only command from others. This helps postpone command counter
1106 * overflow, and keeps no-op CommandCounterIncrement operations cheap.
1107 */
1109 {
1110 /*
1111 * Workers synchronize transaction state at the beginning of each
1112 * parallel operation, so we can't account for new commands after that
1113 * point.
1114 */
1116 ereport(ERROR,
1117 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
1118 errmsg("cannot start commands during a parallel operation")));
1119
1120 currentCommandId += 1;
1122 {
1123 currentCommandId -= 1;
1124 ereport(ERROR,
1125 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1126 errmsg("cannot have more than 2^32-2 commands in a transaction")));
1127 }
1128 currentCommandIdUsed = false;
1129
1130 /* Propagate new command ID into static snapshots */
1132
1133 /*
1134 * Make any catalog changes done by the just-completed command visible
1135 * in the local syscache. We obviously don't need to do this after a
1136 * read-only command. (But see hacks in inval.c to make real sure we
1137 * don't think a command that queued inval messages was read-only.)
1138 */
1140 }
1141}
#define InvalidCommandId
Definition: c.h:675
#define ERROR
Definition: elog.h:39
#define IsParallelWorker()
Definition: parallel.h:60
void SnapshotSetCommandId(CommandId curcid)
Definition: snapmgr.c:488
static bool currentCommandIdUsed
Definition: xact.c:268
static CommandId currentCommandId
Definition: xact.c:267
bool IsInParallelMode(void)
Definition: xact.c:1089
static void AtCCI_LocalCache(void)
Definition: xact.c:1591

References AtCCI_LocalCache(), currentCommandId, currentCommandIdUsed, ereport, errcode(), errmsg(), ERROR, InvalidCommandId, IsInParallelMode(), IsParallelWorker, and SnapshotSetCommandId().

Referenced by _SPI_execute_plan(), acquire_inherited_sample_rows(), addFkConstraint(), AddRoleMems(), AlterPublicationOptions(), AlterRole(), ATAddCheckNNConstraint(), ATExecAddColumn(), ATExecAlterColumnType(), ATExecAlterConstrInheritability(), ATExecCmd(), ATExecDropColumn(), ATExecDropExpression(), ATExecDropIdentity(), ATExecSetAccessMethodNoStorage(), ATExecSetCompression(), ATExecSetExpression(), ATExecSetNotNull(), ATExecSetTableSpace(), ATExecSetTableSpaceNoStorage(), ATParseTransformCmd(), ATRewriteTables(), AttachPartitionEnsureIndexes(), AttachPartitionForeignKey(), btadjustmembers(), CommitSubTransaction(), CommitTransactionCommandInternal(), copy_table_data(), create_ctas_internal(), create_toast_table(), CreateFKCheckTrigger(), createForeignKeyActionTriggers(), CreateForeignTable(), CreatePublication(), CreateRole(), CreateSchemaCommand(), CreateTriggerFiringOn(), DefineCollation(), DefineDomain(), DefineIndex(), DefineRelation(), DefineVirtualRelation(), delete_pg_statistic(), deleteOneObject(), DetachPartitionFinalize(), do_analyze_rel(), DropClonedTriggersFromPartition(), dropconstraint_internal(), DropForeignKeyConstraintTriggers(), DropRole(), end_replication_step(), EventTriggerDDLCommandEnd(), EventTriggerDDLCommandStart(), EventTriggerInvoke(), EventTriggerSQLDrop(), EventTriggerTableRewrite(), exec_eval_simple_expr(), exec_execute_message(), exec_parse_message(), exec_simple_query(), ExecGrant_common(), ExecGrant_Largeobject(), ExecGrant_Parameter(), ExecGrant_Relation(), execute_sql_string(), ExplainOnePlan(), finish_heap_swap(), fmgr_sql(), hashadjustmembers(), ImportForeignSchema(), index_build(), index_create(), IndexSetParentIndex(), InitTempTableNamespace(), inv_create(), inv_drop(), inv_truncate(), inv_write(), LogicalRepSyncTableStart(), make_new_heap(), makeConfigurationDependencies(), moveArrayTypeName(), objectNamesToOids(), OperatorShellMake(), OperatorUpd(), pg_import_system_collations(), PortalRunMulti(), ProcedureCreate(), process_syncing_tables_for_apply(), ProcessUtilitySlow(), recordExtensionInitPrivWorker(), reindex_index(), reindex_relation(), ReindexRelationConcurrently(), relation_statistics_update(), RelationSetNewRelfilenumber(), RemoveInheritedConstraint(), RemoveRoleFromInitPriv(), RemoveRoleFromObjectPolicy(), RenumberEnumType(), ReplaceRoleInInitPriv(), replorigin_create(), replorigin_drop_by_name(), ri_PerformCheck(), set_attnotnull(), SetDatabaseHasLoginEventTriggers(), SetDefaultACL(), SetMatViewPopulatedState(), shdepReassignOwned(), SPI_cursor_open_internal(), standard_ProcessUtility(), StoreConstraints(), StorePartitionBound(), upsert_pg_statistic(), vacuum(), and validatePartitionedIndex().

◆ CommitTransactionCommand()

void CommitTransactionCommand ( void  )

Definition at line 3169 of file xact.c.

3170{
3171 /*
3172 * Repeatedly call CommitTransactionCommandInternal() until all the work
3173 * is done.
3174 */
3176 {
3177 }
3178}
static bool CommitTransactionCommandInternal(void)
Definition: xact.c:3187

References CommitTransactionCommandInternal().

Referenced by _SPI_commit(), AllTablesyncsReady(), apply_handle_commit_internal(), apply_handle_commit_prepared(), apply_handle_prepare(), apply_handle_prepare_internal(), apply_handle_rollback_prepared(), apply_handle_stream_prepare(), ATExecDetachPartition(), autoprewarm_database_main(), bbsink_server_new(), BeginInternalSubTransaction(), BootstrapModeMain(), clear_subscription_skip_lsn(), cluster_multiple_rels(), DefineIndex(), DisableSubscriptionAndExit(), do_autovacuum(), EventTriggerOnLogin(), exec_replication_command(), finish_sync_worker(), finish_xact_command(), get_database_list(), get_subscription_list(), HasSubscriptionRelationsCached(), IdentifySystem(), index_drop(), initialize_worker_spi(), InitializeLogRepWorker(), InitPostgres(), LogicalRepSyncTableStart(), maybe_reread_subscription(), movedb(), pa_start_subtrans(), pa_stream_abort(), ParallelApplyWorkerMain(), ParallelWorkerMain(), process_syncing_tables_for_apply(), process_syncing_tables_for_sync(), ProcessCatchupInterrupt(), ProcessIncomingNotify(), ReindexMultipleInternal(), ReindexRelationConcurrently(), RemoveTempRelationsCallback(), run_apply_worker(), shell_check_detail(), stream_abort_internal(), stream_stop_internal(), synchronize_slots(), update_retention_status(), vacuum(), vacuum_rel(), validate_remote_info(), and worker_spi_main().

◆ DefineSavepoint()

void DefineSavepoint ( const char *  name)

Definition at line 4385 of file xact.c.

4386{
4388
4389 /*
4390 * Workers synchronize transaction state at the beginning of each parallel
4391 * operation, so we can't account for new subtransactions after that
4392 * point. (Note that this check will certainly error out if s->blockState
4393 * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4394 * below.)
4395 */
4397 ereport(ERROR,
4398 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4399 errmsg("cannot define savepoints during a parallel operation")));
4400
4401 switch (s->blockState)
4402 {
4403 case TBLOCK_INPROGRESS:
4405 /* Normal subtransaction start */
4407 s = CurrentTransactionState; /* changed by push */
4408
4409 /*
4410 * Savepoint names, like the TransactionState block itself, live
4411 * in TopTransactionContext.
4412 */
4413 if (name)
4415 break;
4416
4417 /*
4418 * We disallow savepoint commands in implicit transaction blocks.
4419 * There would be no great difficulty in allowing them so far as
4420 * this module is concerned, but a savepoint seems inconsistent
4421 * with exec_simple_query's behavior of abandoning the whole query
4422 * string upon error. Also, the point of an implicit transaction
4423 * block (as opposed to a regular one) is to automatically close
4424 * after an error, so it's hard to see how a savepoint would fit
4425 * into that.
4426 *
4427 * The error messages for this are phrased as if there were no
4428 * active transaction block at all, which is historical but
4429 * perhaps could be improved.
4430 */
4432 ereport(ERROR,
4433 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4434 /* translator: %s represents an SQL statement name */
4435 errmsg("%s can only be used in transaction blocks",
4436 "SAVEPOINT")));
4437 break;
4438
4439 /* These cases are invalid. */
4440 case TBLOCK_DEFAULT:
4441 case TBLOCK_STARTED:
4442 case TBLOCK_BEGIN:
4444 case TBLOCK_SUBBEGIN:
4445 case TBLOCK_END:
4446 case TBLOCK_SUBRELEASE:
4447 case TBLOCK_SUBCOMMIT:
4448 case TBLOCK_ABORT:
4449 case TBLOCK_SUBABORT:
4450 case TBLOCK_ABORT_END:
4454 case TBLOCK_SUBRESTART:
4456 case TBLOCK_PREPARE:
4457 elog(FATAL, "DefineSavepoint: unexpected state %s",
4459 break;
4460 }
4461}

References TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg(), ERROR, FATAL, IsInParallelMode(), IsParallelWorker, MemoryContextStrdup(), TransactionStateData::name, name, PushTransaction(), TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, TBLOCK_SUBRESTART, and TopTransactionContext.

Referenced by CommitTransactionCommandInternal(), pa_start_subtrans(), and standard_ProcessUtility().

◆ EndImplicitTransactionBlock()

void EndImplicitTransactionBlock ( void  )

Definition at line 4363 of file xact.c.

4364{
4366
4367 /*
4368 * If we are in IMPLICIT_INPROGRESS state, switch back to STARTED state,
4369 * allowing CommitTransactionCommand to commit whatever happened during
4370 * the implicit transaction block as though it were a single statement.
4371 *
4372 * For caller convenience, we consider all other transaction states as
4373 * legal here; otherwise the caller would need its own state check, which
4374 * seems rather pointless.
4375 */
4378}

References TransactionStateData::blockState, CurrentTransactionState, TBLOCK_IMPLICIT_INPROGRESS, and TBLOCK_STARTED.

Referenced by exec_simple_query(), and PostgresMain().

◆ EndParallelWorkerTransaction()

void EndParallelWorkerTransaction ( void  )

◆ EndTransactionBlock()

bool EndTransactionBlock ( bool  chain)

Definition at line 4056 of file xact.c.

4057{
4059 bool result = false;
4060
4061 switch (s->blockState)
4062 {
4063 /*
4064 * We are in a transaction block, so tell CommitTransactionCommand
4065 * to COMMIT.
4066 */
4067 case TBLOCK_INPROGRESS:
4069 result = true;
4070 break;
4071
4072 /*
4073 * We are in an implicit transaction block. If AND CHAIN was
4074 * specified, error. Otherwise commit, but issue a warning
4075 * because there was no explicit BEGIN before this.
4076 */
4078 if (chain)
4079 ereport(ERROR,
4080 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4081 /* translator: %s represents an SQL statement name */
4082 errmsg("%s can only be used in transaction blocks",
4083 "COMMIT AND CHAIN")));
4084 else
4086 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4087 errmsg("there is no transaction in progress")));
4089 result = true;
4090 break;
4091
4092 /*
4093 * We are in a failed transaction block. Tell
4094 * CommitTransactionCommand it's time to exit the block.
4095 */
4096 case TBLOCK_ABORT:
4098 break;
4099
4100 /*
4101 * We are in a live subtransaction block. Set up to subcommit all
4102 * open subtransactions and then commit the main transaction.
4103 */
4105 while (s->parent != NULL)
4106 {
4109 else
4110 elog(FATAL, "EndTransactionBlock: unexpected state %s",
4112 s = s->parent;
4113 }
4114 if (s->blockState == TBLOCK_INPROGRESS)
4116 else
4117 elog(FATAL, "EndTransactionBlock: unexpected state %s",
4119 result = true;
4120 break;
4121
4122 /*
4123 * Here we are inside an aborted subtransaction. Treat the COMMIT
4124 * as ROLLBACK: set up to abort everything and exit the main
4125 * transaction.
4126 */
4127 case TBLOCK_SUBABORT:
4128 while (s->parent != NULL)
4129 {
4132 else if (s->blockState == TBLOCK_SUBABORT)
4134 else
4135 elog(FATAL, "EndTransactionBlock: unexpected state %s",
4137 s = s->parent;
4138 }
4139 if (s->blockState == TBLOCK_INPROGRESS)
4141 else if (s->blockState == TBLOCK_ABORT)
4143 else
4144 elog(FATAL, "EndTransactionBlock: unexpected state %s",
4146 break;
4147
4148 /*
4149 * The user issued COMMIT when not inside a transaction. For
4150 * COMMIT without CHAIN, issue a WARNING, staying in
4151 * TBLOCK_STARTED state. The upcoming call to
4152 * CommitTransactionCommand() will then close the transaction and
4153 * put us back into the default state. For COMMIT AND CHAIN,
4154 * error.
4155 */
4156 case TBLOCK_STARTED:
4157 if (chain)
4158 ereport(ERROR,
4159 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4160 /* translator: %s represents an SQL statement name */
4161 errmsg("%s can only be used in transaction blocks",
4162 "COMMIT AND CHAIN")));
4163 else
4165 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4166 errmsg("there is no transaction in progress")));
4167 result = true;
4168 break;
4169
4170 /*
4171 * The user issued a COMMIT that somehow ran inside a parallel
4172 * worker. We can't cope with that.
4173 */
4175 ereport(FATAL,
4176 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4177 errmsg("cannot commit during a parallel operation")));
4178 break;
4179
4180 /* These cases are invalid. */
4181 case TBLOCK_DEFAULT:
4182 case TBLOCK_BEGIN:
4183 case TBLOCK_SUBBEGIN:
4184 case TBLOCK_END:
4185 case TBLOCK_SUBRELEASE:
4186 case TBLOCK_SUBCOMMIT:
4187 case TBLOCK_ABORT_END:
4191 case TBLOCK_SUBRESTART:
4193 case TBLOCK_PREPARE:
4194 elog(FATAL, "EndTransactionBlock: unexpected state %s",
4196 break;
4197 }
4198
4200 s->blockState == TBLOCK_END ||
4203
4204 s->chain = chain;
4205
4206 return result;
4207}

References Assert(), TransactionStateData::blockState, BlockStateAsString(), TransactionStateData::chain, CurrentTransactionState, elog, ereport, errcode(), errmsg(), ERROR, FATAL, TransactionStateData::parent, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, TBLOCK_SUBRESTART, and WARNING.

Referenced by apply_handle_commit_internal(), pa_stream_abort(), PrepareTransactionBlock(), and standard_ProcessUtility().

◆ EnterParallelMode()

◆ EstimateTransactionStateSpace()

Size EstimateTransactionStateSpace ( void  )

Definition at line 5524 of file xact.c.

5525{
5527 Size nxids = 0;
5529
5530 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5531 {
5533 nxids = add_size(nxids, 1);
5534 nxids = add_size(nxids, s->nChildXids);
5535 }
5536
5537 return add_size(size, mul_size(sizeof(TransactionId), nxids));
5538}
uint32 TransactionId
Definition: c.h:658
size_t Size
Definition: c.h:611
Size add_size(Size s1, Size s2)
Definition: shmem.c:493
Size mul_size(Size s1, Size s2)
Definition: shmem.c:510
FullTransactionId fullTransactionId
Definition: xact.c:195
#define FullTransactionIdIsValid(x)
Definition: transam.h:55
#define SerializedTransactionStateHeaderSize
Definition: xact.c:239

References add_size(), CurrentTransactionState, TransactionStateData::fullTransactionId, FullTransactionIdIsValid, mul_size(), TransactionStateData::nChildXids, TransactionStateData::parent, and SerializedTransactionStateHeaderSize.

Referenced by InitializeParallelDSM().

◆ ExitParallelMode()

◆ ForceSyncCommit()

void ForceSyncCommit ( void  )

Definition at line 1152 of file xact.c.

1153{
1154 forceSyncCommit = true;
1155}
static bool forceSyncCommit
Definition: xact.c:293

References forceSyncCommit.

Referenced by createdb(), CreateTableSpace(), dropdb(), DropTableSpace(), and movedb().

◆ GetCurrentCommandId()

CommandId GetCurrentCommandId ( bool  used)

Definition at line 829 of file xact.c.

830{
831 /* this is global to a transaction, not subtransaction-local */
832 if (used)
833 {
834 /*
835 * Forbid setting currentCommandIdUsed in a parallel worker, because
836 * we have no provision for communicating this back to the leader. We
837 * could relax this restriction when currentCommandIdUsed was already
838 * true at the start of the parallel operation.
839 */
840 if (IsParallelWorker())
842 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
843 errmsg("cannot modify data in a parallel worker")));
844
846 }
847 return currentCommandId;
848}

References currentCommandId, currentCommandIdUsed, ereport, errcode(), errmsg(), ERROR, and IsParallelWorker.

Referenced by ATRewriteTable(), CatalogTuplesMultiInsertWithInfo(), CopyFrom(), create_edata_for_relation(), create_estate_for_relation(), FindConflictTuple(), GetSnapshotData(), GetSnapshotDataReuse(), heap_inplace_lock(), intorel_startup(), pgrowlocks(), RegisterRelcacheInvalidation(), RelationFindReplTupleByIndex(), RelationFindReplTupleSeq(), simple_heap_delete(), simple_heap_insert(), simple_heap_update(), simple_table_tuple_delete(), simple_table_tuple_insert(), simple_table_tuple_update(), standard_ExecutorStart(), toast_save_datum(), transientrel_startup(), and UpdateActiveSnapshotCommandId().

◆ GetCurrentFullTransactionId()

FullTransactionId GetCurrentFullTransactionId ( void  )

Definition at line 512 of file xact.c.

513{
515
518 return s->fullTransactionId;
519}
static void AssignTransactionId(TransactionState s)
Definition: xact.c:635

References AssignTransactionId(), CurrentTransactionState, TransactionStateData::fullTransactionId, and FullTransactionIdIsValid.

Referenced by PrepareTransaction().

◆ GetCurrentFullTransactionIdIfAny()

FullTransactionId GetCurrentFullTransactionIdIfAny ( void  )

Definition at line 530 of file xact.c.

References CurrentTransactionState, and TransactionStateData::fullTransactionId.

◆ GetCurrentStatementStartTimestamp()

TimestampTz GetCurrentStatementStartTimestamp ( void  )

Definition at line 879 of file xact.c.

880{
881 return stmtStartTimestamp;
882}
static TimestampTz stmtStartTimestamp
Definition: xact.c:281

References stmtStartTimestamp.

Referenced by check_log_duration(), CreatePortal(), InitializeParallelDSM(), pgstat_report_activity(), statement_timestamp(), and StorePreparedStatement().

◆ GetCurrentSubTransactionId()

◆ GetCurrentTransactionId()

◆ GetCurrentTransactionIdIfAny()

◆ GetCurrentTransactionNestLevel()

◆ GetCurrentTransactionStartTimestamp()

TimestampTz GetCurrentTransactionStartTimestamp ( void  )

◆ GetCurrentTransactionStopTimestamp()

TimestampTz GetCurrentTransactionStopTimestamp ( void  )

Definition at line 891 of file xact.c.

892{
894
895 /* should only be called after commit / abort processing */
896 Assert(s->state == TRANS_DEFAULT ||
897 s->state == TRANS_COMMIT ||
898 s->state == TRANS_ABORT ||
899 s->state == TRANS_PREPARE);
900
901 if (xactStopTimestamp == 0)
903
904 return xactStopTimestamp;
905}
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1645
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:223
static TimestampTz xactStopTimestamp
Definition: xact.c:282
@ TRANS_COMMIT
Definition: xact.c:146
@ TRANS_ABORT
Definition: xact.c:147
@ TRANS_PREPARE
Definition: xact.c:148

References Assert(), CurrentTransactionState, GetCurrentTimestamp(), PG_USED_FOR_ASSERTS_ONLY, TRANS_ABORT, TRANS_COMMIT, TRANS_DEFAULT, TRANS_PREPARE, and xactStopTimestamp.

Referenced by pgstat_relation_flush_cb(), pgstat_report_stat(), RecordTransactionAbort(), and RecordTransactionCommit().

◆ GetStableLatestTransactionId()

TransactionId GetStableLatestTransactionId ( void  )

Definition at line 607 of file xact.c.

608{
610 static TransactionId stablexid = InvalidTransactionId;
611
612 if (lxid != MyProc->vxid.lxid)
613 {
614 lxid = MyProc->vxid.lxid;
615 stablexid = GetTopTransactionIdIfAny();
616 if (!TransactionIdIsValid(stablexid))
617 stablexid = ReadNextTransactionId();
618 }
619
620 Assert(TransactionIdIsValid(stablexid));
621
622 return stablexid;
623}
uint32 LocalTransactionId
Definition: c.h:660
#define InvalidLocalTransactionId
Definition: lock.h:67
PGPROC * MyProc
Definition: proc.c:66
LocalTransactionId lxid
Definition: proc.h:217
struct PGPROC::@128 vxid
static TransactionId ReadNextTransactionId(void)
Definition: transam.h:315
#define InvalidTransactionId
Definition: transam.h:31
#define TransactionIdIsValid(xid)
Definition: transam.h:41
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:441

References Assert(), GetTopTransactionIdIfAny(), InvalidLocalTransactionId, InvalidTransactionId, PGPROC::lxid, MyProc, ReadNextTransactionId(), TransactionIdIsValid, and PGPROC::vxid.

Referenced by xid_age().

◆ GetTopFullTransactionId()

FullTransactionId GetTopFullTransactionId ( void  )

Definition at line 483 of file xact.c.

484{
488}
static TransactionStateData TopTransactionStateData
Definition: xact.c:247
static FullTransactionId XactTopFullTransactionId
Definition: xact.c:125

References AssignTransactionId(), FullTransactionIdIsValid, TopTransactionStateData, and XactTopFullTransactionId.

Referenced by pg_current_xact_id().

◆ GetTopFullTransactionIdIfAny()

FullTransactionId GetTopFullTransactionIdIfAny ( void  )

Definition at line 499 of file xact.c.

500{
502}

References XactTopFullTransactionId.

Referenced by pg_current_xact_id_if_assigned().

◆ GetTopTransactionId()

◆ GetTopTransactionIdIfAny()

◆ IsAbortedTransactionBlockState()

◆ IsInParallelMode()

◆ IsInTransactionBlock()

bool IsInTransactionBlock ( bool  isTopLevel)

Definition at line 3781 of file xact.c.

3782{
3783 /*
3784 * Return true on same conditions that would make
3785 * PreventInTransactionBlock error out
3786 */
3787 if (IsTransactionBlock())
3788 return true;
3789
3790 if (IsSubTransaction())
3791 return true;
3792
3793 if (!isTopLevel)
3794 return true;
3795
3798 return true;
3799
3800 return false;
3801}
bool IsSubTransaction(void)
Definition: xact.c:5056
bool IsTransactionBlock(void)
Definition: xact.c:4983

References TransactionStateData::blockState, CurrentTransactionState, IsSubTransaction(), IsTransactionBlock(), TBLOCK_DEFAULT, and TBLOCK_STARTED.

Referenced by vacuum().

◆ IsSubTransaction()

◆ IsSubxactTopXidLogPending()

bool IsSubxactTopXidLogPending ( void  )

Definition at line 559 of file xact.c.

560{
561 /* check whether it is already logged */
563 return false;
564
565 /* wal_level has to be logical */
567 return false;
568
569 /* we need to be in a transaction state */
570 if (!IsTransactionState())
571 return false;
572
573 /* it has to be a subtransaction */
574 if (!IsSubTransaction())
575 return false;
576
577 /* the subtransaction has to have a XID assigned */
579 return false;
580
581 return true;
582}
bool IsTransactionState(void)
Definition: xact.c:387
TransactionId GetCurrentTransactionIdIfAny(void)
Definition: xact.c:471
#define XLogLogicalInfoActive()
Definition: xlog.h:126

References CurrentTransactionState, GetCurrentTransactionIdIfAny(), IsSubTransaction(), IsTransactionState(), TransactionStateData::topXidLogged, TransactionIdIsValid, and XLogLogicalInfoActive.

Referenced by MarkSubxactTopXidLogged(), and XLogRecordAssemble().

◆ IsTransactionBlock()

◆ IsTransactionOrTransactionBlock()

◆ IsTransactionState()

bool IsTransactionState ( void  )

Definition at line 387 of file xact.c.

388{
390
391 /*
392 * TRANS_DEFAULT and TRANS_ABORT are obviously unsafe states. However, we
393 * also reject the startup/shutdown states TRANS_START, TRANS_COMMIT,
394 * TRANS_PREPARE since it might be too soon or too late within those
395 * transition states to do anything interesting. Hence, the only "valid"
396 * state is TRANS_INPROGRESS.
397 */
398 return (s->state == TRANS_INPROGRESS);
399}

References CurrentTransactionState, TransactionStateData::state, and TRANS_INPROGRESS.

Referenced by AcceptInvalidationMessages(), apply_handle_commit_internal(), apply_handle_origin(), assign_transaction_timeout(), begin_replication_step(), check_client_encoding(), check_default_table_access_method(), check_default_tablespace(), check_default_text_search_config(), check_role(), check_session_authorization(), check_temp_tablespaces(), check_transaction_isolation(), check_transaction_read_only(), clear_subscription_skip_lsn(), ConditionalCatalogCacheInitializeCache(), CreateInitDecodingContext(), ensure_last_message(), FetchTableStates(), finish_sync_worker(), IsSubxactTopXidLogPending(), LogicalRepApplyLoop(), LogLogicalMessage(), maybe_reread_subscription(), pa_send_data(), pa_start_subtrans(), pg_do_encoding_conversion(), PrepareClientEncoding(), PrepareTempTablespaces(), process_syncing_tables_for_apply(), process_syncing_tables_for_sync(), RelationCacheInvalidate(), RelationFlushRelation(), RelationInitPhysicalAddr(), replorigin_create(), replorigin_drop_by_name(), SetMultiXactIdLimit(), SetTransactionIdLimit(), SnapBuildClearExportedSnapshot(), SocketBackend(), stream_stop_internal(), synchronize_slots(), update_retention_status(), and validate_remote_info().

◆ MarkCurrentTransactionIdLoggedIfAny()

void MarkCurrentTransactionIdLoggedIfAny ( void  )

◆ MarkSubxactTopXidLogged()

void MarkSubxactTopXidLogged ( void  )

Definition at line 591 of file xact.c.

592{
594
596}
bool IsSubxactTopXidLogPending(void)
Definition: xact.c:559

References Assert(), CurrentTransactionState, IsSubxactTopXidLogPending(), and TransactionStateData::topXidLogged.

Referenced by XLogInsertRecord().

◆ ParseAbortRecord()

void ParseAbortRecord ( uint8  info,
xl_xact_abort xlrec,
xl_xact_parsed_abort parsed 
)

Definition at line 141 of file xactdesc.c.

142{
143 char *data = ((char *) xlrec) + MinSizeOfXactAbort;
144
145 memset(parsed, 0, sizeof(*parsed));
146
147 parsed->xinfo = 0; /* default, if no XLOG_XACT_HAS_INFO is
148 * present */
149
150 parsed->xact_time = xlrec->xact_time;
151
152 if (info & XLOG_XACT_HAS_INFO)
153 {
154 xl_xact_xinfo *xl_xinfo = (xl_xact_xinfo *) data;
155
156 parsed->xinfo = xl_xinfo->xinfo;
157
158 data += sizeof(xl_xact_xinfo);
159 }
160
161 if (parsed->xinfo & XACT_XINFO_HAS_DBINFO)
162 {
163 xl_xact_dbinfo *xl_dbinfo = (xl_xact_dbinfo *) data;
164
165 parsed->dbId = xl_dbinfo->dbId;
166 parsed->tsId = xl_dbinfo->tsId;
167
168 data += sizeof(xl_xact_dbinfo);
169 }
170
171 if (parsed->xinfo & XACT_XINFO_HAS_SUBXACTS)
172 {
173 xl_xact_subxacts *xl_subxacts = (xl_xact_subxacts *) data;
174
175 parsed->nsubxacts = xl_subxacts->nsubxacts;
176 parsed->subxacts = xl_subxacts->subxacts;
177
179 data += parsed->nsubxacts * sizeof(TransactionId);
180 }
181
183 {
185
186 parsed->nrels = xl_rellocator->nrels;
187 parsed->xlocators = xl_rellocator->xlocators;
188
190 data += xl_rellocator->nrels * sizeof(RelFileLocator);
191 }
192
194 {
196
197 parsed->nstats = xl_drops->nitems;
198 parsed->stats = xl_drops->items;
199
201 data += xl_drops->nitems * sizeof(xl_xact_stats_item);
202 }
203
204 if (parsed->xinfo & XACT_XINFO_HAS_TWOPHASE)
205 {
206 xl_xact_twophase *xl_twophase = (xl_xact_twophase *) data;
207
208 parsed->twophase_xid = xl_twophase->xid;
209
210 data += sizeof(xl_xact_twophase);
211
212 if (parsed->xinfo & XACT_XINFO_HAS_GID)
213 {
214 strlcpy(parsed->twophase_gid, data, sizeof(parsed->twophase_gid));
215 data += strlen(data) + 1;
216 }
217 }
218
219 /* Note: no alignment is guaranteed after this point */
220
221 if (parsed->xinfo & XACT_XINFO_HAS_ORIGIN)
222 {
223 xl_xact_origin xl_origin;
224
225 /* no alignment is guaranteed, so copy onto stack */
226 memcpy(&xl_origin, data, sizeof(xl_origin));
227
228 parsed->origin_lsn = xl_origin.origin_lsn;
229 parsed->origin_timestamp = xl_origin.origin_timestamp;
230
231 data += sizeof(xl_xact_origin);
232 }
233}
const void * data
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
struct RelFileLocator RelFileLocator
TimestampTz xact_time
Definition: xact.h:339
Oid tsId
Definition: xact.h:259
Oid dbId
Definition: xact.h:258
TimestampTz origin_timestamp
Definition: xact.h:318
XLogRecPtr origin_lsn
Definition: xact.h:317
xl_xact_stats_item * stats
Definition: xact.h:426
RelFileLocator * xlocators
Definition: xact.h:423
TransactionId twophase_xid
Definition: xact.h:428
TimestampTz xact_time
Definition: xact.h:413
TransactionId * subxacts
Definition: xact.h:420
XLogRecPtr origin_lsn
Definition: xact.h:431
char twophase_gid[GIDSIZE]
Definition: xact.h:429
TimestampTz origin_timestamp
Definition: xact.h:432
RelFileLocator xlocators[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:272
xl_xact_stats_item items[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:299
TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:265
int nsubxacts
Definition: xact.h:264
TransactionId xid
Definition: xact.h:312
uint32 xinfo
Definition: xact.h:253
struct xl_xact_stats_item xl_xact_stats_item
#define MinSizeOfXactSubxacts
Definition: xact.h:267
struct xl_xact_dbinfo xl_xact_dbinfo
#define XACT_XINFO_HAS_GID
Definition: xact.h:196
struct xl_xact_origin xl_xact_origin
#define XACT_XINFO_HAS_ORIGIN
Definition: xact.h:194
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:193
#define MinSizeOfXactRelfileLocators
Definition: xact.h:274
#define MinSizeOfXactStatsItems
Definition: xact.h:301
#define XACT_XINFO_HAS_RELFILELOCATORS
Definition: xact.h:191
#define MinSizeOfXactAbort
Definition: xact.h:351
struct xl_xact_xinfo xl_xact_xinfo
#define XACT_XINFO_HAS_DBINFO
Definition: xact.h:189
struct xl_xact_twophase xl_xact_twophase
#define XLOG_XACT_HAS_INFO
Definition: xact.h:183
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:190
#define XACT_XINFO_HAS_DROPPED_STATS
Definition: xact.h:197

References data, xl_xact_dbinfo::dbId, xl_xact_parsed_abort::dbId, xl_xact_stats_items::items, MinSizeOfXactAbort, MinSizeOfXactRelfileLocators, MinSizeOfXactStatsItems, MinSizeOfXactSubxacts, xl_xact_stats_items::nitems, xl_xact_relfilelocators::nrels, xl_xact_parsed_abort::nrels, xl_xact_parsed_abort::nstats, xl_xact_subxacts::nsubxacts, xl_xact_parsed_abort::nsubxacts, xl_xact_origin::origin_lsn, xl_xact_parsed_abort::origin_lsn, xl_xact_origin::origin_timestamp, xl_xact_parsed_abort::origin_timestamp, xl_xact_parsed_abort::stats, strlcpy(), xl_xact_subxacts::subxacts, xl_xact_parsed_abort::subxacts, xl_xact_dbinfo::tsId, xl_xact_parsed_abort::tsId, xl_xact_parsed_abort::twophase_gid, xl_xact_parsed_abort::twophase_xid, xl_xact_abort::xact_time, xl_xact_parsed_abort::xact_time, XACT_XINFO_HAS_DBINFO, XACT_XINFO_HAS_DROPPED_STATS, XACT_XINFO_HAS_GID, XACT_XINFO_HAS_ORIGIN, XACT_XINFO_HAS_RELFILELOCATORS, XACT_XINFO_HAS_SUBXACTS, XACT_XINFO_HAS_TWOPHASE, xl_xact_twophase::xid, xl_xact_xinfo::xinfo, xl_xact_parsed_abort::xinfo, xl_xact_relfilelocators::xlocators, xl_xact_parsed_abort::xlocators, and XLOG_XACT_HAS_INFO.

Referenced by recoveryStopsAfter(), recoveryStopsBefore(), SummarizeXactRecord(), xact_decode(), xact_desc_abort(), and xact_redo().

◆ ParseCommitRecord()

void ParseCommitRecord ( uint8  info,
xl_xact_commit xlrec,
xl_xact_parsed_commit parsed 
)

Definition at line 35 of file xactdesc.c.

36{
37 char *data = ((char *) xlrec) + MinSizeOfXactCommit;
38
39 memset(parsed, 0, sizeof(*parsed));
40
41 parsed->xinfo = 0; /* default, if no XLOG_XACT_HAS_INFO is
42 * present */
43
44 parsed->xact_time = xlrec->xact_time;
45
46 if (info & XLOG_XACT_HAS_INFO)
47 {
48 xl_xact_xinfo *xl_xinfo = (xl_xact_xinfo *) data;
49
50 parsed->xinfo = xl_xinfo->xinfo;
51
52 data += sizeof(xl_xact_xinfo);
53 }
54
55 if (parsed->xinfo & XACT_XINFO_HAS_DBINFO)
56 {
57 xl_xact_dbinfo *xl_dbinfo = (xl_xact_dbinfo *) data;
58
59 parsed->dbId = xl_dbinfo->dbId;
60 parsed->tsId = xl_dbinfo->tsId;
61
62 data += sizeof(xl_xact_dbinfo);
63 }
64
65 if (parsed->xinfo & XACT_XINFO_HAS_SUBXACTS)
66 {
67 xl_xact_subxacts *xl_subxacts = (xl_xact_subxacts *) data;
68
69 parsed->nsubxacts = xl_subxacts->nsubxacts;
70 parsed->subxacts = xl_subxacts->subxacts;
71
73 data += parsed->nsubxacts * sizeof(TransactionId);
74 }
75
77 {
79
80 parsed->nrels = xl_rellocators->nrels;
81 parsed->xlocators = xl_rellocators->xlocators;
82
84 data += xl_rellocators->nrels * sizeof(RelFileLocator);
85 }
86
88 {
90
91 parsed->nstats = xl_drops->nitems;
92 parsed->stats = xl_drops->items;
93
95 data += xl_drops->nitems * sizeof(xl_xact_stats_item);
96 }
97
98 if (parsed->xinfo & XACT_XINFO_HAS_INVALS)
99 {
100 xl_xact_invals *xl_invals = (xl_xact_invals *) data;
101
102 parsed->nmsgs = xl_invals->nmsgs;
103 parsed->msgs = xl_invals->msgs;
104
106 data += xl_invals->nmsgs * sizeof(SharedInvalidationMessage);
107 }
108
109 if (parsed->xinfo & XACT_XINFO_HAS_TWOPHASE)
110 {
111 xl_xact_twophase *xl_twophase = (xl_xact_twophase *) data;
112
113 parsed->twophase_xid = xl_twophase->xid;
114
115 data += sizeof(xl_xact_twophase);
116
117 if (parsed->xinfo & XACT_XINFO_HAS_GID)
118 {
119 strlcpy(parsed->twophase_gid, data, sizeof(parsed->twophase_gid));
120 data += strlen(data) + 1;
121 }
122 }
123
124 /* Note: no alignment is guaranteed after this point */
125
126 if (parsed->xinfo & XACT_XINFO_HAS_ORIGIN)
127 {
128 xl_xact_origin xl_origin;
129
130 /* no alignment is guaranteed, so copy onto stack */
131 memcpy(&xl_origin, data, sizeof(xl_origin));
132
133 parsed->origin_lsn = xl_origin.origin_lsn;
134 parsed->origin_timestamp = xl_origin.origin_timestamp;
135
136 data += sizeof(xl_xact_origin);
137 }
138}
TimestampTz xact_time
Definition: xact.h:323
SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:306
int nmsgs
Definition: xact.h:305
xl_xact_stats_item * stats
Definition: xact.h:393
TimestampTz xact_time
Definition: xact.h:380
TransactionId twophase_xid
Definition: xact.h:398
RelFileLocator * xlocators
Definition: xact.h:390
TimestampTz origin_timestamp
Definition: xact.h:406
TransactionId * subxacts
Definition: xact.h:387
char twophase_gid[GIDSIZE]
Definition: xact.h:399
XLogRecPtr origin_lsn
Definition: xact.h:405
SharedInvalidationMessage * msgs
Definition: xact.h:396
#define MinSizeOfXactInvals
Definition: xact.h:308
#define MinSizeOfXactCommit
Definition: xact.h:335
#define XACT_XINFO_HAS_INVALS
Definition: xact.h:192

References data, xl_xact_dbinfo::dbId, xl_xact_parsed_commit::dbId, xl_xact_stats_items::items, MinSizeOfXactCommit, MinSizeOfXactInvals, MinSizeOfXactRelfileLocators, MinSizeOfXactStatsItems, MinSizeOfXactSubxacts, xl_xact_invals::msgs, xl_xact_parsed_commit::msgs, xl_xact_stats_items::nitems, xl_xact_invals::nmsgs, xl_xact_parsed_commit::nmsgs, xl_xact_relfilelocators::nrels, xl_xact_parsed_commit::nrels, xl_xact_parsed_commit::nstats, xl_xact_subxacts::nsubxacts, xl_xact_parsed_commit::nsubxacts, xl_xact_origin::origin_lsn, xl_xact_parsed_commit::origin_lsn, xl_xact_origin::origin_timestamp, xl_xact_parsed_commit::origin_timestamp, xl_xact_parsed_commit::stats, strlcpy(), xl_xact_subxacts::subxacts, xl_xact_parsed_commit::subxacts, xl_xact_dbinfo::tsId, xl_xact_parsed_commit::tsId, xl_xact_parsed_commit::twophase_gid, xl_xact_parsed_commit::twophase_xid, xl_xact_commit::xact_time, xl_xact_parsed_commit::xact_time, XACT_XINFO_HAS_DBINFO, XACT_XINFO_HAS_DROPPED_STATS, XACT_XINFO_HAS_GID, XACT_XINFO_HAS_INVALS, XACT_XINFO_HAS_ORIGIN, XACT_XINFO_HAS_RELFILELOCATORS, XACT_XINFO_HAS_SUBXACTS, XACT_XINFO_HAS_TWOPHASE, xl_xact_twophase::xid, xl_xact_xinfo::xinfo, xl_xact_parsed_commit::xinfo, xl_xact_relfilelocators::xlocators, xl_xact_parsed_commit::xlocators, and XLOG_XACT_HAS_INFO.

Referenced by recoveryStopsAfter(), recoveryStopsBefore(), SummarizeXactRecord(), xact_decode(), xact_desc_commit(), and xact_redo().

◆ ParsePrepareRecord()

void ParsePrepareRecord ( uint8  info,
xl_xact_prepare xlrec,
xl_xact_parsed_prepare parsed 
)

Definition at line 239 of file xactdesc.c.

240{
241 char *bufptr;
242
243 bufptr = ((char *) xlrec) + MAXALIGN(sizeof(xl_xact_prepare));
244
245 memset(parsed, 0, sizeof(*parsed));
246
247 parsed->xact_time = xlrec->prepared_at;
248 parsed->origin_lsn = xlrec->origin_lsn;
249 parsed->origin_timestamp = xlrec->origin_timestamp;
250 parsed->twophase_xid = xlrec->xid;
251 parsed->dbId = xlrec->database;
252 parsed->nsubxacts = xlrec->nsubxacts;
253 parsed->nrels = xlrec->ncommitrels;
254 parsed->nabortrels = xlrec->nabortrels;
255 parsed->nstats = xlrec->ncommitstats;
256 parsed->nabortstats = xlrec->nabortstats;
257 parsed->nmsgs = xlrec->ninvalmsgs;
258
259 strncpy(parsed->twophase_gid, bufptr, xlrec->gidlen);
260 bufptr += MAXALIGN(xlrec->gidlen);
261
262 parsed->subxacts = (TransactionId *) bufptr;
263 bufptr += MAXALIGN(xlrec->nsubxacts * sizeof(TransactionId));
264
265 parsed->xlocators = (RelFileLocator *) bufptr;
266 bufptr += MAXALIGN(xlrec->ncommitrels * sizeof(RelFileLocator));
267
268 parsed->abortlocators = (RelFileLocator *) bufptr;
269 bufptr += MAXALIGN(xlrec->nabortrels * sizeof(RelFileLocator));
270
271 parsed->stats = (xl_xact_stats_item *) bufptr;
272 bufptr += MAXALIGN(xlrec->ncommitstats * sizeof(xl_xact_stats_item));
273
274 parsed->abortstats = (xl_xact_stats_item *) bufptr;
275 bufptr += MAXALIGN(xlrec->nabortstats * sizeof(xl_xact_stats_item));
276
277 parsed->msgs = (SharedInvalidationMessage *) bufptr;
278 bufptr += MAXALIGN(xlrec->ninvalmsgs * sizeof(SharedInvalidationMessage));
279}
#define MAXALIGN(LEN)
Definition: c.h:811
RelFileLocator * abortlocators
Definition: xact.h:401
xl_xact_stats_item * abortstats
Definition: xact.h:403
TimestampTz prepared_at
Definition: xact.h:359
int32 nabortrels
Definition: xact.h:363
int32 ninvalmsgs
Definition: xact.h:366
int32 ncommitstats
Definition: xact.h:364
TimestampTz origin_timestamp
Definition: xact.h:370
uint16 gidlen
Definition: xact.h:368
int32 nabortstats
Definition: xact.h:365
Oid database
Definition: xact.h:358
XLogRecPtr origin_lsn
Definition: xact.h:369
int32 ncommitrels
Definition: xact.h:362
TransactionId xid
Definition: xact.h:357
int32 nsubxacts
Definition: xact.h:361

References xl_xact_parsed_commit::abortlocators, xl_xact_parsed_commit::abortstats, xl_xact_prepare::database, xl_xact_parsed_commit::dbId, xl_xact_prepare::gidlen, MAXALIGN, xl_xact_parsed_commit::msgs, xl_xact_prepare::nabortrels, xl_xact_parsed_commit::nabortrels, xl_xact_prepare::nabortstats, xl_xact_parsed_commit::nabortstats, xl_xact_prepare::ncommitrels, xl_xact_prepare::ncommitstats, xl_xact_prepare::ninvalmsgs, xl_xact_parsed_commit::nmsgs, xl_xact_parsed_commit::nrels, xl_xact_parsed_commit::nstats, xl_xact_prepare::nsubxacts, xl_xact_parsed_commit::nsubxacts, xl_xact_prepare::origin_lsn, xl_xact_parsed_commit::origin_lsn, xl_xact_prepare::origin_timestamp, xl_xact_parsed_commit::origin_timestamp, xl_xact_prepare::prepared_at, xl_xact_parsed_commit::stats, xl_xact_parsed_commit::subxacts, xl_xact_parsed_commit::twophase_gid, xl_xact_parsed_commit::twophase_xid, xl_xact_parsed_commit::xact_time, xl_xact_prepare::xid, and xl_xact_parsed_commit::xlocators.

Referenced by xact_decode(), and xact_desc_prepare().

◆ PrepareTransactionBlock()

bool PrepareTransactionBlock ( const char *  gid)

Definition at line 4004 of file xact.c.

4005{
4007 bool result;
4008
4009 /* Set up to commit the current transaction */
4010 result = EndTransactionBlock(false);
4011
4012 /* If successful, change outer tblock state to PREPARE */
4013 if (result)
4014 {
4016
4017 while (s->parent != NULL)
4018 s = s->parent;
4019
4020 if (s->blockState == TBLOCK_END)
4021 {
4022 /* Save GID where PrepareTransaction can find it again */
4024
4026 }
4027 else
4028 {
4029 /*
4030 * ignore case where we are not in a transaction;
4031 * EndTransactionBlock already issued a warning.
4032 */
4035 /* Don't send back a PREPARE result tag... */
4036 result = false;
4037 }
4038 }
4039
4040 return result;
4041}
static char * prepareGID
Definition: xact.c:288
bool EndTransactionBlock(bool chain)
Definition: xact.c:4056

References Assert(), TransactionStateData::blockState, CurrentTransactionState, EndTransactionBlock(), MemoryContextStrdup(), TransactionStateData::parent, prepareGID, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, and TopTransactionContext.

Referenced by apply_handle_prepare_internal(), and standard_ProcessUtility().

◆ PreventInTransactionBlock()

void PreventInTransactionBlock ( bool  isTopLevel,
const char *  stmtType 
)

Definition at line 3660 of file xact.c.

3661{
3662 /*
3663 * xact block already started?
3664 */
3665 if (IsTransactionBlock())
3666 ereport(ERROR,
3667 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3668 /* translator: %s represents an SQL statement name */
3669 errmsg("%s cannot run inside a transaction block",
3670 stmtType)));
3671
3672 /*
3673 * subtransaction?
3674 */
3675 if (IsSubTransaction())
3676 ereport(ERROR,
3677 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3678 /* translator: %s represents an SQL statement name */
3679 errmsg("%s cannot run inside a subtransaction",
3680 stmtType)));
3681
3682 /*
3683 * inside a function call?
3684 */
3685 if (!isTopLevel)
3686 ereport(ERROR,
3687 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3688 /* translator: %s represents an SQL statement name */
3689 errmsg("%s cannot be executed from a function", stmtType)));
3690
3691 /* If we got past IsTransactionBlock test, should be in default state */
3694 elog(FATAL, "cannot prevent transaction chain");
3695
3696 /* All okay. Set the flag to make sure the right thing happens later. */
3698}
int MyXactFlags
Definition: xact.c:136
#define XACT_FLAGS_NEEDIMMEDIATECOMMIT
Definition: xact.h:115

References TransactionStateData::blockState, CurrentTransactionState, elog, ereport, errcode(), errmsg(), ERROR, FATAL, IsSubTransaction(), IsTransactionBlock(), MyXactFlags, TBLOCK_DEFAULT, TBLOCK_STARTED, and XACT_FLAGS_NEEDIMMEDIATECOMMIT.

Referenced by AlterDatabase(), AlterSubscription(), CheckAlterSubOption(), cluster(), CreateSubscription(), DiscardAll(), DropSubscription(), exec_replication_command(), ExecDropStmt(), ExecReindex(), ProcessUtilitySlow(), ReindexPartitions(), standard_ProcessUtility(), and vacuum().

◆ RegisterSubXactCallback()

void RegisterSubXactCallback ( SubXactCallback  callback,
void *  arg 
)

Definition at line 3876 of file xact.c.

3877{
3878 SubXactCallbackItem *item;
3879
3880 item = (SubXactCallbackItem *)
3882 item->callback = callback;
3883 item->arg = arg;
3884 item->next = SubXact_callbacks;
3885 SubXact_callbacks = item;
3886}
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1229
void * arg
struct SubXactCallbackItem * next
Definition: xact.c:322
SubXactCallback callback
Definition: xact.c:323
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46
static SubXactCallbackItem * SubXact_callbacks
Definition: xact.c:327

References SubXactCallbackItem::arg, arg, SubXactCallbackItem::callback, callback(), MemoryContextAlloc(), SubXactCallbackItem::next, SubXact_callbacks, and TopMemoryContext.

Referenced by _PG_init(), GetConnection(), and sepgsql_init_client_label().

◆ RegisterXactCallback()

void RegisterXactCallback ( XactCallback  callback,
void *  arg 
)

Definition at line 3816 of file xact.c.

3817{
3818 XactCallbackItem *item;
3819
3820 item = (XactCallbackItem *)
3822 item->callback = callback;
3823 item->arg = arg;
3824 item->next = Xact_callbacks;
3825 Xact_callbacks = item;
3826}
struct XactCallbackItem * next
Definition: xact.c:310
void * arg
Definition: xact.c:312
XactCallback callback
Definition: xact.c:311
static XactCallbackItem * Xact_callbacks
Definition: xact.c:315

References XactCallbackItem::arg, arg, XactCallbackItem::callback, callback(), MemoryContextAlloc(), XactCallbackItem::next, TopMemoryContext, and Xact_callbacks.

Referenced by _PG_init(), GetConnection(), and sepgsql_init_client_label().

◆ ReleaseCurrentSubTransaction()

void ReleaseCurrentSubTransaction ( void  )

Definition at line 4780 of file xact.c.

4781{
4783
4784 /*
4785 * We do not check for parallel mode here. It's permissible to start and
4786 * end "internal" subtransactions while in parallel mode, so long as no
4787 * new XIDs or command IDs are assigned.
4788 */
4789
4791 elog(ERROR, "ReleaseCurrentSubTransaction: unexpected state %s",
4796 s = CurrentTransactionState; /* changed by pop */
4798}
MemoryContext CurTransactionContext
Definition: mcxt.c:172
static void CommitSubTransaction(void)
Definition: xact.c:5116

References Assert(), TransactionStateData::blockState, BlockStateAsString(), CommitSubTransaction(), CurrentTransactionState, CurTransactionContext, elog, ERROR, MemoryContextSwitchTo(), TransactionStateData::state, TBLOCK_SUBINPROGRESS, and TRANS_INPROGRESS.

Referenced by exec_stmt_block(), plperl_spi_exec(), plperl_spi_exec_prepared(), plperl_spi_fetchrow(), plperl_spi_prepare(), plperl_spi_query(), plperl_spi_query_prepared(), pltcl_subtrans_commit(), pltcl_subtransaction(), PLy_spi_subtransaction_commit(), and PLy_subtransaction_exit().

◆ ReleaseSavepoint()

void ReleaseSavepoint ( const char *  name)

Definition at line 4470 of file xact.c.

4471{
4473 TransactionState target,
4474 xact;
4475
4476 /*
4477 * Workers synchronize transaction state at the beginning of each parallel
4478 * operation, so we can't account for transaction state change after that
4479 * point. (Note that this check will certainly error out if s->blockState
4480 * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4481 * below.)
4482 */
4484 ereport(ERROR,
4485 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4486 errmsg("cannot release savepoints during a parallel operation")));
4487
4488 switch (s->blockState)
4489 {
4490 /*
4491 * We can't release a savepoint if there is no savepoint defined.
4492 */
4493 case TBLOCK_INPROGRESS:
4494 ereport(ERROR,
4495 (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4496 errmsg("savepoint \"%s\" does not exist", name)));
4497 break;
4498
4500 /* See comment about implicit transactions in DefineSavepoint */
4501 ereport(ERROR,
4502 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4503 /* translator: %s represents an SQL statement name */
4504 errmsg("%s can only be used in transaction blocks",
4505 "RELEASE SAVEPOINT")));
4506 break;
4507
4508 /*
4509 * We are in a non-aborted subtransaction. This is the only valid
4510 * case.
4511 */
4513 break;
4514
4515 /* These cases are invalid. */
4516 case TBLOCK_DEFAULT:
4517 case TBLOCK_STARTED:
4518 case TBLOCK_BEGIN:
4520 case TBLOCK_SUBBEGIN:
4521 case TBLOCK_END:
4522 case TBLOCK_SUBRELEASE:
4523 case TBLOCK_SUBCOMMIT:
4524 case TBLOCK_ABORT:
4525 case TBLOCK_SUBABORT:
4526 case TBLOCK_ABORT_END:
4530 case TBLOCK_SUBRESTART:
4532 case TBLOCK_PREPARE:
4533 elog(FATAL, "ReleaseSavepoint: unexpected state %s",
4535 break;
4536 }
4537
4538 for (target = s; target; target = target->parent)
4539 {
4540 if (target->name && strcmp(target->name, name) == 0)
4541 break;
4542 }
4543
4544 if (!target)
4545 ereport(ERROR,
4546 (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4547 errmsg("savepoint \"%s\" does not exist", name)));
4548
4549 /* disallow crossing savepoint level boundaries */
4550 if (target->savepointLevel != s->savepointLevel)
4551 ereport(ERROR,
4552 (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4553 errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
4554
4555 /*
4556 * Mark "commit pending" all subtransactions up to the target
4557 * subtransaction. The actual commits will happen when control gets to
4558 * CommitTransactionCommand.
4559 */
4561 for (;;)
4562 {
4565 if (xact == target)
4566 break;
4567 xact = xact->parent;
4568 Assert(xact);
4569 }
4570}

References Assert(), TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg(), ERROR, FATAL, IsInParallelMode(), IsParallelWorker, TransactionStateData::name, name, TransactionStateData::parent, TransactionStateData::savepointLevel, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, and TBLOCK_SUBRESTART.

Referenced by standard_ProcessUtility().

◆ RequireTransactionBlock()

void RequireTransactionBlock ( bool  isTopLevel,
const char *  stmtType 
)

Definition at line 3728 of file xact.c.

3729{
3730 CheckTransactionBlock(isTopLevel, true, stmtType);
3731}
static void CheckTransactionBlock(bool isTopLevel, bool throwError, const char *stmtType)
Definition: xact.c:3737

References CheckTransactionBlock().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

◆ RestoreTransactionCharacteristics()

◆ RollbackAndReleaseCurrentSubTransaction()

void RollbackAndReleaseCurrentSubTransaction ( void  )

Definition at line 4808 of file xact.c.

4809{
4811
4812 /*
4813 * We do not check for parallel mode here. It's permissible to start and
4814 * end "internal" subtransactions while in parallel mode, so long as no
4815 * new XIDs or command IDs are assigned.
4816 */
4817
4818 switch (s->blockState)
4819 {
4820 /* Must be in a subtransaction */
4822 case TBLOCK_SUBABORT:
4823 break;
4824
4825 /* These cases are invalid. */
4826 case TBLOCK_DEFAULT:
4827 case TBLOCK_STARTED:
4828 case TBLOCK_BEGIN:
4831 case TBLOCK_SUBBEGIN:
4832 case TBLOCK_INPROGRESS:
4833 case TBLOCK_END:
4834 case TBLOCK_SUBRELEASE:
4835 case TBLOCK_SUBCOMMIT:
4836 case TBLOCK_ABORT:
4837 case TBLOCK_ABORT_END:
4841 case TBLOCK_SUBRESTART:
4843 case TBLOCK_PREPARE:
4844 elog(FATAL, "RollbackAndReleaseCurrentSubTransaction: unexpected state %s",
4846 break;
4847 }
4848
4849 /*
4850 * Abort the current subtransaction, if needed.
4851 */
4854
4855 /* And clean it up, too */
4857
4858 s = CurrentTransactionState; /* changed by pop */
4864}

References AbortSubTransaction(), Assert(), TransactionStateData::blockState, BlockStateAsString(), CleanupSubTransaction(), CurrentTransactionState, elog, FATAL, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, and TBLOCK_SUBRESTART.

Referenced by exec_stmt_block(), plperl_spi_exec(), plperl_spi_exec_prepared(), plperl_spi_fetchrow(), plperl_spi_prepare(), plperl_spi_query(), plperl_spi_query_prepared(), pltcl_subtrans_abort(), pltcl_subtransaction(), PLy_abort_open_subtransactions(), PLy_spi_subtransaction_abort(), PLy_subtransaction_exit(), ReorderBufferImmediateInvalidation(), and ReorderBufferProcessTXN().

◆ RollbackToSavepoint()

void RollbackToSavepoint ( const char *  name)

Definition at line 4579 of file xact.c.

4580{
4582 TransactionState target,
4583 xact;
4584
4585 /*
4586 * Workers synchronize transaction state at the beginning of each parallel
4587 * operation, so we can't account for transaction state change after that
4588 * point. (Note that this check will certainly error out if s->blockState
4589 * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4590 * below.)
4591 */
4593 ereport(ERROR,
4594 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4595 errmsg("cannot rollback to savepoints during a parallel operation")));
4596
4597 switch (s->blockState)
4598 {
4599 /*
4600 * We can't rollback to a savepoint if there is no savepoint
4601 * defined.
4602 */
4603 case TBLOCK_INPROGRESS:
4604 case TBLOCK_ABORT:
4605 ereport(ERROR,
4606 (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4607 errmsg("savepoint \"%s\" does not exist", name)));
4608 break;
4609
4611 /* See comment about implicit transactions in DefineSavepoint */
4612 ereport(ERROR,
4613 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4614 /* translator: %s represents an SQL statement name */
4615 errmsg("%s can only be used in transaction blocks",
4616 "ROLLBACK TO SAVEPOINT")));
4617 break;
4618
4619 /*
4620 * There is at least one savepoint, so proceed.
4621 */
4623 case TBLOCK_SUBABORT:
4624 break;
4625
4626 /* These cases are invalid. */
4627 case TBLOCK_DEFAULT:
4628 case TBLOCK_STARTED:
4629 case TBLOCK_BEGIN:
4631 case TBLOCK_SUBBEGIN:
4632 case TBLOCK_END:
4633 case TBLOCK_SUBRELEASE:
4634 case TBLOCK_SUBCOMMIT:
4635 case TBLOCK_ABORT_END:
4639 case TBLOCK_SUBRESTART:
4641 case TBLOCK_PREPARE:
4642 elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4644 break;
4645 }
4646
4647 for (target = s; target; target = target->parent)
4648 {
4649 if (target->name && strcmp(target->name, name) == 0)
4650 break;
4651 }
4652
4653 if (!target)
4654 ereport(ERROR,
4655 (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4656 errmsg("savepoint \"%s\" does not exist", name)));
4657
4658 /* disallow crossing savepoint level boundaries */
4659 if (target->savepointLevel != s->savepointLevel)
4660 ereport(ERROR,
4661 (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4662 errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
4663
4664 /*
4665 * Mark "abort pending" all subtransactions up to the target
4666 * subtransaction. The actual aborts will happen when control gets to
4667 * CommitTransactionCommand.
4668 */
4670 for (;;)
4671 {
4672 if (xact == target)
4673 break;
4674 if (xact->blockState == TBLOCK_SUBINPROGRESS)
4676 else if (xact->blockState == TBLOCK_SUBABORT)
4678 else
4679 elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4681 xact = xact->parent;
4682 Assert(xact);
4683 }
4684
4685 /* And mark the target as "restart pending" */
4686 if (xact->blockState == TBLOCK_SUBINPROGRESS)
4688 else if (xact->blockState == TBLOCK_SUBABORT)
4690 else
4691 elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4693}

References Assert(), TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg(), ERROR, FATAL, IsInParallelMode(), IsParallelWorker, TransactionStateData::name, name, TransactionStateData::parent, TransactionStateData::savepointLevel, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, and TBLOCK_SUBRESTART.

Referenced by pa_stream_abort(), and standard_ProcessUtility().

◆ SaveTransactionCharacteristics()

◆ SerializeTransactionState()

void SerializeTransactionState ( Size  maxsize,
char *  start_address 
)

Definition at line 5552 of file xact.c.

5553{
5555 Size nxids = 0;
5556 Size i = 0;
5557 TransactionId *workspace;
5559
5560 result = (SerializedTransactionState *) start_address;
5561
5562 result->xactIsoLevel = XactIsoLevel;
5565 result->currentFullTransactionId =
5568
5569 /*
5570 * If we're running in a parallel worker and launching a parallel worker
5571 * of our own, we can just pass along the information that was passed to
5572 * us.
5573 */
5574 if (nParallelCurrentXids > 0)
5575 {
5577 memcpy(&result->parallelCurrentXids[0], ParallelCurrentXids,
5579 return;
5580 }
5581
5582 /*
5583 * OK, we need to generate a sorted list of XIDs that our workers should
5584 * view as current. First, figure out how many there are.
5585 */
5586 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5587 {
5589 nxids = add_size(nxids, 1);
5590 nxids = add_size(nxids, s->nChildXids);
5591 }
5593 <= maxsize);
5594
5595 /* Copy them to our scratch space. */
5596 workspace = palloc(nxids * sizeof(TransactionId));
5597 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5598 {
5600 workspace[i++] = XidFromFullTransactionId(s->fullTransactionId);
5601 if (s->nChildXids > 0)
5602 memcpy(&workspace[i], s->childXids,
5603 s->nChildXids * sizeof(TransactionId));
5604 i += s->nChildXids;
5605 }
5606 Assert(i == nxids);
5607
5608 /* Sort them. */
5609 qsort(workspace, nxids, sizeof(TransactionId), xidComparator);
5610
5611 /* Copy data into output area. */
5612 result->nParallelCurrentXids = nxids;
5613 memcpy(&result->parallelCurrentXids[0], workspace,
5614 nxids * sizeof(TransactionId));
5615}
int i
Definition: isn.c:77
void * palloc(Size size)
Definition: mcxt.c:1365
#define qsort(a, b, c, d)
Definition: port.h:479
FullTransactionId currentFullTransactionId
Definition: xact.c:232
FullTransactionId topFullTransactionId
Definition: xact.c:231
CommandId currentCommandId
Definition: xact.c:233
TransactionId parallelCurrentXids[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.c:235
TransactionId * childXids
Definition: xact.c:206
static int nParallelCurrentXids
Definition: xact.c:126
static TransactionId * ParallelCurrentXids
Definition: xact.c:127
int xidComparator(const void *arg1, const void *arg2)
Definition: xid.c:152

References add_size(), Assert(), TransactionStateData::childXids, SerializedTransactionState::currentCommandId, currentCommandId, SerializedTransactionState::currentFullTransactionId, CurrentTransactionState, TransactionStateData::fullTransactionId, FullTransactionIdIsValid, i, TransactionStateData::nChildXids, nParallelCurrentXids, SerializedTransactionState::nParallelCurrentXids, palloc(), ParallelCurrentXids, SerializedTransactionState::parallelCurrentXids, TransactionStateData::parent, qsort, SerializedTransactionStateHeaderSize, SerializedTransactionState::topFullTransactionId, XactDeferrable, SerializedTransactionState::xactDeferrable, XactIsoLevel, SerializedTransactionState::xactIsoLevel, XactTopFullTransactionId, xidComparator(), and XidFromFullTransactionId.

Referenced by InitializeParallelDSM().

◆ SetCurrentStatementStartTimestamp()

◆ SetParallelStartTimestamps()

void SetParallelStartTimestamps ( TimestampTz  xact_ts,
TimestampTz  stmt_ts 
)

Definition at line 859 of file xact.c.

860{
862 xactStartTimestamp = xact_ts;
863 stmtStartTimestamp = stmt_ts;
864}

References Assert(), IsParallelWorker, stmtStartTimestamp, and xactStartTimestamp.

Referenced by ParallelWorkerMain().

◆ StartParallelWorkerTransaction()

void StartParallelWorkerTransaction ( char *  tstatespace)

◆ StartTransactionCommand()

void StartTransactionCommand ( void  )

Definition at line 3071 of file xact.c.

3072{
3074
3075 switch (s->blockState)
3076 {
3077 /*
3078 * if we aren't in a transaction block, we just do our usual start
3079 * transaction.
3080 */
3081 case TBLOCK_DEFAULT:
3084 break;
3085
3086 /*
3087 * We are somewhere in a transaction block or subtransaction and
3088 * about to start a new command. For now we do nothing, but
3089 * someday we may do command-local resource initialization. (Note
3090 * that any needed CommandCounterIncrement was done by the
3091 * previous CommitTransactionCommand.)
3092 */
3093 case TBLOCK_INPROGRESS:
3096 break;
3097
3098 /*
3099 * Here we are in a failed transaction block (one of the commands
3100 * caused an abort) so we do nothing but remain in the abort
3101 * state. Eventually we will get a ROLLBACK command which will
3102 * get us out of this state. (It is up to other code to ensure
3103 * that no commands other than ROLLBACK will be processed in these
3104 * states.)
3105 */
3106 case TBLOCK_ABORT:
3107 case TBLOCK_SUBABORT:
3108 break;
3109
3110 /* These cases are invalid. */
3111 case TBLOCK_STARTED:
3112 case TBLOCK_BEGIN:
3114 case TBLOCK_SUBBEGIN:
3115 case TBLOCK_END:
3116 case TBLOCK_SUBRELEASE:
3117 case TBLOCK_SUBCOMMIT:
3118 case TBLOCK_ABORT_END:
3122 case TBLOCK_SUBRESTART:
3124 case TBLOCK_PREPARE:
3125 elog(ERROR, "StartTransactionCommand: unexpected state %s",
3127 break;
3128 }
3129
3130 /*
3131 * We must switch to CurTransactionContext before returning. This is
3132 * already done if we called StartTransaction, otherwise not.
3133 */
3136}

References Assert(), TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, CurTransactionContext, elog, ERROR, MemoryContextSwitchTo(), StartTransaction(), TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, and TBLOCK_SUBRESTART.

Referenced by _SPI_commit(), _SPI_rollback(), apply_handle_commit_internal(), ATExecDetachPartition(), autoprewarm_database_main(), bbsink_server_new(), begin_replication_step(), BeginInternalSubTransaction(), BootstrapModeMain(), clear_subscription_skip_lsn(), cluster(), cluster_multiple_rels(), DefineIndex(), DisableSubscriptionAndExit(), do_autovacuum(), EventTriggerOnLogin(), exec_replication_command(), FetchTableStates(), finish_sync_worker(), get_database_list(), get_subscription_list(), IdentifySystem(), index_drop(), initialize_worker_spi(), InitializeLogRepWorker(), InitPostgres(), LogicalRepSyncTableStart(), maybe_reread_subscription(), movedb(), pa_start_subtrans(), ParallelApplyWorkerMain(), ParallelWorkerMain(), perform_work_item(), process_syncing_tables_for_apply(), process_syncing_tables_for_sync(), ProcessCatchupInterrupt(), ProcessIncomingNotify(), ReindexMultipleInternal(), ReindexRelationConcurrently(), RemoveTempRelationsCallback(), ReorderBufferProcessTXN(), run_apply_worker(), shell_check_detail(), SnapBuildExportSnapshot(), start_xact_command(), synchronize_slots(), update_retention_status(), vacuum(), vacuum_rel(), validate_remote_info(), and worker_spi_main().

◆ SubTransactionIsActive()

bool SubTransactionIsActive ( SubTransactionId  subxid)

Definition at line 805 of file xact.c.

806{
808
809 for (s = CurrentTransactionState; s != NULL; s = s->parent)
810 {
811 if (s->state == TRANS_ABORT)
812 continue;
813 if (s->subTransactionId == subxid)
814 return true;
815 }
816 return false;
817}

References CurrentTransactionState, TransactionStateData::parent, TransactionStateData::state, TransactionStateData::subTransactionId, and TRANS_ABORT.

◆ TransactionBlockStatusCode()

char TransactionBlockStatusCode ( void  )

Definition at line 5015 of file xact.c.

5016{
5018
5019 switch (s->blockState)
5020 {
5021 case TBLOCK_DEFAULT:
5022 case TBLOCK_STARTED:
5023 return 'I'; /* idle --- not in transaction */
5024 case TBLOCK_BEGIN:
5025 case TBLOCK_SUBBEGIN:
5026 case TBLOCK_INPROGRESS:
5030 case TBLOCK_END:
5031 case TBLOCK_SUBRELEASE:
5032 case TBLOCK_SUBCOMMIT:
5033 case TBLOCK_PREPARE:
5034 return 'T'; /* in transaction */
5035 case TBLOCK_ABORT:
5036 case TBLOCK_SUBABORT:
5037 case TBLOCK_ABORT_END:
5041 case TBLOCK_SUBRESTART:
5043 return 'E'; /* in failed transaction */
5044 }
5045
5046 /* should never get here */
5047 elog(FATAL, "invalid transaction block state: %s",
5049 return 0; /* keep compiler quiet */
5050}

References TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, FATAL, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, and TBLOCK_SUBRESTART.

Referenced by ReadyForQuery().

◆ TransactionIdIsCurrentTransactionId()

bool TransactionIdIsCurrentTransactionId ( TransactionId  xid)

Definition at line 941 of file xact.c.

942{
944
945 /*
946 * We always say that BootstrapTransactionId is "not my transaction ID"
947 * even when it is (ie, during bootstrap). Along with the fact that
948 * transam.c always treats BootstrapTransactionId as already committed,
949 * this causes the heapam_visibility.c routines to see all tuples as
950 * committed, which is what we need during bootstrap. (Bootstrap mode
951 * only inserts tuples, it never updates or deletes them, so all tuples
952 * can be presumed good immediately.)
953 *
954 * Likewise, InvalidTransactionId and FrozenTransactionId are certainly
955 * not my transaction ID, so we can just return "false" immediately for
956 * any non-normal XID.
957 */
958 if (!TransactionIdIsNormal(xid))
959 return false;
960
962 return true;
963
964 /*
965 * In parallel workers, the XIDs we must consider as current are stored in
966 * ParallelCurrentXids rather than the transaction-state stack. Note that
967 * the XIDs in this array are sorted numerically rather than according to
968 * transactionIdPrecedes order.
969 */
970 if (nParallelCurrentXids > 0)
971 {
972 int low,
973 high;
974
975 low = 0;
976 high = nParallelCurrentXids - 1;
977 while (low <= high)
978 {
979 int middle;
980 TransactionId probe;
981
982 middle = low + (high - low) / 2;
983 probe = ParallelCurrentXids[middle];
984 if (probe == xid)
985 return true;
986 else if (probe < xid)
987 low = middle + 1;
988 else
989 high = middle - 1;
990 }
991 return false;
992 }
993
994 /*
995 * We will return true for the Xid of the current subtransaction, any of
996 * its subcommitted children, any of its parents, or any of their
997 * previously subcommitted children. However, a transaction being aborted
998 * is no longer "current", even though it may still have an entry on the
999 * state stack.
1000 */
1001 for (s = CurrentTransactionState; s != NULL; s = s->parent)
1002 {
1003 int low,
1004 high;
1005
1006 if (s->state == TRANS_ABORT)
1007 continue;
1009 continue; /* it can't have any child XIDs either */
1011 return true;
1012 /* As the childXids array is ordered, we can use binary search */
1013 low = 0;
1014 high = s->nChildXids - 1;
1015 while (low <= high)
1016 {
1017 int middle;
1018 TransactionId probe;
1019
1020 middle = low + (high - low) / 2;
1021 probe = s->childXids[middle];
1022 if (TransactionIdEquals(probe, xid))
1023 return true;
1024 else if (TransactionIdPrecedes(probe, xid))
1025 low = middle + 1;
1026 else
1027 high = middle - 1;
1028 }
1029 }
1030
1031 return false;
1032}
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:280
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
#define TransactionIdIsNormal(xid)
Definition: transam.h:42

References TransactionStateData::childXids, CurrentTransactionState, TransactionStateData::fullTransactionId, FullTransactionIdIsValid, GetTopTransactionIdIfAny(), TransactionStateData::nChildXids, nParallelCurrentXids, ParallelCurrentXids, TransactionStateData::parent, TransactionStateData::state, TRANS_ABORT, TransactionIdEquals, TransactionIdIsNormal, TransactionIdPrecedes(), and XidFromFullTransactionId.

Referenced by compute_new_xmax_infomask(), Do_MultiXactIdWait(), DoesMultiXactIdConflict(), ExecCheckTupleVisible(), ExecMergeMatched(), ExecOnConflictUpdate(), FreezeMultiXactId(), get_xid_status(), heap_delete(), heap_inplace_lock(), heap_lock_tuple(), heap_update(), heapam_index_build_range_scan(), heapam_relation_copy_for_cluster(), heapam_scan_analyze_next_tuple(), heapam_tuple_lock(), HeapTupleHeaderAdjustCmax(), HeapTupleHeaderGetCmax(), HeapTupleHeaderGetCmin(), HeapTupleHeaderIsOnlyLocked(), HeapTupleSatisfiesDirty(), HeapTupleSatisfiesMVCC(), HeapTupleSatisfiesSelf(), HeapTupleSatisfiesToast(), HeapTupleSatisfiesUpdate(), HeapTupleSatisfiesVacuumHorizon(), MultiXactIdIsRunning(), PredicateLockTID(), SnapBuildWaitSnapshot(), test_lockmode_for_conflict(), TransactionIdIsInProgress(), tts_buffer_is_current_xact_tuple(), and tts_heap_is_current_xact_tuple().

◆ UnregisterSubXactCallback()

void UnregisterSubXactCallback ( SubXactCallback  callback,
void *  arg 
)

Definition at line 3889 of file xact.c.

3890{
3891 SubXactCallbackItem *item;
3892 SubXactCallbackItem *prev;
3893
3894 prev = NULL;
3895 for (item = SubXact_callbacks; item; prev = item, item = item->next)
3896 {
3897 if (item->callback == callback && item->arg == arg)
3898 {
3899 if (prev)
3900 prev->next = item->next;
3901 else
3902 SubXact_callbacks = item->next;
3903 pfree(item);
3904 break;
3905 }
3906 }
3907}
void pfree(void *pointer)
Definition: mcxt.c:1594

References SubXactCallbackItem::arg, arg, SubXactCallbackItem::callback, callback(), SubXactCallbackItem::next, pfree(), and SubXact_callbacks.

◆ UnregisterXactCallback()

void UnregisterXactCallback ( XactCallback  callback,
void *  arg 
)

Definition at line 3829 of file xact.c.

3830{
3831 XactCallbackItem *item;
3832 XactCallbackItem *prev;
3833
3834 prev = NULL;
3835 for (item = Xact_callbacks; item; prev = item, item = item->next)
3836 {
3837 if (item->callback == callback && item->arg == arg)
3838 {
3839 if (prev)
3840 prev->next = item->next;
3841 else
3842 Xact_callbacks = item->next;
3843 pfree(item);
3844 break;
3845 }
3846 }
3847}

References XactCallbackItem::arg, arg, XactCallbackItem::callback, callback(), XactCallbackItem::next, pfree(), and Xact_callbacks.

◆ UserAbortTransactionBlock()

void UserAbortTransactionBlock ( bool  chain)

Definition at line 4216 of file xact.c.

4217{
4219
4220 switch (s->blockState)
4221 {
4222 /*
4223 * We are inside a transaction block and we got a ROLLBACK command
4224 * from the user, so tell CommitTransactionCommand to abort and
4225 * exit the transaction block.
4226 */
4227 case TBLOCK_INPROGRESS:
4229 break;
4230
4231 /*
4232 * We are inside a failed transaction block and we got a ROLLBACK
4233 * command from the user. Abort processing is already done, so
4234 * CommitTransactionCommand just has to cleanup and go back to
4235 * idle state.
4236 */
4237 case TBLOCK_ABORT:
4239 break;
4240
4241 /*
4242 * We are inside a subtransaction. Mark everything up to top
4243 * level as exitable.
4244 */
4246 case TBLOCK_SUBABORT:
4247 while (s->parent != NULL)
4248 {
4251 else if (s->blockState == TBLOCK_SUBABORT)
4253 else
4254 elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4256 s = s->parent;
4257 }
4258 if (s->blockState == TBLOCK_INPROGRESS)
4260 else if (s->blockState == TBLOCK_ABORT)
4262 else
4263 elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4265 break;
4266
4267 /*
4268 * The user issued ABORT when not inside a transaction. For
4269 * ROLLBACK without CHAIN, issue a WARNING and go to abort state.
4270 * The upcoming call to CommitTransactionCommand() will then put
4271 * us back into the default state. For ROLLBACK AND CHAIN, error.
4272 *
4273 * We do the same thing with ABORT inside an implicit transaction,
4274 * although in this case we might be rolling back actual database
4275 * state changes. (It's debatable whether we should issue a
4276 * WARNING in this case, but we have done so historically.)
4277 */
4278 case TBLOCK_STARTED:
4280 if (chain)
4281 ereport(ERROR,
4282 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4283 /* translator: %s represents an SQL statement name */
4284 errmsg("%s can only be used in transaction blocks",
4285 "ROLLBACK AND CHAIN")));
4286 else
4288 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4289 errmsg("there is no transaction in progress")));
4291 break;
4292
4293 /*
4294 * The user issued an ABORT that somehow ran inside a parallel
4295 * worker. We can't cope with that.
4296 */
4298 ereport(FATAL,
4299 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4300 errmsg("cannot abort during a parallel operation")));
4301 break;
4302
4303 /* These cases are invalid. */
4304 case TBLOCK_DEFAULT:
4305 case TBLOCK_BEGIN:
4306 case TBLOCK_SUBBEGIN:
4307 case TBLOCK_END:
4308 case TBLOCK_SUBRELEASE:
4309 case TBLOCK_SUBCOMMIT:
4310 case TBLOCK_ABORT_END:
4314 case TBLOCK_SUBRESTART:
4316 case TBLOCK_PREPARE:
4317 elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4319 break;
4320 }
4321
4324
4325 s->chain = chain;
4326}

References Assert(), TransactionStateData::blockState, BlockStateAsString(), TransactionStateData::chain, CurrentTransactionState, elog, ereport, errcode(), errmsg(), ERROR, FATAL, TransactionStateData::parent, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_IMPLICIT_INPROGRESS, TBLOCK_INPROGRESS, TBLOCK_PARALLEL_INPROGRESS, TBLOCK_PREPARE, TBLOCK_STARTED, TBLOCK_SUBABORT, TBLOCK_SUBABORT_END, TBLOCK_SUBABORT_PENDING, TBLOCK_SUBABORT_RESTART, TBLOCK_SUBBEGIN, TBLOCK_SUBCOMMIT, TBLOCK_SUBINPROGRESS, TBLOCK_SUBRELEASE, TBLOCK_SUBRESTART, and WARNING.

Referenced by standard_ProcessUtility().

◆ WarnNoTransactionBlock()

void WarnNoTransactionBlock ( bool  isTopLevel,
const char *  stmtType 
)

Definition at line 3722 of file xact.c.

3723{
3724 CheckTransactionBlock(isTopLevel, false, stmtType);
3725}

References CheckTransactionBlock().

Referenced by ExecSetVariableStmt(), and standard_ProcessUtility().

◆ xact_desc()

void xact_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 439 of file xactdesc.c.

440{
441 char *rec = XLogRecGetData(record);
442 uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
443
444 if (info == XLOG_XACT_COMMIT || info == XLOG_XACT_COMMIT_PREPARED)
445 {
446 xl_xact_commit *xlrec = (xl_xact_commit *) rec;
447
448 xact_desc_commit(buf, XLogRecGetInfo(record), xlrec,
449 XLogRecGetOrigin(record));
450 }
451 else if (info == XLOG_XACT_ABORT || info == XLOG_XACT_ABORT_PREPARED)
452 {
453 xl_xact_abort *xlrec = (xl_xact_abort *) rec;
454
455 xact_desc_abort(buf, XLogRecGetInfo(record), xlrec,
456 XLogRecGetOrigin(record));
457 }
458 else if (info == XLOG_XACT_PREPARE)
459 {
460 xl_xact_prepare *xlrec = (xl_xact_prepare *) rec;
461
462 xact_desc_prepare(buf, XLogRecGetInfo(record), xlrec,
463 XLogRecGetOrigin(record));
464 }
465 else if (info == XLOG_XACT_ASSIGNMENT)
466 {
467 xl_xact_assignment *xlrec = (xl_xact_assignment *) rec;
468
469 /*
470 * Note that we ignore the WAL record's xid, since we're more
471 * interested in the top-level xid that issued the record and which
472 * xids are being reported here.
473 */
474 appendStringInfo(buf, "xtop %u: ", xlrec->xtop);
476 }
477 else if (info == XLOG_XACT_INVALIDATIONS)
478 {
479 xl_xact_invals *xlrec = (xl_xact_invals *) rec;
480
482 InvalidOid, false);
483 }
484}
uint8_t uint8
Definition: c.h:537
static char * buf
Definition: pg_test_fsync.c:72
#define InvalidOid
Definition: postgres_ext.h:37
void standby_desc_invalidations(StringInfo buf, int nmsgs, SharedInvalidationMessage *msgs, Oid dbId, Oid tsId, bool relcacheInitFileInval)
Definition: standbydesc.c:101
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
TransactionId xtop
Definition: xact.h:221
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:173
#define XLOG_XACT_INVALIDATIONS
Definition: xact.h:176
#define XLOG_XACT_PREPARE
Definition: xact.h:171
#define XLOG_XACT_COMMIT
Definition: xact.h:170
#define XLOG_XACT_OPMASK
Definition: xact.h:180
#define XLOG_XACT_ABORT
Definition: xact.h:172
#define XLOG_XACT_ASSIGNMENT
Definition: xact.h:175
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:174
static void xact_desc_commit(StringInfo buf, uint8 info, xl_xact_commit *xlrec, RepOriginId origin_id)
Definition: xactdesc.c:334
static void xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec, RepOriginId origin_id)
Definition: xactdesc.c:370
static void xact_desc_assignment(StringInfo buf, xl_xact_assignment *xlrec)
Definition: xactdesc.c:428
static void xact_desc_prepare(StringInfo buf, uint8 info, xl_xact_prepare *xlrec, RepOriginId origin_id)
Definition: xactdesc.c:397
#define XLogRecGetOrigin(decoder)
Definition: xlogreader.h:413
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:410
#define XLogRecGetData(decoder)
Definition: xlogreader.h:415

References appendStringInfo(), buf, InvalidOid, xl_xact_invals::msgs, xl_xact_invals::nmsgs, standby_desc_invalidations(), xact_desc_abort(), xact_desc_assignment(), xact_desc_commit(), xact_desc_prepare(), XLOG_XACT_ABORT, XLOG_XACT_ABORT_PREPARED, XLOG_XACT_ASSIGNMENT, XLOG_XACT_COMMIT, XLOG_XACT_COMMIT_PREPARED, XLOG_XACT_INVALIDATIONS, XLOG_XACT_OPMASK, XLOG_XACT_PREPARE, XLogRecGetData, XLogRecGetInfo, XLogRecGetOrigin, and xl_xact_assignment::xtop.

◆ xact_identify()

const char * xact_identify ( uint8  info)

Definition at line 487 of file xactdesc.c.

488{
489 const char *id = NULL;
490
491 switch (info & XLOG_XACT_OPMASK)
492 {
493 case XLOG_XACT_COMMIT:
494 id = "COMMIT";
495 break;
497 id = "PREPARE";
498 break;
499 case XLOG_XACT_ABORT:
500 id = "ABORT";
501 break;
503 id = "COMMIT_PREPARED";
504 break;
506 id = "ABORT_PREPARED";
507 break;
509 id = "ASSIGNMENT";
510 break;
512 id = "INVALIDATION";
513 break;
514 }
515
516 return id;
517}

References XLOG_XACT_ABORT, XLOG_XACT_ABORT_PREPARED, XLOG_XACT_ASSIGNMENT, XLOG_XACT_COMMIT, XLOG_XACT_COMMIT_PREPARED, XLOG_XACT_INVALIDATIONS, XLOG_XACT_OPMASK, and XLOG_XACT_PREPARE.

◆ xact_redo()

void xact_redo ( XLogReaderState record)

Definition at line 6375 of file xact.c.

6376{
6377 uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
6378
6379 /* Backup blocks are not used in xact records */
6381
6382 if (info == XLOG_XACT_COMMIT)
6383 {
6384 xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6385 xl_xact_parsed_commit parsed;
6386
6387 ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6388 xact_redo_commit(&parsed, XLogRecGetXid(record),
6389 record->EndRecPtr, XLogRecGetOrigin(record));
6390 }
6391 else if (info == XLOG_XACT_COMMIT_PREPARED)
6392 {
6393 xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6394 xl_xact_parsed_commit parsed;
6395
6396 ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6397 xact_redo_commit(&parsed, parsed.twophase_xid,
6398 record->EndRecPtr, XLogRecGetOrigin(record));
6399
6400 /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6401 LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6402 PrepareRedoRemove(parsed.twophase_xid, false);
6403 LWLockRelease(TwoPhaseStateLock);
6404 }
6405 else if (info == XLOG_XACT_ABORT)
6406 {
6407 xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6408 xl_xact_parsed_abort parsed;
6409
6410 ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6411 xact_redo_abort(&parsed, XLogRecGetXid(record),
6412 record->EndRecPtr, XLogRecGetOrigin(record));
6413 }
6414 else if (info == XLOG_XACT_ABORT_PREPARED)
6415 {
6416 xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6417 xl_xact_parsed_abort parsed;
6418
6419 ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6420 xact_redo_abort(&parsed, parsed.twophase_xid,
6421 record->EndRecPtr, XLogRecGetOrigin(record));
6422
6423 /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6424 LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6425 PrepareRedoRemove(parsed.twophase_xid, false);
6426 LWLockRelease(TwoPhaseStateLock);
6427 }
6428 else if (info == XLOG_XACT_PREPARE)
6429 {
6430 /*
6431 * Store xid and start/end pointers of the WAL record in TwoPhaseState
6432 * gxact entry.
6433 */
6434 LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6436 XLogRecGetData(record),
6437 record->ReadRecPtr,
6438 record->EndRecPtr,
6439 XLogRecGetOrigin(record));
6440 LWLockRelease(TwoPhaseStateLock);
6441 }
6442 else if (info == XLOG_XACT_ASSIGNMENT)
6443 {
6445
6448 xlrec->nsubxacts, xlrec->xsub);
6449 }
6450 else if (info == XLOG_XACT_INVALIDATIONS)
6451 {
6452 /*
6453 * XXX we do ignore this for now, what matters are invalidations
6454 * written into the commit record.
6455 */
6456 }
6457 else
6458 elog(PANIC, "xact_redo: unknown op code %u", info);
6459}
#define PANIC
Definition: elog.h:42
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1174
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1894
@ LW_EXCLUSIVE
Definition: lwlock.h:112
void ProcArrayApplyXidAssignment(TransactionId topxid, int nsubxids, TransactionId *subxids)
Definition: procarray.c:1318
XLogRecPtr EndRecPtr
Definition: xlogreader.h:207
XLogRecPtr ReadRecPtr
Definition: xlogreader.h:206
TransactionId xsub[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:223
#define InvalidFullTransactionId
Definition: transam.h:56
void PrepareRedoRemove(TransactionId xid, bool giveWarning)
Definition: twophase.c:2664
void PrepareRedoAdd(FullTransactionId fxid, char *buf, XLogRecPtr start_lsn, XLogRecPtr end_lsn, RepOriginId origin_id)
Definition: twophase.c:2507
static void xact_redo_commit(xl_xact_parsed_commit *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:6142
static void xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:6296
void ParseCommitRecord(uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *parsed)
Definition: xactdesc.c:35
void ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
Definition: xactdesc.c:141
#define XLogRecGetXid(decoder)
Definition: xlogreader.h:412
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:417
HotStandbyState standbyState
Definition: xlogutils.c:53
@ STANDBY_INITIALIZED
Definition: xlogutils.h:53

References Assert(), elog, XLogReaderState::EndRecPtr, InvalidFullTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), xl_xact_assignment::nsubxacts, PANIC, ParseAbortRecord(), ParseCommitRecord(), PrepareRedoAdd(), PrepareRedoRemove(), ProcArrayApplyXidAssignment(), XLogReaderState::ReadRecPtr, STANDBY_INITIALIZED, standbyState, xl_xact_parsed_commit::twophase_xid, xl_xact_parsed_abort::twophase_xid, xact_redo_abort(), xact_redo_commit(), XLOG_XACT_ABORT, XLOG_XACT_ABORT_PREPARED, XLOG_XACT_ASSIGNMENT, XLOG_XACT_COMMIT, XLOG_XACT_COMMIT_PREPARED, XLOG_XACT_INVALIDATIONS, XLOG_XACT_OPMASK, XLOG_XACT_PREPARE, XLogRecGetData, XLogRecGetInfo, XLogRecGetOrigin, XLogRecGetXid, XLogRecHasAnyBlockRefs, xl_xact_assignment::xsub, and xl_xact_assignment::xtop.

◆ xactGetCommittedChildren()

int xactGetCommittedChildren ( TransactionId **  ptr)

Definition at line 5802 of file xact.c.

5803{
5805
5806 if (s->nChildXids == 0)
5807 *ptr = NULL;
5808 else
5809 *ptr = s->childXids;
5810
5811 return s->nChildXids;
5812}

References TransactionStateData::childXids, CurrentTransactionState, and TransactionStateData::nChildXids.

Referenced by ExportSnapshot(), RecordTransactionAbort(), RecordTransactionCommit(), and StartPrepare().

◆ XactLogAbortRecord()

XLogRecPtr XactLogAbortRecord ( TimestampTz  abort_time,
int  nsubxacts,
TransactionId subxacts,
int  nrels,
RelFileLocator rels,
int  ndroppedstats,
xl_xact_stats_item droppedstats,
int  xactflags,
TransactionId  twophase_xid,
const char *  twophase_gid 
)

Definition at line 5998 of file xact.c.

6004{
6005 xl_xact_abort xlrec;
6006 xl_xact_xinfo xl_xinfo;
6007 xl_xact_subxacts xl_subxacts;
6008 xl_xact_relfilelocators xl_relfilelocators;
6009 xl_xact_stats_items xl_dropped_stats;
6010 xl_xact_twophase xl_twophase;
6011 xl_xact_dbinfo xl_dbinfo;
6012 xl_xact_origin xl_origin;
6013
6014 uint8 info;
6015
6017
6018 xl_xinfo.xinfo = 0;
6019
6020 /* decide between a plain and 2pc abort */
6021 if (!TransactionIdIsValid(twophase_xid))
6022 info = XLOG_XACT_ABORT;
6023 else
6025
6026
6027 /* First figure out and collect all the information needed */
6028
6029 xlrec.xact_time = abort_time;
6030
6032 xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
6033
6034 if (nsubxacts > 0)
6035 {
6036 xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
6037 xl_subxacts.nsubxacts = nsubxacts;
6038 }
6039
6040 if (nrels > 0)
6041 {
6043 xl_relfilelocators.nrels = nrels;
6044 info |= XLR_SPECIAL_REL_UPDATE;
6045 }
6046
6047 if (ndroppedstats > 0)
6048 {
6050 xl_dropped_stats.nitems = ndroppedstats;
6051 }
6052
6053 if (TransactionIdIsValid(twophase_xid))
6054 {
6055 xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
6056 xl_twophase.xid = twophase_xid;
6057 Assert(twophase_gid != NULL);
6058
6060 xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
6061 }
6062
6063 if (TransactionIdIsValid(twophase_xid) && XLogLogicalInfoActive())
6064 {
6065 xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
6066 xl_dbinfo.dbId = MyDatabaseId;
6067 xl_dbinfo.tsId = MyDatabaseTableSpace;
6068 }
6069
6070 /*
6071 * Dump transaction origin information. We need this during recovery to
6072 * update the replication origin progress.
6073 */
6075 {
6076 xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
6077
6080 }
6081
6082 if (xl_xinfo.xinfo != 0)
6083 info |= XLOG_XACT_HAS_INFO;
6084
6085 /* Then include all the collected data into the abort record. */
6086
6088
6090
6091 if (xl_xinfo.xinfo != 0)
6092 XLogRegisterData(&xl_xinfo, sizeof(xl_xinfo));
6093
6094 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
6095 XLogRegisterData(&xl_dbinfo, sizeof(xl_dbinfo));
6096
6097 if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
6098 {
6099 XLogRegisterData(&xl_subxacts,
6101 XLogRegisterData(subxacts,
6102 nsubxacts * sizeof(TransactionId));
6103 }
6104
6106 {
6107 XLogRegisterData(&xl_relfilelocators,
6109 XLogRegisterData(rels,
6110 nrels * sizeof(RelFileLocator));
6111 }
6112
6113 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
6114 {
6115 XLogRegisterData(&xl_dropped_stats,
6117 XLogRegisterData(droppedstats,
6118 ndroppedstats * sizeof(xl_xact_stats_item));
6119 }
6120
6121 if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
6122 {
6123 XLogRegisterData(&xl_twophase, sizeof(xl_xact_twophase));
6124 if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
6125 XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
6126 }
6127
6128 if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
6129 XLogRegisterData(&xl_origin, sizeof(xl_xact_origin));
6130
6131 /* Include the replication origin */
6133
6134 return XLogInsert(RM_XACT_ID, info);
6135}
Oid MyDatabaseTableSpace
Definition: globals.c:96
volatile uint32 CritSectionCount
Definition: globals.c:45
Oid MyDatabaseId
Definition: globals.c:94
TimestampTz replorigin_session_origin_timestamp
Definition: origin.c:165
RepOriginId replorigin_session_origin
Definition: origin.c:163
XLogRecPtr replorigin_session_origin_lsn
Definition: origin.c:164
#define InvalidRepOriginId
Definition: origin.h:33
#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK
Definition: xact.h:109
#define XACT_XINFO_HAS_AE_LOCKS
Definition: xact.h:195
#define XLOG_INCLUDE_ORIGIN
Definition: xlog.h:154
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:474
void XLogRegisterData(const void *data, uint32 len)
Definition: xloginsert.c:364
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:456
void XLogBeginInsert(void)
Definition: xloginsert.c:149
#define XLR_SPECIAL_REL_UPDATE
Definition: xlogrecord.h:82

References Assert(), CritSectionCount, xl_xact_dbinfo::dbId, InvalidRepOriginId, MinSizeOfXactAbort, MinSizeOfXactRelfileLocators, MinSizeOfXactStatsItems, MinSizeOfXactSubxacts, MyDatabaseId, MyDatabaseTableSpace, xl_xact_stats_items::nitems, xl_xact_relfilelocators::nrels, xl_xact_subxacts::nsubxacts, xl_xact_origin::origin_lsn, xl_xact_origin::origin_timestamp, replorigin_session_origin, replorigin_session_origin_lsn, replorigin_session_origin_timestamp, TransactionIdIsValid, xl_xact_dbinfo::tsId, XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK, xl_xact_abort::xact_time, XACT_XINFO_HAS_AE_LOCKS, XACT_XINFO_HAS_DBINFO, XACT_XINFO_HAS_DROPPED_STATS, XACT_XINFO_HAS_GID, XACT_XINFO_HAS_ORIGIN, XACT_XINFO_HAS_RELFILELOCATORS, XACT_XINFO_HAS_SUBXACTS, XACT_XINFO_HAS_TWOPHASE, xl_xact_twophase::xid, xl_xact_xinfo::xinfo, XLOG_INCLUDE_ORIGIN, XLOG_XACT_ABORT, XLOG_XACT_ABORT_PREPARED, XLOG_XACT_HAS_INFO, XLogBeginInsert(), XLogInsert(), XLogLogicalInfoActive, XLogRegisterData(), XLogSetRecordFlags(), and XLR_SPECIAL_REL_UPDATE.

Referenced by RecordTransactionAbort(), and RecordTransactionAbortPrepared().

◆ XactLogCommitRecord()

XLogRecPtr XactLogCommitRecord ( TimestampTz  commit_time,
int  nsubxacts,
TransactionId subxacts,
int  nrels,
RelFileLocator rels,
int  ndroppedstats,
xl_xact_stats_item droppedstats,
int  nmsgs,
SharedInvalidationMessage msgs,
bool  relcacheInval,
int  xactflags,
TransactionId  twophase_xid,
const char *  twophase_gid 
)

Definition at line 5826 of file xact.c.

5834{
5835 xl_xact_commit xlrec;
5836 xl_xact_xinfo xl_xinfo;
5837 xl_xact_dbinfo xl_dbinfo;
5838 xl_xact_subxacts xl_subxacts;
5839 xl_xact_relfilelocators xl_relfilelocators;
5840 xl_xact_stats_items xl_dropped_stats;
5841 xl_xact_invals xl_invals;
5842 xl_xact_twophase xl_twophase;
5843 xl_xact_origin xl_origin;
5844 uint8 info;
5845
5847
5848 xl_xinfo.xinfo = 0;
5849
5850 /* decide between a plain and 2pc commit */
5851 if (!TransactionIdIsValid(twophase_xid))
5852 info = XLOG_XACT_COMMIT;
5853 else
5855
5856 /* First figure out and collect all the information needed */
5857
5858 xlrec.xact_time = commit_time;
5859
5860 if (relcacheInval)
5862 if (forceSyncCommit)
5865 xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5866
5867 /*
5868 * Check if the caller would like to ask standbys for immediate feedback
5869 * once this commit is applied.
5870 */
5873
5874 /*
5875 * Relcache invalidations requires information about the current database
5876 * and so does logical decoding.
5877 */
5878 if (nmsgs > 0 || XLogLogicalInfoActive())
5879 {
5880 xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5881 xl_dbinfo.dbId = MyDatabaseId;
5882 xl_dbinfo.tsId = MyDatabaseTableSpace;
5883 }
5884
5885 if (nsubxacts > 0)
5886 {
5887 xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5888 xl_subxacts.nsubxacts = nsubxacts;
5889 }
5890
5891 if (nrels > 0)
5892 {
5894 xl_relfilelocators.nrels = nrels;
5895 info |= XLR_SPECIAL_REL_UPDATE;
5896 }
5897
5898 if (ndroppedstats > 0)
5899 {
5901 xl_dropped_stats.nitems = ndroppedstats;
5902 }
5903
5904 if (nmsgs > 0)
5905 {
5906 xl_xinfo.xinfo |= XACT_XINFO_HAS_INVALS;
5907 xl_invals.nmsgs = nmsgs;
5908 }
5909
5910 if (TransactionIdIsValid(twophase_xid))
5911 {
5912 xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5913 xl_twophase.xid = twophase_xid;
5914 Assert(twophase_gid != NULL);
5915
5917 xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
5918 }
5919
5920 /* dump transaction origin information */
5922 {
5923 xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
5924
5927 }
5928
5929 if (xl_xinfo.xinfo != 0)
5930 info |= XLOG_XACT_HAS_INFO;
5931
5932 /* Then include all the collected data into the commit record. */
5933
5935
5936 XLogRegisterData(&xlrec, sizeof(xl_xact_commit));
5937
5938 if (xl_xinfo.xinfo != 0)
5939 XLogRegisterData(&xl_xinfo.xinfo, sizeof(xl_xinfo.xinfo));
5940
5941 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5942 XLogRegisterData(&xl_dbinfo, sizeof(xl_dbinfo));
5943
5944 if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5945 {
5946 XLogRegisterData(&xl_subxacts,
5948 XLogRegisterData(subxacts,
5949 nsubxacts * sizeof(TransactionId));
5950 }
5951
5953 {
5954 XLogRegisterData(&xl_relfilelocators,
5956 XLogRegisterData(rels,
5957 nrels * sizeof(RelFileLocator));
5958 }
5959
5960 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
5961 {
5962 XLogRegisterData(&xl_dropped_stats,
5964 XLogRegisterData(droppedstats,
5965 ndroppedstats * sizeof(xl_xact_stats_item));
5966 }
5967
5968 if (xl_xinfo.xinfo & XACT_XINFO_HAS_INVALS)
5969 {
5971 XLogRegisterData(msgs,
5972 nmsgs * sizeof(SharedInvalidationMessage));
5973 }
5974
5975 if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5976 {
5977 XLogRegisterData(&xl_twophase, sizeof(xl_xact_twophase));
5978 if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
5979 XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
5980 }
5981
5982 if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5983 XLogRegisterData(&xl_origin, sizeof(xl_xact_origin));
5984
5985 /* we allow filtering by xacts */
5987
5988 return XLogInsert(RM_XACT_ID, info);
5989}
int synchronous_commit
Definition: xact.c:87
#define XACT_COMPLETION_UPDATE_RELCACHE_FILE
Definition: xact.h:208
#define XACT_COMPLETION_FORCE_SYNC_COMMIT
Definition: xact.h:209
#define XACT_COMPLETION_APPLY_FEEDBACK
Definition: xact.h:207

References Assert(), CritSectionCount, xl_xact_dbinfo::dbId, forceSyncCommit, InvalidRepOriginId, MinSizeOfXactInvals, MinSizeOfXactRelfileLocators, MinSizeOfXactStatsItems, MinSizeOfXactSubxacts, MyDatabaseId, MyDatabaseTableSpace, xl_xact_stats_items::nitems, xl_xact_invals::nmsgs, xl_xact_relfilelocators::nrels, xl_xact_subxacts::nsubxacts, xl_xact_origin::origin_lsn, xl_xact_origin::origin_timestamp, replorigin_session_origin, replorigin_session_origin_lsn, replorigin_session_origin_timestamp, synchronous_commit, SYNCHRONOUS_COMMIT_REMOTE_APPLY, TransactionIdIsValid, xl_xact_dbinfo::tsId, XACT_COMPLETION_APPLY_FEEDBACK, XACT_COMPLETION_FORCE_SYNC_COMMIT, XACT_COMPLETION_UPDATE_RELCACHE_FILE, XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK, xl_xact_commit::xact_time, XACT_XINFO_HAS_AE_LOCKS, XACT_XINFO_HAS_DBINFO, XACT_XINFO_HAS_DROPPED_STATS, XACT_XINFO_HAS_GID, XACT_XINFO_HAS_INVALS, XACT_XINFO_HAS_ORIGIN, XACT_XINFO_HAS_RELFILELOCATORS, XACT_XINFO_HAS_SUBXACTS, XACT_XINFO_HAS_TWOPHASE, xl_xact_twophase::xid, xl_xact_xinfo::xinfo, XLOG_INCLUDE_ORIGIN, XLOG_XACT_COMMIT, XLOG_XACT_COMMIT_PREPARED, XLOG_XACT_HAS_INFO, XLogBeginInsert(), XLogInsert(), XLogLogicalInfoActive, XLogRegisterData(), XLogSetRecordFlags(), and XLR_SPECIAL_REL_UPDATE.

Referenced by RecordTransactionCommit(), and RecordTransactionCommitPrepared().

Variable Documentation

◆ bsysscan

◆ CheckXidAlive

◆ DefaultXactDeferrable

PGDLLIMPORT bool DefaultXactDeferrable
extern

Definition at line 84 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactIsoLevel

PGDLLIMPORT int DefaultXactIsoLevel
extern

Definition at line 78 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactReadOnly

PGDLLIMPORT bool DefaultXactReadOnly
extern

Definition at line 81 of file xact.c.

Referenced by StartTransaction().

◆ MyXactFlags

◆ synchronous_commit

PGDLLIMPORT int synchronous_commit
extern

Definition at line 87 of file xact.c.

Referenced by AutoVacWorkerMain(), RecordTransactionCommit(), and XactLogCommitRecord().

◆ xact_is_sampled

PGDLLIMPORT bool xact_is_sampled
extern

Definition at line 296 of file xact.c.

Referenced by check_log_duration(), and StartTransaction().

◆ XactDeferrable

◆ XactIsoLevel

◆ XactReadOnly