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 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 52 of file xact.h.

◆ IsolationUsesXactSnapshot

#define IsolationUsesXactSnapshot ( )    (XactIsoLevel >= XACT_REPEATABLE_READ)

Definition at line 51 of file xact.h.

◆ MinSizeOfXactAbort

#define MinSizeOfXactAbort   sizeof(xl_xact_abort)

Definition at line 337 of file xact.h.

◆ MinSizeOfXactAssignment

#define MinSizeOfXactAssignment   offsetof(xl_xact_assignment, xsub)

Definition at line 218 of file xact.h.

◆ MinSizeOfXactCommit

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

Definition at line 321 of file xact.h.

◆ MinSizeOfXactInvals

#define MinSizeOfXactInvals   offsetof(xl_xact_invals, msgs)

Definition at line 294 of file xact.h.

◆ MinSizeOfXactRelfileLocators

#define MinSizeOfXactRelfileLocators   offsetof(xl_xact_relfilelocators, xlocators)

Definition at line 266 of file xact.h.

◆ MinSizeOfXactStatsItems

#define MinSizeOfXactStatsItems   offsetof(xl_xact_stats_items, items)

Definition at line 287 of file xact.h.

◆ MinSizeOfXactSubxacts

#define MinSizeOfXactSubxacts   offsetof(xl_xact_subxacts, subxacts)

Definition at line 259 of file xact.h.

◆ SYNCHRONOUS_COMMIT_ON

#define SYNCHRONOUS_COMMIT_ON   SYNCHRONOUS_COMMIT_REMOTE_FLUSH

Definition at line 80 of file xact.h.

◆ XACT_COMPLETION_APPLY_FEEDBACK

#define XACT_COMPLETION_APPLY_FEEDBACK   (1U << 29)

Definition at line 199 of file xact.h.

◆ XACT_COMPLETION_FORCE_SYNC_COMMIT

#define XACT_COMPLETION_FORCE_SYNC_COMMIT   (1U << 31)

Definition at line 201 of file xact.h.

◆ XACT_COMPLETION_UPDATE_RELCACHE_FILE

#define XACT_COMPLETION_UPDATE_RELCACHE_FILE   (1U << 30)

Definition at line 200 of file xact.h.

◆ XACT_FLAGS_ACCESSEDTEMPNAMESPACE

#define XACT_FLAGS_ACCESSEDTEMPNAMESPACE   (1U << 0)

Definition at line 102 of file xact.h.

◆ XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK

#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK   (1U << 1)

Definition at line 108 of file xact.h.

◆ XACT_FLAGS_NEEDIMMEDIATECOMMIT

#define XACT_FLAGS_NEEDIMMEDIATECOMMIT   (1U << 2)

Definition at line 114 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 187 of file xact.h.

◆ XACT_XINFO_HAS_DBINFO

#define XACT_XINFO_HAS_DBINFO   (1U << 0)

Definition at line 181 of file xact.h.

◆ XACT_XINFO_HAS_DROPPED_STATS

#define XACT_XINFO_HAS_DROPPED_STATS   (1U << 8)

Definition at line 189 of file xact.h.

◆ XACT_XINFO_HAS_GID

#define XACT_XINFO_HAS_GID   (1U << 7)

Definition at line 188 of file xact.h.

◆ XACT_XINFO_HAS_INVALS

#define XACT_XINFO_HAS_INVALS   (1U << 3)

Definition at line 184 of file xact.h.

◆ XACT_XINFO_HAS_ORIGIN

#define XACT_XINFO_HAS_ORIGIN   (1U << 5)

Definition at line 186 of file xact.h.

◆ XACT_XINFO_HAS_RELFILELOCATORS

#define XACT_XINFO_HAS_RELFILELOCATORS   (1U << 2)

Definition at line 183 of file xact.h.

◆ XACT_XINFO_HAS_SUBXACTS

#define XACT_XINFO_HAS_SUBXACTS   (1U << 1)

Definition at line 182 of file xact.h.

◆ XACT_XINFO_HAS_TWOPHASE

#define XACT_XINFO_HAS_TWOPHASE   (1U << 4)

Definition at line 185 of file xact.h.

◆ XactCompletionApplyFeedback

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

Definition at line 204 of file xact.h.

◆ XactCompletionForceSyncCommit

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

Definition at line 208 of file xact.h.

◆ XactCompletionRelcacheInitFileInval

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

Definition at line 206 of file xact.h.

◆ XLOG_XACT_ABORT

#define XLOG_XACT_ABORT   0x20

Definition at line 164 of file xact.h.

◆ XLOG_XACT_ABORT_PREPARED

#define XLOG_XACT_ABORT_PREPARED   0x40

Definition at line 166 of file xact.h.

◆ XLOG_XACT_ASSIGNMENT

#define XLOG_XACT_ASSIGNMENT   0x50

Definition at line 167 of file xact.h.

◆ XLOG_XACT_COMMIT

#define XLOG_XACT_COMMIT   0x00

Definition at line 162 of file xact.h.

◆ XLOG_XACT_COMMIT_PREPARED

#define XLOG_XACT_COMMIT_PREPARED   0x30

Definition at line 165 of file xact.h.

◆ XLOG_XACT_HAS_INFO

#define XLOG_XACT_HAS_INFO   0x80

Definition at line 175 of file xact.h.

◆ XLOG_XACT_INVALIDATIONS

#define XLOG_XACT_INVALIDATIONS   0x60

Definition at line 168 of file xact.h.

◆ XLOG_XACT_OPMASK

#define XLOG_XACT_OPMASK   0x70

Definition at line 172 of file xact.h.

◆ XLOG_XACT_PREPARE

#define XLOG_XACT_PREPARE   0x10

Definition at line 163 of file xact.h.

Typedef Documentation

◆ SavedTransactionCharacteristics

◆ SubXactCallback

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

Definition at line 141 of file xact.h.

◆ XactCallback

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

Definition at line 131 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 395 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 133 of file xact.h.

134 {
139 } SubXactEvent;
SubXactEvent
Definition: xact.h:134
@ SUBXACT_EVENT_PRE_COMMIT_SUB
Definition: xact.h:138
@ SUBXACT_EVENT_START_SUB
Definition: xact.h:135
@ SUBXACT_EVENT_ABORT_SUB
Definition: xact.h:137
@ SUBXACT_EVENT_COMMIT_SUB
Definition: xact.h:136

◆ SyncCommitLevel

Enumerator
SYNCHRONOUS_COMMIT_OFF 
SYNCHRONOUS_COMMIT_LOCAL_FLUSH 
SYNCHRONOUS_COMMIT_REMOTE_WRITE 
SYNCHRONOUS_COMMIT_REMOTE_FLUSH 
SYNCHRONOUS_COMMIT_REMOTE_APPLY 

Definition at line 68 of file xact.h.

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

◆ 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 119 of file xact.h.

120 {
129 } XactEvent;
XactEvent
Definition: xact.h:120
@ XACT_EVENT_PRE_PREPARE
Definition: xact.h:128
@ XACT_EVENT_COMMIT
Definition: xact.h:121
@ XACT_EVENT_PARALLEL_PRE_COMMIT
Definition: xact.h:127
@ XACT_EVENT_PARALLEL_COMMIT
Definition: xact.h:122
@ XACT_EVENT_ABORT
Definition: xact.h:123
@ XACT_EVENT_PRE_COMMIT
Definition: xact.h:126
@ XACT_EVENT_PARALLEL_ABORT
Definition: xact.h:124
@ XACT_EVENT_PREPARE
Definition: xact.h:125

Function Documentation

◆ AbortCurrentTransaction()

void AbortCurrentTransaction ( void  )

Definition at line 3293 of file xact.c.

3294 {
3296 
3297  switch (s->blockState)
3298  {
3299  case TBLOCK_DEFAULT:
3300  if (s->state == TRANS_DEFAULT)
3301  {
3302  /* we are idle, so nothing to do */
3303  }
3304  else
3305  {
3306  /*
3307  * We can get here after an error during transaction start
3308  * (state will be TRANS_START). Need to clean up the
3309  * incompletely started transaction. First, adjust the
3310  * low-level state to suppress warning message from
3311  * AbortTransaction.
3312  */
3313  if (s->state == TRANS_START)
3314  s->state = TRANS_INPROGRESS;
3315  AbortTransaction();
3317  }
3318  break;
3319 
3320  /*
3321  * If we aren't in a transaction block, we just do the basic abort
3322  * & cleanup transaction. For this purpose, we treat an implicit
3323  * transaction block as if it were a simple statement.
3324  */
3325  case TBLOCK_STARTED:
3327  AbortTransaction();
3330  break;
3331 
3332  /*
3333  * If we are in TBLOCK_BEGIN it means something screwed up right
3334  * after reading "BEGIN TRANSACTION". We assume that the user
3335  * will interpret the error as meaning the BEGIN failed to get him
3336  * into a transaction block, so we should abort and return to idle
3337  * state.
3338  */
3339  case TBLOCK_BEGIN:
3340  AbortTransaction();
3343  break;
3344 
3345  /*
3346  * We are somewhere in a transaction block and we've gotten a
3347  * failure, so we abort the transaction and set up the persistent
3348  * ABORT state. We will stay in ABORT until we get a ROLLBACK.
3349  */
3350  case TBLOCK_INPROGRESS:
3352  AbortTransaction();
3353  s->blockState = TBLOCK_ABORT;
3354  /* CleanupTransaction happens when we exit TBLOCK_ABORT_END */
3355  break;
3356 
3357  /*
3358  * Here, we failed while trying to COMMIT. Clean up the
3359  * transaction and return to idle state (we do not want to stay in
3360  * the transaction).
3361  */
3362  case TBLOCK_END:
3363  AbortTransaction();
3366  break;
3367 
3368  /*
3369  * Here, we are already in an aborted transaction state and are
3370  * waiting for a ROLLBACK, but for some reason we failed again! So
3371  * we just remain in the abort state.
3372  */
3373  case TBLOCK_ABORT:
3374  case TBLOCK_SUBABORT:
3375  break;
3376 
3377  /*
3378  * We are in a failed transaction and we got the ROLLBACK command.
3379  * We have already aborted, we just need to cleanup and go to idle
3380  * state.
3381  */
3382  case TBLOCK_ABORT_END:
3385  break;
3386 
3387  /*
3388  * We are in a live transaction and we got a ROLLBACK command.
3389  * Abort, cleanup, go to idle state.
3390  */
3391  case TBLOCK_ABORT_PENDING:
3392  AbortTransaction();
3395  break;
3396 
3397  /*
3398  * Here, we failed while trying to PREPARE. Clean up the
3399  * transaction and return to idle state (we do not want to stay in
3400  * the transaction).
3401  */
3402  case TBLOCK_PREPARE:
3403  AbortTransaction();
3406  break;
3407 
3408  /*
3409  * We got an error inside a subtransaction. Abort just the
3410  * subtransaction, and go to the persistent SUBABORT state until
3411  * we get ROLLBACK.
3412  */
3413  case TBLOCK_SUBINPROGRESS:
3416  break;
3417 
3418  /*
3419  * If we failed while trying to create a subtransaction, clean up
3420  * the broken subtransaction and abort the parent. The same
3421  * applies if we get a failure while ending a subtransaction.
3422  */
3423  case TBLOCK_SUBBEGIN:
3424  case TBLOCK_SUBRELEASE:
3425  case TBLOCK_SUBCOMMIT:
3427  case TBLOCK_SUBRESTART:
3431  break;
3432 
3433  /*
3434  * Same as above, except the Abort() was already done.
3435  */
3436  case TBLOCK_SUBABORT_END:
3440  break;
3441  }
3442 }
TransState state
Definition: xact.c:194
TBlockState blockState
Definition: xact.c:195
static void CleanupSubTransaction(void)
Definition: xact.c:5197
static void CleanupTransaction(void)
Definition: xact.c:2876
@ TRANS_INPROGRESS
Definition: xact.c:144
@ TRANS_START
Definition: xact.c:143
@ TRANS_DEFAULT
Definition: xact.c:142
static void AbortSubTransaction(void)
Definition: xact.c:5038
@ TBLOCK_DEFAULT
Definition: xact.c:159
@ TBLOCK_SUBABORT_END
Definition: xact.c:179
@ TBLOCK_STARTED
Definition: xact.c:160
@ TBLOCK_SUBCOMMIT
Definition: xact.c:177
@ TBLOCK_IMPLICIT_INPROGRESS
Definition: xact.c:165
@ TBLOCK_ABORT_END
Definition: xact.c:169
@ TBLOCK_PREPARE
Definition: xact.c:171
@ TBLOCK_ABORT_PENDING
Definition: xact.c:170
@ TBLOCK_ABORT
Definition: xact.c:168
@ TBLOCK_SUBRELEASE
Definition: xact.c:176
@ TBLOCK_SUBBEGIN
Definition: xact.c:174
@ TBLOCK_SUBABORT
Definition: xact.c:178
@ TBLOCK_SUBRESTART
Definition: xact.c:181
@ TBLOCK_INPROGRESS
Definition: xact.c:164
@ TBLOCK_END
Definition: xact.c:167
@ TBLOCK_PARALLEL_INPROGRESS
Definition: xact.c:166
@ TBLOCK_SUBABORT_RESTART
Definition: xact.c:182
@ TBLOCK_SUBABORT_PENDING
Definition: xact.c:180
@ TBLOCK_BEGIN
Definition: xact.c:163
@ TBLOCK_SUBINPROGRESS
Definition: xact.c:175
static void AbortTransaction(void)
Definition: xact.c:2685
static TransactionState CurrentTransactionState
Definition: xact.c:253
void AbortCurrentTransaction(void)
Definition: xact.c:3293

References AbortSubTransaction(), AbortTransaction(), TransactionStateData::blockState, CleanupSubTransaction(), CleanupTransaction(), CurrentTransactionState, TransactionStateData::state, 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, TRANS_DEFAULT, TRANS_INPROGRESS, and TRANS_START.

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

◆ AbortOutOfAnyTransaction()

void AbortOutOfAnyTransaction ( void  )

Definition at line 4692 of file xact.c.

4693 {
4695 
4696  /* Ensure we're not running in a doomed memory context */
4697  AtAbort_Memory();
4698 
4699  /*
4700  * Get out of any transaction or nested transaction
4701  */
4702  do
4703  {
4704  switch (s->blockState)
4705  {
4706  case TBLOCK_DEFAULT:
4707  if (s->state == TRANS_DEFAULT)
4708  {
4709  /* Not in a transaction, do nothing */
4710  }
4711  else
4712  {
4713  /*
4714  * We can get here after an error during transaction start
4715  * (state will be TRANS_START). Need to clean up the
4716  * incompletely started transaction. First, adjust the
4717  * low-level state to suppress warning message from
4718  * AbortTransaction.
4719  */
4720  if (s->state == TRANS_START)
4721  s->state = TRANS_INPROGRESS;
4722  AbortTransaction();
4724  }
4725  break;
4726  case TBLOCK_STARTED:
4727  case TBLOCK_BEGIN:
4728  case TBLOCK_INPROGRESS:
4731  case TBLOCK_END:
4732  case TBLOCK_ABORT_PENDING:
4733  case TBLOCK_PREPARE:
4734  /* In a transaction, so clean up */
4735  AbortTransaction();
4738  break;
4739  case TBLOCK_ABORT:
4740  case TBLOCK_ABORT_END:
4741 
4742  /*
4743  * AbortTransaction is already done, still need Cleanup.
4744  * However, if we failed partway through running ROLLBACK,
4745  * there will be an active portal running that command, which
4746  * we need to shut down before doing CleanupTransaction.
4747  */
4748  AtAbort_Portals();
4751  break;
4752 
4753  /*
4754  * In a subtransaction, so clean it up and abort parent too
4755  */
4756  case TBLOCK_SUBBEGIN:
4757  case TBLOCK_SUBINPROGRESS:
4758  case TBLOCK_SUBRELEASE:
4759  case TBLOCK_SUBCOMMIT:
4761  case TBLOCK_SUBRESTART:
4764  s = CurrentTransactionState; /* changed by pop */
4765  break;
4766 
4767  case TBLOCK_SUBABORT:
4768  case TBLOCK_SUBABORT_END:
4770  /* As above, but AbortSubTransaction already done */
4771  if (s->curTransactionOwner)
4772  {
4773  /* As in TBLOCK_ABORT, might have a live portal to zap */
4778  }
4780  s = CurrentTransactionState; /* changed by pop */
4781  break;
4782  }
4783  } while (s->blockState != TBLOCK_DEFAULT);
4784 
4785  /* Should be out of all subxacts now */
4786  Assert(s->parent == NULL);
4787 
4788  /* If we didn't actually have anything to do, revert to TopMemoryContext */
4789  AtCleanup_Memory();
4790 }
Assert(fmt[strlen(fmt) - 1] !='\n')
void AtAbort_Portals(void)
Definition: portalmem.c:782
void AtSubAbort_Portals(SubTransactionId mySubid, SubTransactionId parentSubid, ResourceOwner myXactOwner, ResourceOwner parentXactOwner)
Definition: portalmem.c:980
SubTransactionId subTransactionId
Definition: xact.c:191
struct TransactionStateData * parent
Definition: xact.c:211
ResourceOwner curTransactionOwner
Definition: xact.c:199
static void AtCleanup_Memory(void)
Definition: xact.c:1911
static void AtAbort_Memory(void)
Definition: xact.c:1821

References AbortSubTransaction(), AbortTransaction(), Assert(), AtAbort_Memory(), AtAbort_Portals(), AtCleanup_Memory(), AtSubAbort_Portals(), TransactionStateData::blockState, CleanupSubTransaction(), CleanupTransaction(), CurrentTransactionState, TransactionStateData::curTransactionOwner, 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, 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 4152 of file xact.c.

4153 {
4155 
4156  /*
4157  * If we are in STARTED state (that is, no transaction block is open),
4158  * switch to IMPLICIT_INPROGRESS state, creating an implicit transaction
4159  * block.
4160  *
4161  * For caller convenience, we consider all other transaction states as
4162  * legal here; otherwise the caller would need its own state check, which
4163  * seems rather pointless.
4164  */
4165  if (s->blockState == TBLOCK_STARTED)
4167 }

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

Referenced by exec_simple_query().

◆ BeginInternalSubTransaction()

void BeginInternalSubTransaction ( const char *  name)

Definition at line 4520 of file xact.c.

4521 {
4523 
4524  /*
4525  * Workers synchronize transaction state at the beginning of each parallel
4526  * operation, so we can't account for new subtransactions after that
4527  * point. We might be able to make an exception for the type of
4528  * subtransaction established by this function, which is typically used in
4529  * contexts where we're going to release or roll back the subtransaction
4530  * before proceeding further, so that no enduring change to the
4531  * transaction state occurs. For now, however, we prohibit this case along
4532  * with all the others.
4533  */
4534  if (IsInParallelMode())
4535  ereport(ERROR,
4536  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4537  errmsg("cannot start subtransactions during a parallel operation")));
4538 
4539  switch (s->blockState)
4540  {
4541  case TBLOCK_STARTED:
4542  case TBLOCK_INPROGRESS:
4544  case TBLOCK_END:
4545  case TBLOCK_PREPARE:
4546  case TBLOCK_SUBINPROGRESS:
4547  /* Normal subtransaction start */
4548  PushTransaction();
4549  s = CurrentTransactionState; /* changed by push */
4550 
4551  /*
4552  * Savepoint names, like the TransactionState block itself, live
4553  * in TopTransactionContext.
4554  */
4555  if (name)
4557  break;
4558 
4559  /* These cases are invalid. */
4560  case TBLOCK_DEFAULT:
4561  case TBLOCK_BEGIN:
4563  case TBLOCK_SUBBEGIN:
4564  case TBLOCK_SUBRELEASE:
4565  case TBLOCK_SUBCOMMIT:
4566  case TBLOCK_ABORT:
4567  case TBLOCK_SUBABORT:
4568  case TBLOCK_ABORT_END:
4569  case TBLOCK_SUBABORT_END:
4570  case TBLOCK_ABORT_PENDING:
4572  case TBLOCK_SUBRESTART:
4574  elog(FATAL, "BeginInternalSubTransaction: unexpected state %s",
4576  break;
4577  }
4578 
4581 }
int errcode(int sqlerrcode)
Definition: elog.c:695
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define FATAL
Definition: elog.h:37
#define ERROR
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:145
const char * name
Definition: encode.c:561
MemoryContext TopTransactionContext
Definition: mcxt.c:135
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1470
static void PushTransaction(void)
Definition: xact.c:5230
void StartTransactionCommand(void)
Definition: xact.c:2925
bool IsInParallelMode(void)
Definition: xact.c:1068
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5510
void CommitTransactionCommand(void)
Definition: xact.c:3022

References TransactionStateData::blockState, BlockStateAsString(), CommitTransactionCommand(), CurrentTransactionState, elog(), ereport, errcode(), errmsg(), ERROR, FATAL, IsInParallelMode(), 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 3750 of file xact.c.

3751 {
3753 
3754  switch (s->blockState)
3755  {
3756  /*
3757  * We are not inside a transaction block, so allow one to begin.
3758  */
3759  case TBLOCK_STARTED:
3760  s->blockState = TBLOCK_BEGIN;
3761  break;
3762 
3763  /*
3764  * BEGIN converts an implicit transaction block to a regular one.
3765  * (Note that we allow this even if we've already done some
3766  * commands, which is a bit odd but matches historical practice.)
3767  */
3769  s->blockState = TBLOCK_BEGIN;
3770  break;
3771 
3772  /*
3773  * Already a transaction block in progress.
3774  */
3775  case TBLOCK_INPROGRESS:
3777  case TBLOCK_SUBINPROGRESS:
3778  case TBLOCK_ABORT:
3779  case TBLOCK_SUBABORT:
3780  ereport(WARNING,
3781  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3782  errmsg("there is already a transaction in progress")));
3783  break;
3784 
3785  /* These cases are invalid. */
3786  case TBLOCK_DEFAULT:
3787  case TBLOCK_BEGIN:
3788  case TBLOCK_SUBBEGIN:
3789  case TBLOCK_END:
3790  case TBLOCK_SUBRELEASE:
3791  case TBLOCK_SUBCOMMIT:
3792  case TBLOCK_ABORT_END:
3793  case TBLOCK_SUBABORT_END:
3794  case TBLOCK_ABORT_PENDING:
3796  case TBLOCK_SUBRESTART:
3798  case TBLOCK_PREPARE:
3799  elog(FATAL, "BeginTransactionBlock: unexpected state %s",
3801  break;
3802  }
3803 }
#define WARNING
Definition: elog.h:32

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(), and standard_ProcessUtility().

◆ CommandCounterIncrement()

void CommandCounterIncrement ( void  )

Definition at line 1077 of file xact.c.

1078 {
1079  /*
1080  * If the current value of the command counter hasn't been "used" to mark
1081  * tuples, we need not increment it, since there's no need to distinguish
1082  * a read-only command from others. This helps postpone command counter
1083  * overflow, and keeps no-op CommandCounterIncrement operations cheap.
1084  */
1086  {
1087  /*
1088  * Workers synchronize transaction state at the beginning of each
1089  * parallel operation, so we can't account for new commands after that
1090  * point.
1091  */
1093  elog(ERROR, "cannot start commands during a parallel operation");
1094 
1095  currentCommandId += 1;
1097  {
1098  currentCommandId -= 1;
1099  ereport(ERROR,
1100  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1101  errmsg("cannot have more than 2^32-2 commands in a transaction")));
1102  }
1103  currentCommandIdUsed = false;
1104 
1105  /* Propagate new command ID into static snapshots */
1107 
1108  /*
1109  * Make any catalog changes done by the just-completed command visible
1110  * in the local syscache. We obviously don't need to do this after a
1111  * read-only command. (But see hacks in inval.c to make real sure we
1112  * don't think a command that queued inval messages was read-only.)
1113  */
1114  AtCCI_LocalCache();
1115  }
1116 }
#define InvalidCommandId
Definition: c.h:605
#define IsParallelWorker()
Definition: parallel.h:61
void SnapshotSetCommandId(CommandId curcid)
Definition: snapmgr.c:491
static bool currentCommandIdUsed
Definition: xact.c:261
static CommandId currentCommandId
Definition: xact.c:260
static void AtCCI_LocalCache(void)
Definition: xact.c:1539

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

Referenced by _SPI_execute_plan(), acquire_inherited_sample_rows(), addFkRecurseReferenced(), addFkRecurseReferencing(), AddRoleMems(), AlterPublicationOptions(), AlterRole(), ATAddCheckConstraint(), ATExecAddColumn(), ATExecAlterColumnType(), ATExecCmd(), ATExecDropColumn(), ATExecDropConstraint(), ATExecDropExpression(), ATExecDropIdentity(), ATExecSetCompression(), ATExecSetTableSpace(), ATExecSetTableSpaceNoStorage(), ATParseTransformCmd(), ATRewriteTables(), AttachPartitionEnsureIndexes(), btadjustmembers(), CloneFkReferencing(), CommitSubTransaction(), CommitTransactionCommand(), copy_table_data(), create_ctas_internal(), create_toast_table(), CreateFKCheckTrigger(), createForeignKeyActionTriggers(), CreateForeignTable(), CreatePublication(), CreateRole(), CreateSchemaCommand(), CreateTriggerFiringOn(), DefineCollation(), DefineDomain(), DefineRelation(), DefineVirtualRelation(), deleteOneObject(), DetachPartitionFinalize(), DropClonedTriggersFromPartition(), DropRole(), end_replication_step(), EventTriggerDDLCommandEnd(), EventTriggerDDLCommandStart(), EventTriggerInvoke(), EventTriggerSQLDrop(), EventTriggerTableRewrite(), exec_eval_simple_expr(), exec_execute_message(), exec_parse_message(), exec_simple_query(), ExecGrant_Database(), ExecGrant_Fdw(), ExecGrant_ForeignServer(), ExecGrant_Function(), ExecGrant_Language(), ExecGrant_Largeobject(), ExecGrant_Namespace(), ExecGrant_Parameter(), ExecGrant_Relation(), ExecGrant_Tablespace(), ExecGrant_Type(), 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(), ProcessUtilitySlow(), recordExtensionInitPrivWorker(), reindex_index(), reindex_relation(), ReindexRelationConcurrently(), RelationSetNewRelfilenumber(), RemoveRoleFromObjectPolicy(), RenumberEnumType(), replorigin_create(), replorigin_drop_guts(), ri_PerformCheck(), SetDefaultACL(), SetMatViewPopulatedState(), shdepReassignOwned(), SPI_cursor_open_internal(), standard_ProcessUtility(), StoreConstraints(), StorePartitionBound(), tryAttachPartitionForeignKey(), vacuum(), and validatePartitionedIndex().

◆ CommitTransactionCommand()

void CommitTransactionCommand ( void  )

Definition at line 3022 of file xact.c.

3023 {
3026 
3028 
3029  switch (s->blockState)
3030  {
3031  /*
3032  * These shouldn't happen. TBLOCK_DEFAULT means the previous
3033  * StartTransactionCommand didn't set the STARTED state
3034  * appropriately, while TBLOCK_PARALLEL_INPROGRESS should be ended
3035  * by EndParallelWorkerTransaction(), not this function.
3036  */
3037  case TBLOCK_DEFAULT:
3039  elog(FATAL, "CommitTransactionCommand: unexpected state %s",
3041  break;
3042 
3043  /*
3044  * If we aren't in a transaction block, just do our usual
3045  * transaction commit, and return to the idle state.
3046  */
3047  case TBLOCK_STARTED:
3050  break;
3051 
3052  /*
3053  * We are completing a "BEGIN TRANSACTION" command, so we change
3054  * to the "transaction block in progress" state and return. (We
3055  * assume the BEGIN did nothing to the database, so we need no
3056  * CommandCounterIncrement.)
3057  */
3058  case TBLOCK_BEGIN:
3060  break;
3061 
3062  /*
3063  * This is the case when we have finished executing a command
3064  * someplace within a transaction block. We increment the command
3065  * counter and return.
3066  */
3067  case TBLOCK_INPROGRESS:
3069  case TBLOCK_SUBINPROGRESS:
3071  break;
3072 
3073  /*
3074  * We are completing a "COMMIT" command. Do it and return to the
3075  * idle state.
3076  */
3077  case TBLOCK_END:
3080  if (s->chain)
3081  {
3082  StartTransaction();
3084  s->chain = false;
3086  }
3087  break;
3088 
3089  /*
3090  * Here we are in the middle of a transaction block but one of the
3091  * commands caused an abort so we do nothing but remain in the
3092  * abort state. Eventually we will get a ROLLBACK command.
3093  */
3094  case TBLOCK_ABORT:
3095  case TBLOCK_SUBABORT:
3096  break;
3097 
3098  /*
3099  * Here we were in an aborted transaction block and we just got
3100  * the ROLLBACK command from the user, so clean up the
3101  * already-aborted transaction and return to the idle state.
3102  */
3103  case TBLOCK_ABORT_END:
3106  if (s->chain)
3107  {
3108  StartTransaction();
3110  s->chain = false;
3112  }
3113  break;
3114 
3115  /*
3116  * Here we were in a perfectly good transaction block but the user
3117  * told us to ROLLBACK anyway. We have to abort the transaction
3118  * and then clean up.
3119  */
3120  case TBLOCK_ABORT_PENDING:
3121  AbortTransaction();
3124  if (s->chain)
3125  {
3126  StartTransaction();
3128  s->chain = false;
3130  }
3131  break;
3132 
3133  /*
3134  * We are completing a "PREPARE TRANSACTION" command. Do it and
3135  * return to the idle state.
3136  */
3137  case TBLOCK_PREPARE:
3140  break;
3141 
3142  /*
3143  * The user issued a SAVEPOINT inside a transaction block.
3144  * Start a subtransaction. (DefineSavepoint already did
3145  * PushTransaction, so as to have someplace to put the SUBBEGIN
3146  * state.)
3147  */
3148  case TBLOCK_SUBBEGIN:
3151  break;
3152 
3153  /*
3154  * The user issued a RELEASE command, so we end the current
3155  * subtransaction and return to the parent transaction. The parent
3156  * might be ended too, so repeat till we find an INPROGRESS
3157  * transaction or subtransaction.
3158  */
3159  case TBLOCK_SUBRELEASE:
3160  do
3161  {
3163  s = CurrentTransactionState; /* changed by pop */
3164  } while (s->blockState == TBLOCK_SUBRELEASE);
3165 
3168  break;
3169 
3170  /*
3171  * The user issued a COMMIT, so we end the current subtransaction
3172  * hierarchy and perform final commit. We do this by rolling up
3173  * any subtransactions into their parent, which leads to O(N^2)
3174  * operations with respect to resource owners - this isn't that
3175  * bad until we approach a thousands of savepoints but is
3176  * necessary for correctness should after triggers create new
3177  * resource owners.
3178  */
3179  case TBLOCK_SUBCOMMIT:
3180  do
3181  {
3183  s = CurrentTransactionState; /* changed by pop */
3184  } while (s->blockState == TBLOCK_SUBCOMMIT);
3185  /* If we had a COMMIT command, finish off the main xact too */
3186  if (s->blockState == TBLOCK_END)
3187  {
3188  Assert(s->parent == NULL);
3191  if (s->chain)
3192  {
3193  StartTransaction();
3195  s->chain = false;
3197  }
3198  }
3199  else if (s->blockState == TBLOCK_PREPARE)
3200  {
3201  Assert(s->parent == NULL);
3204  }
3205  else
3206  elog(ERROR, "CommitTransactionCommand: unexpected state %s",
3208  break;
3209 
3210  /*
3211  * The current already-failed subtransaction is ending due to a
3212  * ROLLBACK or ROLLBACK TO command, so pop it and recursively
3213  * examine the parent (which could be in any of several states).
3214  */
3215  case TBLOCK_SUBABORT_END:
3218  break;
3219 
3220  /*
3221  * As above, but it's not dead yet, so abort first.
3222  */
3227  break;
3228 
3229  /*
3230  * The current subtransaction is the target of a ROLLBACK TO
3231  * command. Abort and pop it, then start a new subtransaction
3232  * with the same name.
3233  */
3234  case TBLOCK_SUBRESTART:
3235  {
3236  char *name;
3237  int savepointLevel;
3238 
3239  /* save name and keep Cleanup from freeing it */
3240  name = s->name;
3241  s->name = NULL;
3242  savepointLevel = s->savepointLevel;
3243 
3246 
3247  DefineSavepoint(NULL);
3248  s = CurrentTransactionState; /* changed by push */
3249  s->name = name;
3250  s->savepointLevel = savepointLevel;
3251 
3252  /* This is the same as TBLOCK_SUBBEGIN case */
3256  }
3257  break;
3258 
3259  /*
3260  * Same as above, but the subtransaction had already failed, so we
3261  * don't need AbortSubTransaction.
3262  */
3264  {
3265  char *name;
3266  int savepointLevel;
3267 
3268  /* save name and keep Cleanup from freeing it */
3269  name = s->name;
3270  s->name = NULL;
3271  savepointLevel = s->savepointLevel;
3272 
3274 
3275  DefineSavepoint(NULL);
3276  s = CurrentTransactionState; /* changed by push */
3277  s->name = name;
3278  s->savepointLevel = savepointLevel;
3279 
3280  /* This is the same as TBLOCK_SUBBEGIN case */
3284  }
3285  break;
3286  }
3287 }
void SaveTransactionCharacteristics(SavedTransactionCharacteristics *s)
Definition: xact.c:3002
void RestoreTransactionCharacteristics(const SavedTransactionCharacteristics *s)
Definition: xact.c:3010
static void StartTransaction(void)
Definition: xact.c:1982
void DefineSavepoint(const char *name)
Definition: xact.c:4199
static void CommitSubTransaction(void)
Definition: xact.c:4929
void CommandCounterIncrement(void)
Definition: xact.c:1077
static void CommitTransaction(void)
Definition: xact.c:2141
static void PrepareTransaction(void)
Definition: xact.c:2400
static void StartSubTransaction(void)
Definition: xact.c:4892

References AbortSubTransaction(), AbortTransaction(), Assert(), TransactionStateData::blockState, BlockStateAsString(), TransactionStateData::chain, CleanupSubTransaction(), CleanupTransaction(), CommandCounterIncrement(), CommitSubTransaction(), CommitTransaction(), CurrentTransactionState, DefineSavepoint(), elog(), ERROR, FATAL, TransactionStateData::name, name, TransactionStateData::parent, PrepareTransaction(), RestoreTransactionCharacteristics(), TransactionStateData::savepointLevel, SaveTransactionCharacteristics(), StartSubTransaction(), 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(), AllTablesyncsReady(), apply_handle_commit_internal(), apply_handle_commit_prepared(), apply_handle_prepare(), apply_handle_prepare_internal(), apply_handle_rollback_prepared(), apply_handle_stream_abort(), apply_handle_stream_prepare(), apply_handle_stream_stop(), ApplyWorkerMain(), ATExecDetachPartition(), autoprewarm_database_main(), bbsink_server_new(), BeginInternalSubTransaction(), BootstrapModeMain(), clear_subscription_skip_lsn(), cluster_multiple_rels(), DefineIndex(), DisableSubscriptionAndExit(), do_autovacuum(), exec_replication_command(), finish_xact_command(), get_database_list(), get_subscription_list(), IdentifySystem(), index_drop(), initialize_worker_spi(), InitPostgres(), LogicalRepSyncTableStart(), maybe_reread_subscription(), movedb(), ParallelWorkerMain(), pg_attribute_noreturn(), process_syncing_tables_for_apply(), process_syncing_tables_for_sync(), ProcessCatchupInterrupt(), ProcessIncomingNotify(), ReindexMultipleInternal(), ReindexRelationConcurrently(), RemoveTempRelationsCallback(), shell_check_detail(), vacuum(), and vacuum_rel().

◆ DefineSavepoint()

void DefineSavepoint ( const char *  name)

Definition at line 4199 of file xact.c.

4200 {
4202 
4203  /*
4204  * Workers synchronize transaction state at the beginning of each parallel
4205  * operation, so we can't account for new subtransactions after that
4206  * point. (Note that this check will certainly error out if s->blockState
4207  * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4208  * below.)
4209  */
4210  if (IsInParallelMode())
4211  ereport(ERROR,
4212  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4213  errmsg("cannot define savepoints during a parallel operation")));
4214 
4215  switch (s->blockState)
4216  {
4217  case TBLOCK_INPROGRESS:
4218  case TBLOCK_SUBINPROGRESS:
4219  /* Normal subtransaction start */
4220  PushTransaction();
4221  s = CurrentTransactionState; /* changed by push */
4222 
4223  /*
4224  * Savepoint names, like the TransactionState block itself, live
4225  * in TopTransactionContext.
4226  */
4227  if (name)
4229  break;
4230 
4231  /*
4232  * We disallow savepoint commands in implicit transaction blocks.
4233  * There would be no great difficulty in allowing them so far as
4234  * this module is concerned, but a savepoint seems inconsistent
4235  * with exec_simple_query's behavior of abandoning the whole query
4236  * string upon error. Also, the point of an implicit transaction
4237  * block (as opposed to a regular one) is to automatically close
4238  * after an error, so it's hard to see how a savepoint would fit
4239  * into that.
4240  *
4241  * The error messages for this are phrased as if there were no
4242  * active transaction block at all, which is historical but
4243  * perhaps could be improved.
4244  */
4246  ereport(ERROR,
4247  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4248  /* translator: %s represents an SQL statement name */
4249  errmsg("%s can only be used in transaction blocks",
4250  "SAVEPOINT")));
4251  break;
4252 
4253  /* These cases are invalid. */
4254  case TBLOCK_DEFAULT:
4255  case TBLOCK_STARTED:
4256  case TBLOCK_BEGIN:
4258  case TBLOCK_SUBBEGIN:
4259  case TBLOCK_END:
4260  case TBLOCK_SUBRELEASE:
4261  case TBLOCK_SUBCOMMIT:
4262  case TBLOCK_ABORT:
4263  case TBLOCK_SUBABORT:
4264  case TBLOCK_ABORT_END:
4265  case TBLOCK_SUBABORT_END:
4266  case TBLOCK_ABORT_PENDING:
4268  case TBLOCK_SUBRESTART:
4270  case TBLOCK_PREPARE:
4271  elog(FATAL, "DefineSavepoint: unexpected state %s",
4273  break;
4274  }
4275 }

References TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog(), ereport, errcode(), errmsg(), ERROR, FATAL, IsInParallelMode(), 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 CommitTransactionCommand(), and standard_ProcessUtility().

◆ EndImplicitTransactionBlock()

void EndImplicitTransactionBlock ( void  )

Definition at line 4177 of file xact.c.

4178 {
4180 
4181  /*
4182  * If we are in IMPLICIT_INPROGRESS state, switch back to STARTED state,
4183  * allowing CommitTransactionCommand to commit whatever happened during
4184  * the implicit transaction block as though it were a single statement.
4185  *
4186  * For caller convenience, we consider all other transaction states as
4187  * legal here; otherwise the caller would need its own state check, which
4188  * seems rather pointless.
4189  */
4192 }

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

Referenced by exec_simple_query().

◆ EndParallelWorkerTransaction()

◆ EndTransactionBlock()

bool EndTransactionBlock ( bool  chain)

Definition at line 3870 of file xact.c.

3871 {
3873  bool result = false;
3874 
3875  switch (s->blockState)
3876  {
3877  /*
3878  * We are in a transaction block, so tell CommitTransactionCommand
3879  * to COMMIT.
3880  */
3881  case TBLOCK_INPROGRESS:
3882  s->blockState = TBLOCK_END;
3883  result = true;
3884  break;
3885 
3886  /*
3887  * We are in an implicit transaction block. If AND CHAIN was
3888  * specified, error. Otherwise commit, but issue a warning
3889  * because there was no explicit BEGIN before this.
3890  */
3892  if (chain)
3893  ereport(ERROR,
3894  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
3895  /* translator: %s represents an SQL statement name */
3896  errmsg("%s can only be used in transaction blocks",
3897  "COMMIT AND CHAIN")));
3898  else
3899  ereport(WARNING,
3900  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
3901  errmsg("there is no transaction in progress")));
3902  s->blockState = TBLOCK_END;
3903  result = true;
3904  break;
3905 
3906  /*
3907  * We are in a failed transaction block. Tell
3908  * CommitTransactionCommand it's time to exit the block.
3909  */
3910  case TBLOCK_ABORT:
3912  break;
3913 
3914  /*
3915  * We are in a live subtransaction block. Set up to subcommit all
3916  * open subtransactions and then commit the main transaction.
3917  */
3918  case TBLOCK_SUBINPROGRESS:
3919  while (s->parent != NULL)
3920  {
3921  if (s->blockState == TBLOCK_SUBINPROGRESS)
3923  else
3924  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3926  s = s->parent;
3927  }
3928  if (s->blockState == TBLOCK_INPROGRESS)
3929  s->blockState = TBLOCK_END;
3930  else
3931  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3933  result = true;
3934  break;
3935 
3936  /*
3937  * Here we are inside an aborted subtransaction. Treat the COMMIT
3938  * as ROLLBACK: set up to abort everything and exit the main
3939  * transaction.
3940  */
3941  case TBLOCK_SUBABORT:
3942  while (s->parent != NULL)
3943  {
3944  if (s->blockState == TBLOCK_SUBINPROGRESS)
3946  else if (s->blockState == TBLOCK_SUBABORT)
3948  else
3949  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3951  s = s->parent;
3952  }
3953  if (s->blockState == TBLOCK_INPROGRESS)
3955  else if (s->blockState == TBLOCK_ABORT)
3957  else
3958  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3960  break;
3961 
3962  /*
3963  * The user issued COMMIT when not inside a transaction. For
3964  * COMMIT without CHAIN, issue a WARNING, staying in
3965  * TBLOCK_STARTED state. The upcoming call to
3966  * CommitTransactionCommand() will then close the transaction and
3967  * put us back into the default state. For COMMIT AND CHAIN,
3968  * error.
3969  */
3970  case TBLOCK_STARTED:
3971  if (chain)
3972  ereport(ERROR,
3973  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
3974  /* translator: %s represents an SQL statement name */
3975  errmsg("%s can only be used in transaction blocks",
3976  "COMMIT AND CHAIN")));
3977  else
3978  ereport(WARNING,
3979  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
3980  errmsg("there is no transaction in progress")));
3981  result = true;
3982  break;
3983 
3984  /*
3985  * The user issued a COMMIT that somehow ran inside a parallel
3986  * worker. We can't cope with that.
3987  */
3989  ereport(FATAL,
3990  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
3991  errmsg("cannot commit during a parallel operation")));
3992  break;
3993 
3994  /* These cases are invalid. */
3995  case TBLOCK_DEFAULT:
3996  case TBLOCK_BEGIN:
3997  case TBLOCK_SUBBEGIN:
3998  case TBLOCK_END:
3999  case TBLOCK_SUBRELEASE:
4000  case TBLOCK_SUBCOMMIT:
4001  case TBLOCK_ABORT_END:
4002  case TBLOCK_SUBABORT_END:
4003  case TBLOCK_ABORT_PENDING:
4005  case TBLOCK_SUBRESTART:
4007  case TBLOCK_PREPARE:
4008  elog(FATAL, "EndTransactionBlock: unexpected state %s",
4010  break;
4011  }
4012 
4014  s->blockState == TBLOCK_END ||
4015  s->blockState == TBLOCK_ABORT_END ||
4017 
4018  s->chain = chain;
4019 
4020  return result;
4021 }

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 PrepareTransactionBlock(), and standard_ProcessUtility().

◆ EnterParallelMode()

void EnterParallelMode ( void  )

◆ EstimateTransactionStateSpace()

Size EstimateTransactionStateSpace ( void  )

Definition at line 5324 of file xact.c.

5325 {
5326  TransactionState s;
5327  Size nxids = 0;
5329 
5330  for (s = CurrentTransactionState; s != NULL; s = s->parent)
5331  {
5333  nxids = add_size(nxids, 1);
5334  nxids = add_size(nxids, s->nChildXids);
5335  }
5336 
5337  return add_size(size, mul_size(sizeof(TransactionId), nxids));
5338 }
uint32 TransactionId
Definition: c.h:588
size_t Size
Definition: c.h:541
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
Size mul_size(Size s1, Size s2)
Definition: shmem.c:519
FullTransactionId fullTransactionId
Definition: xact.c:190
#define FullTransactionIdIsValid(x)
Definition: transam.h:55
#define SerializedTransactionStateHeaderSize
Definition: xact.c:232

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

Referenced by InitializeParallelDSM().

◆ ExitParallelMode()

void ExitParallelMode ( void  )

◆ ForceSyncCommit()

void ForceSyncCommit ( void  )

Definition at line 1127 of file xact.c.

1128 {
1129  forceSyncCommit = true;
1130 }
static bool forceSyncCommit
Definition: xact.c:286

References forceSyncCommit.

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

◆ GetCurrentCommandId()

CommandId GetCurrentCommandId ( bool  used)

Definition at line 817 of file xact.c.

818 {
819  /* this is global to a transaction, not subtransaction-local */
820  if (used)
821  {
822  /*
823  * Forbid setting currentCommandIdUsed in a parallel worker, because
824  * we have no provision for communicating this back to the leader. We
825  * could relax this restriction when currentCommandIdUsed was already
826  * true at the start of the parallel operation.
827  */
829  currentCommandIdUsed = true;
830  }
831  return currentCommandId;
832 }

References Assert(), currentCommandId, currentCommandIdUsed, and IsParallelWorker.

Referenced by ATRewriteTable(), CatalogTuplesMultiInsertWithInfo(), CopyFrom(), create_edata_for_relation(), create_estate_for_relation(), GetSnapshotData(), GetSnapshotDataReuse(), 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 502 of file xact.c.

503 {
505 
508  return s->fullTransactionId;
509 }
static void AssignTransactionId(TransactionState s)
Definition: xact.c:625

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

◆ GetCurrentFullTransactionIdIfAny()

FullTransactionId GetCurrentFullTransactionIdIfAny ( void  )

Definition at line 520 of file xact.c.

521 {
523 }

References CurrentTransactionState, and TransactionStateData::fullTransactionId.

◆ GetCurrentStatementStartTimestamp()

TimestampTz GetCurrentStatementStartTimestamp ( void  )

Definition at line 863 of file xact.c.

864 {
865  return stmtStartTimestamp;
866 }
static TimestampTz stmtStartTimestamp
Definition: xact.c:274

References stmtStartTimestamp.

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

◆ GetCurrentSubTransactionId()

◆ GetCurrentTransactionId()

◆ GetCurrentTransactionIdIfAny()

◆ GetCurrentTransactionNestLevel()

◆ GetCurrentTransactionStartTimestamp()

TimestampTz GetCurrentTransactionStartTimestamp ( void  )

Definition at line 854 of file xact.c.

855 {
856  return xactStartTimestamp;
857 }
static TimestampTz xactStartTimestamp
Definition: xact.c:273

References xactStartTimestamp.

Referenced by current_timestamp(), GetCurrentTimeUsec(), InitializeParallelDSM(), now(), pg_timezone_abbrevs(), sql_localtimestamp(), and timetz_zone().

◆ GetCurrentTransactionStopTimestamp()

TimestampTz GetCurrentTransactionStopTimestamp ( void  )

Definition at line 875 of file xact.c.

876 {
878 
879  /* should only be called after commit / abort processing */
880  Assert(s->state == TRANS_DEFAULT ||
881  s->state == TRANS_COMMIT ||
882  s->state == TRANS_ABORT ||
883  s->state == TRANS_PREPARE);
884 
885  if (xactStopTimestamp == 0)
887 
888  return xactStopTimestamp;
889 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1573
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:166
static TimestampTz xactStopTimestamp
Definition: xact.c:275
@ TRANS_COMMIT
Definition: xact.c:145
@ TRANS_ABORT
Definition: xact.c:146
@ TRANS_PREPARE
Definition: xact.c:147

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 597 of file xact.c.

598 {
600  static TransactionId stablexid = InvalidTransactionId;
601 
602  if (lxid != MyProc->lxid)
603  {
604  lxid = MyProc->lxid;
605  stablexid = GetTopTransactionIdIfAny();
606  if (!TransactionIdIsValid(stablexid))
607  stablexid = ReadNextTransactionId();
608  }
609 
610  Assert(TransactionIdIsValid(stablexid));
611 
612  return stablexid;
613 }
uint32 LocalTransactionId
Definition: c.h:590
#define InvalidLocalTransactionId
Definition: lock.h:70
PGPROC * MyProc
Definition: proc.c:68
LocalTransactionId lxid
Definition: proc.h:183
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:431

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

Referenced by xid_age().

◆ GetTopFullTransactionId()

FullTransactionId GetTopFullTransactionId ( void  )

Definition at line 473 of file xact.c.

474 {
478 }
static TransactionStateData TopTransactionStateData
Definition: xact.c:240
static FullTransactionId XactTopFullTransactionId
Definition: xact.c:124

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

Referenced by pg_current_xact_id().

◆ GetTopFullTransactionIdIfAny()

FullTransactionId GetTopFullTransactionIdIfAny ( void  )

Definition at line 489 of file xact.c.

490 {
492 }

References XactTopFullTransactionId.

Referenced by pg_current_xact_id_if_assigned().

◆ GetTopTransactionId()

◆ GetTopTransactionIdIfAny()

◆ IsAbortedTransactionBlockState()

◆ IsInParallelMode()

◆ IsInTransactionBlock()

bool IsInTransactionBlock ( bool  isTopLevel)

Definition at line 3588 of file xact.c.

3589 {
3590  /*
3591  * Return true on same conditions that would make
3592  * PreventInTransactionBlock error out
3593  */
3594  if (IsTransactionBlock())
3595  return true;
3596 
3597  if (IsSubTransaction())
3598  return true;
3599 
3600  if (!isTopLevel)
3601  return true;
3602 
3605  return true;
3606 
3607  /*
3608  * If we tell the caller we're not in a transaction block, then inform
3609  * postgres.c that it had better commit when the statement is done.
3610  * Otherwise our report could be a lie.
3611  */
3613 
3614  return false;
3615 }
bool IsSubTransaction(void)
Definition: xact.c:4869
bool IsTransactionBlock(void)
Definition: xact.c:4796
int MyXactFlags
Definition: xact.c:135
#define XACT_FLAGS_NEEDIMMEDIATECOMMIT
Definition: xact.h:114

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

Referenced by vacuum().

◆ IsSubTransaction()

◆ IsSubxactTopXidLogPending()

bool IsSubxactTopXidLogPending ( void  )

Definition at line 549 of file xact.c.

550 {
551  /* check whether it is already logged */
553  return false;
554 
555  /* wal_level has to be logical */
556  if (!XLogLogicalInfoActive())
557  return false;
558 
559  /* we need to be in a transaction state */
560  if (!IsTransactionState())
561  return false;
562 
563  /* it has to be a subtransaction */
564  if (!IsSubTransaction())
565  return false;
566 
567  /* the subtransaction has to have a XID assigned */
569  return false;
570 
571  return true;
572 }
bool IsTransactionState(void)
Definition: xact.c:377
TransactionId GetCurrentTransactionIdIfAny(void)
Definition: xact.c:461
#define XLogLogicalInfoActive()
Definition: xlog.h:121

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

Referenced by MarkSubxactTopXidLogged(), and XLogRecordAssemble().

◆ IsTransactionBlock()

bool IsTransactionBlock ( void  )

◆ IsTransactionOrTransactionBlock()

◆ IsTransactionState()

bool IsTransactionState ( void  )

Definition at line 377 of file xact.c.

378 {
380 
381  /*
382  * TRANS_DEFAULT and TRANS_ABORT are obviously unsafe states. However, we
383  * also reject the startup/shutdown states TRANS_START, TRANS_COMMIT,
384  * TRANS_PREPARE since it might be too soon or too late within those
385  * transition states to do anything interesting. Hence, the only "valid"
386  * state is TRANS_INPROGRESS.
387  */
388  return (s->state == TRANS_INPROGRESS);
389 }

References CurrentTransactionState, TransactionStateData::state, and TRANS_INPROGRESS.

Referenced by apply_handle_commit_internal(), apply_handle_origin(), apply_handle_stream_stop(), 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(), CreateInitDecodingContext(), FetchTableStates(), InitializeClientEncoding(), IsSubxactTopXidLogPending(), LogicalRepApplyLoop(), LogLogicalMessage(), maybe_reread_subscription(), pg_attribute_noreturn(), pg_do_encoding_conversion(), PrepareClientEncoding(), PrepareTempTablespaces(), process_syncing_tables_for_apply(), process_syncing_tables_for_sync(), RelationClearRelation(), RelationIdGetRelation(), RelationInitPhysicalAddr(), RelationReloadNailed(), replorigin_create(), replorigin_drop_by_name(), SearchCatCacheInternal(), SetMultiXactIdLimit(), SetTransactionIdLimit(), SnapBuildClearExportedSnapshot(), and SocketBackend().

◆ MarkCurrentTransactionIdLoggedIfAny()

void MarkCurrentTransactionIdLoggedIfAny ( void  )

◆ MarkSubxactTopXidLogged()

void MarkSubxactTopXidLogged ( void  )

Definition at line 581 of file xact.c.

582 {
584 
586 }
bool IsSubxactTopXidLogPending(void)
Definition: xact.c:549

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 
193  if (parsed->xinfo & XACT_XINFO_HAS_DROPPED_STATS)
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:325
Oid tsId
Definition: xact.h:251
Oid dbId
Definition: xact.h:250
TimestampTz origin_timestamp
Definition: xact.h:304
XLogRecPtr origin_lsn
Definition: xact.h:303
xl_xact_stats_item * stats
Definition: xact.h:412
RelFileLocator * xlocators
Definition: xact.h:409
TransactionId twophase_xid
Definition: xact.h:414
TimestampTz xact_time
Definition: xact.h:399
TransactionId * subxacts
Definition: xact.h:406
XLogRecPtr origin_lsn
Definition: xact.h:417
char twophase_gid[GIDSIZE]
Definition: xact.h:415
TimestampTz origin_timestamp
Definition: xact.h:418
RelFileLocator xlocators[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:264
xl_xact_stats_item items[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:285
TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:257
int nsubxacts
Definition: xact.h:256
TransactionId xid
Definition: xact.h:298
uint32 xinfo
Definition: xact.h:245
struct xl_xact_stats_item xl_xact_stats_item
#define MinSizeOfXactSubxacts
Definition: xact.h:259
struct xl_xact_dbinfo xl_xact_dbinfo
#define XACT_XINFO_HAS_GID
Definition: xact.h:188
struct xl_xact_origin xl_xact_origin
#define XACT_XINFO_HAS_ORIGIN
Definition: xact.h:186
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:185
#define MinSizeOfXactRelfileLocators
Definition: xact.h:266
#define MinSizeOfXactStatsItems
Definition: xact.h:287
#define XACT_XINFO_HAS_RELFILELOCATORS
Definition: xact.h:183
#define MinSizeOfXactAbort
Definition: xact.h:337
struct xl_xact_xinfo xl_xact_xinfo
#define XACT_XINFO_HAS_DBINFO
Definition: xact.h:181
struct xl_xact_twophase xl_xact_twophase
#define XLOG_XACT_HAS_INFO
Definition: xact.h:175
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:182
#define XACT_XINFO_HAS_DROPPED_STATS
Definition: xact.h:189

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(), 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 
87  if (parsed->xinfo & XACT_XINFO_HAS_DROPPED_STATS)
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:309
SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:292
int nmsgs
Definition: xact.h:291
xl_xact_stats_item * stats
Definition: xact.h:379
TimestampTz xact_time
Definition: xact.h:366
TransactionId twophase_xid
Definition: xact.h:384
RelFileLocator * xlocators
Definition: xact.h:376
TimestampTz origin_timestamp
Definition: xact.h:392
TransactionId * subxacts
Definition: xact.h:373
char twophase_gid[GIDSIZE]
Definition: xact.h:385
XLogRecPtr origin_lsn
Definition: xact.h:391
SharedInvalidationMessage * msgs
Definition: xact.h:382
#define MinSizeOfXactInvals
Definition: xact.h:294
#define MinSizeOfXactCommit
Definition: xact.h:321
#define XACT_XINFO_HAS_INVALS
Definition: xact.h:184

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(), 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->nmsgs = xlrec->ninvalmsgs;
256 
257  strncpy(parsed->twophase_gid, bufptr, xlrec->gidlen);
258  bufptr += MAXALIGN(xlrec->gidlen);
259 
260  parsed->subxacts = (TransactionId *) bufptr;
261  bufptr += MAXALIGN(xlrec->nsubxacts * sizeof(TransactionId));
262 
263  parsed->xlocators = (RelFileLocator *) bufptr;
264  bufptr += MAXALIGN(xlrec->ncommitrels * sizeof(RelFileLocator));
265 
266  parsed->abortlocators = (RelFileLocator *) bufptr;
267  bufptr += MAXALIGN(xlrec->nabortrels * sizeof(RelFileLocator));
268 
269  parsed->stats = (xl_xact_stats_item *) bufptr;
270  bufptr += MAXALIGN(xlrec->ncommitstats * sizeof(xl_xact_stats_item));
271 
272  parsed->abortstats = (xl_xact_stats_item *) bufptr;
273  bufptr += MAXALIGN(xlrec->nabortstats * sizeof(xl_xact_stats_item));
274 
275  parsed->msgs = (SharedInvalidationMessage *) bufptr;
276  bufptr += MAXALIGN(xlrec->ninvalmsgs * sizeof(SharedInvalidationMessage));
277 }
#define MAXALIGN(LEN)
Definition: c.h:747
RelFileLocator * abortlocators
Definition: xact.h:387
xl_xact_stats_item * abortstats
Definition: xact.h:389
TimestampTz prepared_at
Definition: xact.h:345
int32 nabortrels
Definition: xact.h:349
int32 ninvalmsgs
Definition: xact.h:352
int32 ncommitstats
Definition: xact.h:350
TimestampTz origin_timestamp
Definition: xact.h:356
uint16 gidlen
Definition: xact.h:354
int32 nabortstats
Definition: xact.h:351
Oid database
Definition: xact.h:344
XLogRecPtr origin_lsn
Definition: xact.h:355
int32 ncommitrels
Definition: xact.h:348
TransactionId xid
Definition: xact.h:343
int32 nsubxacts
Definition: xact.h:347

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_prepare::ncommitrels, xl_xact_prepare::ncommitstats, xl_xact_prepare::ninvalmsgs, xl_xact_parsed_commit::nmsgs, xl_xact_parsed_commit::nrels, 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 3818 of file xact.c.

3819 {
3820  TransactionState s;
3821  bool result;
3822 
3823  /* Set up to commit the current transaction */
3824  result = EndTransactionBlock(false);
3825 
3826  /* If successful, change outer tblock state to PREPARE */
3827  if (result)
3828  {
3830 
3831  while (s->parent != NULL)
3832  s = s->parent;
3833 
3834  if (s->blockState == TBLOCK_END)
3835  {
3836  /* Save GID where PrepareTransaction can find it again */
3838 
3840  }
3841  else
3842  {
3843  /*
3844  * ignore case where we are not in a transaction;
3845  * EndTransactionBlock already issued a warning.
3846  */
3849  /* Don't send back a PREPARE result tag... */
3850  result = false;
3851  }
3852  }
3853 
3854  return result;
3855 }
static char * prepareGID
Definition: xact.c:281
bool EndTransactionBlock(bool chain)
Definition: xact.c:3870

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 3469 of file xact.c.

3470 {
3471  /*
3472  * xact block already started?
3473  */
3474  if (IsTransactionBlock())
3475  ereport(ERROR,
3476  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3477  /* translator: %s represents an SQL statement name */
3478  errmsg("%s cannot run inside a transaction block",
3479  stmtType)));
3480 
3481  /*
3482  * subtransaction?
3483  */
3484  if (IsSubTransaction())
3485  ereport(ERROR,
3486  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3487  /* translator: %s represents an SQL statement name */
3488  errmsg("%s cannot run inside a subtransaction",
3489  stmtType)));
3490 
3491  /*
3492  * inside a function call?
3493  */
3494  if (!isTopLevel)
3495  ereport(ERROR,
3496  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3497  /* translator: %s represents an SQL statement name */
3498  errmsg("%s cannot be executed from a function", stmtType)));
3499 
3500  /* If we got past IsTransactionBlock test, should be in default state */
3503  elog(FATAL, "cannot prevent transaction chain");
3504 
3505  /* All okay. Set the flag to make sure the right thing happens later. */
3507 }

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(), 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 3690 of file xact.c.

3691 {
3692  SubXactCallbackItem *item;
3693 
3694  item = (SubXactCallbackItem *)
3696  item->callback = callback;
3697  item->arg = arg;
3698  item->next = SubXact_callbacks;
3699  SubXact_callbacks = item;
3700 }
MemoryContext TopMemoryContext
Definition: mcxt.c:130
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:994
void * arg
struct SubXactCallbackItem * next
Definition: xact.c:315
SubXactCallback callback
Definition: xact.c:316
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46
static SubXactCallbackItem * SubXact_callbacks
Definition: xact.c:320

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 3630 of file xact.c.

3631 {
3632  XactCallbackItem *item;
3633 
3634  item = (XactCallbackItem *)
3636  item->callback = callback;
3637  item->arg = arg;
3638  item->next = Xact_callbacks;
3639  Xact_callbacks = item;
3640 }
struct XactCallbackItem * next
Definition: xact.c:303
void * arg
Definition: xact.c:305
XactCallback callback
Definition: xact.c:304
static XactCallbackItem * Xact_callbacks
Definition: xact.c:308

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 4591 of file xact.c.

4592 {
4594 
4595  /*
4596  * Workers synchronize transaction state at the beginning of each parallel
4597  * operation, so we can't account for commit of subtransactions after that
4598  * point. This should not happen anyway. Code calling this would
4599  * typically have called BeginInternalSubTransaction() first, failing
4600  * there.
4601  */
4602  if (IsInParallelMode())
4603  ereport(ERROR,
4604  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4605  errmsg("cannot commit subtransactions during a parallel operation")));
4606 
4607  if (s->blockState != TBLOCK_SUBINPROGRESS)
4608  elog(ERROR, "ReleaseCurrentSubTransaction: unexpected state %s",
4610  Assert(s->state == TRANS_INPROGRESS);
4613  s = CurrentTransactionState; /* changed by pop */
4614  Assert(s->state == TRANS_INPROGRESS);
4615 }
MemoryContext CurTransactionContext
Definition: mcxt.c:136
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:135

References Assert(), TransactionStateData::blockState, BlockStateAsString(), CommitSubTransaction(), CurrentTransactionState, CurTransactionContext, elog(), ereport, errcode(), errmsg(), ERROR, IsInParallelMode(), 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 4284 of file xact.c.

4285 {
4287  TransactionState target,
4288  xact;
4289 
4290  /*
4291  * Workers synchronize transaction state at the beginning of each parallel
4292  * operation, so we can't account for transaction state change after that
4293  * point. (Note that this check will certainly error out if s->blockState
4294  * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4295  * below.)
4296  */
4297  if (IsInParallelMode())
4298  ereport(ERROR,
4299  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4300  errmsg("cannot release savepoints during a parallel operation")));
4301 
4302  switch (s->blockState)
4303  {
4304  /*
4305  * We can't release a savepoint if there is no savepoint defined.
4306  */
4307  case TBLOCK_INPROGRESS:
4308  ereport(ERROR,
4309  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4310  errmsg("savepoint \"%s\" does not exist", name)));
4311  break;
4312 
4314  /* See comment about implicit transactions in DefineSavepoint */
4315  ereport(ERROR,
4316  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4317  /* translator: %s represents an SQL statement name */
4318  errmsg("%s can only be used in transaction blocks",
4319  "RELEASE SAVEPOINT")));
4320  break;
4321 
4322  /*
4323  * We are in a non-aborted subtransaction. This is the only valid
4324  * case.
4325  */
4326  case TBLOCK_SUBINPROGRESS:
4327  break;
4328 
4329  /* These cases are invalid. */
4330  case TBLOCK_DEFAULT:
4331  case TBLOCK_STARTED:
4332  case TBLOCK_BEGIN:
4334  case TBLOCK_SUBBEGIN:
4335  case TBLOCK_END:
4336  case TBLOCK_SUBRELEASE:
4337  case TBLOCK_SUBCOMMIT:
4338  case TBLOCK_ABORT:
4339  case TBLOCK_SUBABORT:
4340  case TBLOCK_ABORT_END:
4341  case TBLOCK_SUBABORT_END:
4342  case TBLOCK_ABORT_PENDING:
4344  case TBLOCK_SUBRESTART:
4346  case TBLOCK_PREPARE:
4347  elog(FATAL, "ReleaseSavepoint: unexpected state %s",
4349  break;
4350  }
4351 
4352  for (target = s; PointerIsValid(target); target = target->parent)
4353  {
4354  if (PointerIsValid(target->name) && strcmp(target->name, name) == 0)
4355  break;
4356  }
4357 
4358  if (!PointerIsValid(target))
4359  ereport(ERROR,
4360  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4361  errmsg("savepoint \"%s\" does not exist", name)));
4362 
4363  /* disallow crossing savepoint level boundaries */
4364  if (target->savepointLevel != s->savepointLevel)
4365  ereport(ERROR,
4366  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4367  errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
4368 
4369  /*
4370  * Mark "commit pending" all subtransactions up to the target
4371  * subtransaction. The actual commits will happen when control gets to
4372  * CommitTransactionCommand.
4373  */
4374  xact = CurrentTransactionState;
4375  for (;;)
4376  {
4378  xact->blockState = TBLOCK_SUBRELEASE;
4379  if (xact == target)
4380  break;
4381  xact = xact->parent;
4382  Assert(PointerIsValid(xact));
4383  }
4384 }
#define PointerIsValid(pointer)
Definition: c.h:699

References Assert(), TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog(), ereport, errcode(), errmsg(), ERROR, FATAL, IsInParallelMode(), TransactionStateData::name, name, TransactionStateData::parent, PointerIsValid, 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 3537 of file xact.c.

3538 {
3539  CheckTransactionBlock(isTopLevel, true, stmtType);
3540 }
static void CheckTransactionBlock(bool isTopLevel, bool throwError, const char *stmtType)
Definition: xact.c:3546

References CheckTransactionBlock().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

◆ RestoreTransactionCharacteristics()

◆ RollbackAndReleaseCurrentSubTransaction()

void RollbackAndReleaseCurrentSubTransaction ( void  )

Definition at line 4625 of file xact.c.

4626 {
4628 
4629  /*
4630  * Unlike ReleaseCurrentSubTransaction(), this is nominally permitted
4631  * during parallel operations. That's because we may be in the leader,
4632  * recovering from an error thrown while we were in parallel mode. We
4633  * won't reach here in a worker, because BeginInternalSubTransaction()
4634  * will have failed.
4635  */
4636 
4637  switch (s->blockState)
4638  {
4639  /* Must be in a subtransaction */
4640  case TBLOCK_SUBINPROGRESS:
4641  case TBLOCK_SUBABORT:
4642  break;
4643 
4644  /* These cases are invalid. */
4645  case TBLOCK_DEFAULT:
4646  case TBLOCK_STARTED:
4647  case TBLOCK_BEGIN:
4650  case TBLOCK_SUBBEGIN:
4651  case TBLOCK_INPROGRESS:
4652  case TBLOCK_END:
4653  case TBLOCK_SUBRELEASE:
4654  case TBLOCK_SUBCOMMIT:
4655  case TBLOCK_ABORT:
4656  case TBLOCK_ABORT_END:
4657  case TBLOCK_SUBABORT_END:
4658  case TBLOCK_ABORT_PENDING:
4660  case TBLOCK_SUBRESTART:
4662  case TBLOCK_PREPARE:
4663  elog(FATAL, "RollbackAndReleaseCurrentSubTransaction: unexpected state %s",
4665  break;
4666  }
4667 
4668  /*
4669  * Abort the current subtransaction, if needed.
4670  */
4671  if (s->blockState == TBLOCK_SUBINPROGRESS)
4673 
4674  /* And clean it up, too */
4676 
4677  s = CurrentTransactionState; /* changed by pop */
4679  s->blockState == TBLOCK_INPROGRESS ||
4681  s->blockState == TBLOCK_STARTED);
4682 }

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 4393 of file xact.c.

4394 {
4396  TransactionState target,
4397  xact;
4398 
4399  /*
4400  * Workers synchronize transaction state at the beginning of each parallel
4401  * operation, so we can't account for transaction state change after that
4402  * point. (Note that this check will certainly error out if s->blockState
4403  * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4404  * below.)
4405  */
4406  if (IsInParallelMode())
4407  ereport(ERROR,
4408  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4409  errmsg("cannot rollback to savepoints during a parallel operation")));
4410 
4411  switch (s->blockState)
4412  {
4413  /*
4414  * We can't rollback to a savepoint if there is no savepoint
4415  * defined.
4416  */
4417  case TBLOCK_INPROGRESS:
4418  case TBLOCK_ABORT:
4419  ereport(ERROR,
4420  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4421  errmsg("savepoint \"%s\" does not exist", name)));
4422  break;
4423 
4425  /* See comment about implicit transactions in DefineSavepoint */
4426  ereport(ERROR,
4427  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4428  /* translator: %s represents an SQL statement name */
4429  errmsg("%s can only be used in transaction blocks",
4430  "ROLLBACK TO SAVEPOINT")));
4431  break;
4432 
4433  /*
4434  * There is at least one savepoint, so proceed.
4435  */
4436  case TBLOCK_SUBINPROGRESS:
4437  case TBLOCK_SUBABORT:
4438  break;
4439 
4440  /* These cases are invalid. */
4441  case TBLOCK_DEFAULT:
4442  case TBLOCK_STARTED:
4443  case TBLOCK_BEGIN:
4445  case TBLOCK_SUBBEGIN:
4446  case TBLOCK_END:
4447  case TBLOCK_SUBRELEASE:
4448  case TBLOCK_SUBCOMMIT:
4449  case TBLOCK_ABORT_END:
4450  case TBLOCK_SUBABORT_END:
4451  case TBLOCK_ABORT_PENDING:
4453  case TBLOCK_SUBRESTART:
4455  case TBLOCK_PREPARE:
4456  elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4458  break;
4459  }
4460 
4461  for (target = s; PointerIsValid(target); target = target->parent)
4462  {
4463  if (PointerIsValid(target->name) && strcmp(target->name, name) == 0)
4464  break;
4465  }
4466 
4467  if (!PointerIsValid(target))
4468  ereport(ERROR,
4469  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4470  errmsg("savepoint \"%s\" does not exist", name)));
4471 
4472  /* disallow crossing savepoint level boundaries */
4473  if (target->savepointLevel != s->savepointLevel)
4474  ereport(ERROR,
4475  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4476  errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
4477 
4478  /*
4479  * Mark "abort pending" all subtransactions up to the target
4480  * subtransaction. The actual aborts will happen when control gets to
4481  * CommitTransactionCommand.
4482  */
4483  xact = CurrentTransactionState;
4484  for (;;)
4485  {
4486  if (xact == target)
4487  break;
4488  if (xact->blockState == TBLOCK_SUBINPROGRESS)
4490  else if (xact->blockState == TBLOCK_SUBABORT)
4492  else
4493  elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4495  xact = xact->parent;
4496  Assert(PointerIsValid(xact));
4497  }
4498 
4499  /* And mark the target as "restart pending" */
4500  if (xact->blockState == TBLOCK_SUBINPROGRESS)
4501  xact->blockState = TBLOCK_SUBRESTART;
4502  else if (xact->blockState == TBLOCK_SUBABORT)
4504  else
4505  elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4507 }

References Assert(), TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog(), ereport, errcode(), errmsg(), ERROR, FATAL, IsInParallelMode(), TransactionStateData::name, name, TransactionStateData::parent, PointerIsValid, 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().

◆ SaveTransactionCharacteristics()

◆ SerializeTransactionState()

void SerializeTransactionState ( Size  maxsize,
char *  start_address 
)

Definition at line 5352 of file xact.c.

5353 {
5354  TransactionState s;
5355  Size nxids = 0;
5356  Size i = 0;
5357  TransactionId *workspace;
5359 
5360  result = (SerializedTransactionState *) start_address;
5361 
5362  result->xactIsoLevel = XactIsoLevel;
5363  result->xactDeferrable = XactDeferrable;
5365  result->currentFullTransactionId =
5368 
5369  /*
5370  * If we're running in a parallel worker and launching a parallel worker
5371  * of our own, we can just pass along the information that was passed to
5372  * us.
5373  */
5374  if (nParallelCurrentXids > 0)
5375  {
5377  memcpy(&result->parallelCurrentXids[0], ParallelCurrentXids,
5379  return;
5380  }
5381 
5382  /*
5383  * OK, we need to generate a sorted list of XIDs that our workers should
5384  * view as current. First, figure out how many there are.
5385  */
5386  for (s = CurrentTransactionState; s != NULL; s = s->parent)
5387  {
5389  nxids = add_size(nxids, 1);
5390  nxids = add_size(nxids, s->nChildXids);
5391  }
5393  <= maxsize);
5394 
5395  /* Copy them to our scratch space. */
5396  workspace = palloc(nxids * sizeof(TransactionId));
5397  for (s = CurrentTransactionState; s != NULL; s = s->parent)
5398  {
5400  workspace[i++] = XidFromFullTransactionId(s->fullTransactionId);
5401  if (s->nChildXids > 0)
5402  memcpy(&workspace[i], s->childXids,
5403  s->nChildXids * sizeof(TransactionId));
5404  i += s->nChildXids;
5405  }
5406  Assert(i == nxids);
5407 
5408  /* Sort them. */
5409  qsort(workspace, nxids, sizeof(TransactionId), xidComparator);
5410 
5411  /* Copy data into output area. */
5412  result->nParallelCurrentXids = nxids;
5413  memcpy(&result->parallelCurrentXids[0], workspace,
5414  nxids * sizeof(TransactionId));
5415 }
int i
Definition: isn.c:73
void * palloc(Size size)
Definition: mcxt.c:1199
#define qsort(a, b, c, d)
Definition: port.h:445
FullTransactionId currentFullTransactionId
Definition: xact.c:225
FullTransactionId topFullTransactionId
Definition: xact.c:224
CommandId currentCommandId
Definition: xact.c:226
TransactionId parallelCurrentXids[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.c:228
TransactionId * childXids
Definition: xact.c:200
static int nParallelCurrentXids
Definition: xact.c:125
static TransactionId * ParallelCurrentXids
Definition: xact.c:126
int xidComparator(const void *arg1, const void *arg2)
Definition: xid.c:136

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()

void SetCurrentStatementStartTimestamp ( void  )

◆ SetParallelStartTimestamps()

void SetParallelStartTimestamps ( TimestampTz  xact_ts,
TimestampTz  stmt_ts 
)

Definition at line 843 of file xact.c.

844 {
846  xactStartTimestamp = xact_ts;
847  stmtStartTimestamp = stmt_ts;
848 }

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

Referenced by ParallelWorkerMain().

◆ StartParallelWorkerTransaction()

void StartParallelWorkerTransaction ( char *  tstatespace)

◆ StartTransactionCommand()

void StartTransactionCommand ( void  )

Definition at line 2925 of file xact.c.

2926 {
2928 
2929  switch (s->blockState)
2930  {
2931  /*
2932  * if we aren't in a transaction block, we just do our usual start
2933  * transaction.
2934  */
2935  case TBLOCK_DEFAULT:
2936  StartTransaction();
2938  break;
2939 
2940  /*
2941  * We are somewhere in a transaction block or subtransaction and
2942  * about to start a new command. For now we do nothing, but
2943  * someday we may do command-local resource initialization. (Note
2944  * that any needed CommandCounterIncrement was done by the
2945  * previous CommitTransactionCommand.)
2946  */
2947  case TBLOCK_INPROGRESS:
2949  case TBLOCK_SUBINPROGRESS:
2950  break;
2951 
2952  /*
2953  * Here we are in a failed transaction block (one of the commands
2954  * caused an abort) so we do nothing but remain in the abort
2955  * state. Eventually we will get a ROLLBACK command which will
2956  * get us out of this state. (It is up to other code to ensure
2957  * that no commands other than ROLLBACK will be processed in these
2958  * states.)
2959  */
2960  case TBLOCK_ABORT:
2961  case TBLOCK_SUBABORT:
2962  break;
2963 
2964  /* These cases are invalid. */
2965  case TBLOCK_STARTED:
2966  case TBLOCK_BEGIN:
2968  case TBLOCK_SUBBEGIN:
2969  case TBLOCK_END:
2970  case TBLOCK_SUBRELEASE:
2971  case TBLOCK_SUBCOMMIT:
2972  case TBLOCK_ABORT_END:
2973  case TBLOCK_SUBABORT_END:
2974  case TBLOCK_ABORT_PENDING:
2976  case TBLOCK_SUBRESTART:
2978  case TBLOCK_PREPARE:
2979  elog(ERROR, "StartTransactionCommand: unexpected state %s",
2981  break;
2982  }
2983 
2984  /*
2985  * We must switch to CurTransactionContext before returning. This is
2986  * already done if we called StartTransaction, otherwise not.
2987  */
2988  Assert(CurTransactionContext != NULL);
2990 }

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(), ApplyWorkerMain(), ATExecDetachPartition(), autoprewarm_database_main(), bbsink_server_new(), begin_replication_step(), BeginInternalSubTransaction(), BootstrapModeMain(), clear_subscription_skip_lsn(), cluster(), cluster_multiple_rels(), DefineIndex(), DisableSubscriptionAndExit(), do_autovacuum(), exec_replication_command(), FetchTableStates(), get_database_list(), get_subscription_list(), IdentifySystem(), index_drop(), initialize_worker_spi(), InitPostgres(), LogicalRepSyncTableStart(), maybe_reread_subscription(), movedb(), ParallelWorkerMain(), perform_work_item(), pg_attribute_noreturn(), process_syncing_tables_for_apply(), process_syncing_tables_for_sync(), ProcessCatchupInterrupt(), ProcessIncomingNotify(), ReindexMultipleInternal(), ReindexRelationConcurrently(), RemoveTempRelationsCallback(), ReorderBufferProcessTXN(), shell_check_detail(), SnapBuildExportSnapshot(), start_xact_command(), vacuum(), and vacuum_rel().

◆ SubTransactionIsActive()

bool SubTransactionIsActive ( SubTransactionId  subxid)

Definition at line 793 of file xact.c.

794 {
796 
797  for (s = CurrentTransactionState; s != NULL; s = s->parent)
798  {
799  if (s->state == TRANS_ABORT)
800  continue;
801  if (s->subTransactionId == subxid)
802  return true;
803  }
804  return false;
805 }

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

Referenced by fmgr_sql().

◆ TransactionBlockStatusCode()

char TransactionBlockStatusCode ( void  )

Definition at line 4828 of file xact.c.

4829 {
4831 
4832  switch (s->blockState)
4833  {
4834  case TBLOCK_DEFAULT:
4835  case TBLOCK_STARTED:
4836  return 'I'; /* idle --- not in transaction */
4837  case TBLOCK_BEGIN:
4838  case TBLOCK_SUBBEGIN:
4839  case TBLOCK_INPROGRESS:
4842  case TBLOCK_SUBINPROGRESS:
4843  case TBLOCK_END:
4844  case TBLOCK_SUBRELEASE:
4845  case TBLOCK_SUBCOMMIT:
4846  case TBLOCK_PREPARE:
4847  return 'T'; /* in transaction */
4848  case TBLOCK_ABORT:
4849  case TBLOCK_SUBABORT:
4850  case TBLOCK_ABORT_END:
4851  case TBLOCK_SUBABORT_END:
4852  case TBLOCK_ABORT_PENDING:
4854  case TBLOCK_SUBRESTART:
4856  return 'E'; /* in failed transaction */
4857  }
4858 
4859  /* should never get here */
4860  elog(FATAL, "invalid transaction block state: %s",
4862  return 0; /* keep compiler quiet */
4863 }

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 925 of file xact.c.

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

◆ UnregisterSubXactCallback()

void UnregisterSubXactCallback ( SubXactCallback  callback,
void *  arg 
)

Definition at line 3703 of file xact.c.

3704 {
3705  SubXactCallbackItem *item;
3706  SubXactCallbackItem *prev;
3707 
3708  prev = NULL;
3709  for (item = SubXact_callbacks; item; prev = item, item = item->next)
3710  {
3711  if (item->callback == callback && item->arg == arg)
3712  {
3713  if (prev)
3714  prev->next = item->next;
3715  else
3716  SubXact_callbacks = item->next;
3717  pfree(item);
3718  break;
3719  }
3720  }
3721 }
void pfree(void *pointer)
Definition: mcxt.c:1306

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

◆ UnregisterXactCallback()

void UnregisterXactCallback ( XactCallback  callback,
void *  arg 
)

Definition at line 3643 of file xact.c.

3644 {
3645  XactCallbackItem *item;
3646  XactCallbackItem *prev;
3647 
3648  prev = NULL;
3649  for (item = Xact_callbacks; item; prev = item, item = item->next)
3650  {
3651  if (item->callback == callback && item->arg == arg)
3652  {
3653  if (prev)
3654  prev->next = item->next;
3655  else
3656  Xact_callbacks = item->next;
3657  pfree(item);
3658  break;
3659  }
3660  }
3661 }

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

◆ UserAbortTransactionBlock()

void UserAbortTransactionBlock ( bool  chain)

Definition at line 4030 of file xact.c.

4031 {
4033 
4034  switch (s->blockState)
4035  {
4036  /*
4037  * We are inside a transaction block and we got a ROLLBACK command
4038  * from the user, so tell CommitTransactionCommand to abort and
4039  * exit the transaction block.
4040  */
4041  case TBLOCK_INPROGRESS:
4043  break;
4044 
4045  /*
4046  * We are inside a failed transaction block and we got a ROLLBACK
4047  * command from the user. Abort processing is already done, so
4048  * CommitTransactionCommand just has to cleanup and go back to
4049  * idle state.
4050  */
4051  case TBLOCK_ABORT:
4053  break;
4054 
4055  /*
4056  * We are inside a subtransaction. Mark everything up to top
4057  * level as exitable.
4058  */
4059  case TBLOCK_SUBINPROGRESS:
4060  case TBLOCK_SUBABORT:
4061  while (s->parent != NULL)
4062  {
4063  if (s->blockState == TBLOCK_SUBINPROGRESS)
4065  else if (s->blockState == TBLOCK_SUBABORT)
4067  else
4068  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4070  s = s->parent;
4071  }
4072  if (s->blockState == TBLOCK_INPROGRESS)
4074  else if (s->blockState == TBLOCK_ABORT)
4076  else
4077  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4079  break;
4080 
4081  /*
4082  * The user issued ABORT when not inside a transaction. For
4083  * ROLLBACK without CHAIN, issue a WARNING and go to abort state.
4084  * The upcoming call to CommitTransactionCommand() will then put
4085  * us back into the default state. For ROLLBACK AND CHAIN, error.
4086  *
4087  * We do the same thing with ABORT inside an implicit transaction,
4088  * although in this case we might be rolling back actual database
4089  * state changes. (It's debatable whether we should issue a
4090  * WARNING in this case, but we have done so historically.)
4091  */
4092  case TBLOCK_STARTED:
4094  if (chain)
4095  ereport(ERROR,
4096  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4097  /* translator: %s represents an SQL statement name */
4098  errmsg("%s can only be used in transaction blocks",
4099  "ROLLBACK AND CHAIN")));
4100  else
4101  ereport(WARNING,
4102  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4103  errmsg("there is no transaction in progress")));
4105  break;
4106 
4107  /*
4108  * The user issued an ABORT that somehow ran inside a parallel
4109  * worker. We can't cope with that.
4110  */
4112  ereport(FATAL,
4113  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4114  errmsg("cannot abort during a parallel operation")));
4115  break;
4116 
4117  /* These cases are invalid. */
4118  case TBLOCK_DEFAULT:
4119  case TBLOCK_BEGIN:
4120  case TBLOCK_SUBBEGIN:
4121  case TBLOCK_END:
4122  case TBLOCK_SUBRELEASE:
4123  case TBLOCK_SUBCOMMIT:
4124  case TBLOCK_ABORT_END:
4125  case TBLOCK_SUBABORT_END:
4126  case TBLOCK_ABORT_PENDING:
4128  case TBLOCK_SUBRESTART:
4130  case TBLOCK_PREPARE:
4131  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4133  break;
4134  }
4135 
4138 
4139  s->chain = chain;
4140 }

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 3531 of file xact.c.

3532 {
3533  CheckTransactionBlock(isTopLevel, false, stmtType);
3534 }

References CheckTransactionBlock().

Referenced by ExecSetVariableStmt(), and standard_ProcessUtility().

◆ xact_desc()

void xact_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 436 of file xactdesc.c.

437 {
438  char *rec = XLogRecGetData(record);
439  uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
440 
441  if (info == XLOG_XACT_COMMIT || info == XLOG_XACT_COMMIT_PREPARED)
442  {
443  xl_xact_commit *xlrec = (xl_xact_commit *) rec;
444 
445  xact_desc_commit(buf, XLogRecGetInfo(record), xlrec,
446  XLogRecGetOrigin(record));
447  }
448  else if (info == XLOG_XACT_ABORT || info == XLOG_XACT_ABORT_PREPARED)
449  {
450  xl_xact_abort *xlrec = (xl_xact_abort *) rec;
451 
452  xact_desc_abort(buf, XLogRecGetInfo(record), xlrec,
453  XLogRecGetOrigin(record));
454  }
455  else if (info == XLOG_XACT_PREPARE)
456  {
457  xl_xact_prepare *xlrec = (xl_xact_prepare *) rec;
458 
459  xact_desc_prepare(buf, XLogRecGetInfo(record), xlrec,
460  XLogRecGetOrigin(record));
461  }
462  else if (info == XLOG_XACT_ASSIGNMENT)
463  {
464  xl_xact_assignment *xlrec = (xl_xact_assignment *) rec;
465 
466  /*
467  * Note that we ignore the WAL record's xid, since we're more
468  * interested in the top-level xid that issued the record and which
469  * xids are being reported here.
470  */
471  appendStringInfo(buf, "xtop %u: ", xlrec->xtop);
472  xact_desc_assignment(buf, xlrec);
473  }
474  else if (info == XLOG_XACT_INVALIDATIONS)
475  {
476  xl_xact_invals *xlrec = (xl_xact_invals *) rec;
477 
479  InvalidOid, false);
480  }
481 }
unsigned char uint8
Definition: c.h:440
static char * buf
Definition: pg_test_fsync.c:67
#define InvalidOid
Definition: postgres_ext.h:36
void standby_desc_invalidations(StringInfo buf, int nmsgs, SharedInvalidationMessage *msgs, Oid dbId, Oid tsId, bool relcacheInitFileInval)
Definition: standbydesc.c:105
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
TransactionId xtop
Definition: xact.h:213
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:165
#define XLOG_XACT_INVALIDATIONS
Definition: xact.h:168
#define XLOG_XACT_PREPARE
Definition: xact.h:163
#define XLOG_XACT_COMMIT
Definition: xact.h:162
#define XLOG_XACT_OPMASK
Definition: xact.h:172
#define XLOG_XACT_ABORT
Definition: xact.h:164
#define XLOG_XACT_ASSIGNMENT
Definition: xact.h:167
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:166
static void xact_desc_commit(StringInfo buf, uint8 info, xl_xact_commit *xlrec, RepOriginId origin_id)
Definition: xactdesc.c:331
static void xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec, RepOriginId origin_id)
Definition: xactdesc.c:367
static void xact_desc_assignment(StringInfo buf, xl_xact_assignment *xlrec)
Definition: xactdesc.c:425
static void xact_desc_prepare(StringInfo buf, uint8 info, xl_xact_prepare *xlrec, RepOriginId origin_id)
Definition: xactdesc.c:394
#define XLogRecGetOrigin(decoder)
Definition: xlogreader.h:414
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:411
#define XLogRecGetData(decoder)
Definition: xlogreader.h:416

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 484 of file xactdesc.c.

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

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 6167 of file xact.c.

6168 {
6169  uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
6170 
6171  /* Backup blocks are not used in xact records */
6172  Assert(!XLogRecHasAnyBlockRefs(record));
6173 
6174  if (info == XLOG_XACT_COMMIT)
6175  {
6176  xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6177  xl_xact_parsed_commit parsed;
6178 
6179  ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6180  xact_redo_commit(&parsed, XLogRecGetXid(record),
6181  record->EndRecPtr, XLogRecGetOrigin(record));
6182  }
6183  else if (info == XLOG_XACT_COMMIT_PREPARED)
6184  {
6185  xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6186  xl_xact_parsed_commit parsed;
6187 
6188  ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6189  xact_redo_commit(&parsed, parsed.twophase_xid,
6190  record->EndRecPtr, XLogRecGetOrigin(record));
6191 
6192  /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6193  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6194  PrepareRedoRemove(parsed.twophase_xid, false);
6195  LWLockRelease(TwoPhaseStateLock);
6196  }
6197  else if (info == XLOG_XACT_ABORT)
6198  {
6199  xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6200  xl_xact_parsed_abort parsed;
6201 
6202  ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6203  xact_redo_abort(&parsed, XLogRecGetXid(record),
6204  record->EndRecPtr, XLogRecGetOrigin(record));
6205  }
6206  else if (info == XLOG_XACT_ABORT_PREPARED)
6207  {
6208  xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6209  xl_xact_parsed_abort parsed;
6210 
6211  ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6212  xact_redo_abort(&parsed, parsed.twophase_xid,
6213  record->EndRecPtr, XLogRecGetOrigin(record));
6214 
6215  /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6216  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6217  PrepareRedoRemove(parsed.twophase_xid, false);
6218  LWLockRelease(TwoPhaseStateLock);
6219  }
6220  else if (info == XLOG_XACT_PREPARE)
6221  {
6222  /*
6223  * Store xid and start/end pointers of the WAL record in TwoPhaseState
6224  * gxact entry.
6225  */
6226  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6228  record->ReadRecPtr,
6229  record->EndRecPtr,
6230  XLogRecGetOrigin(record));
6231  LWLockRelease(TwoPhaseStateLock);
6232  }
6233  else if (info == XLOG_XACT_ASSIGNMENT)
6234  {
6236 
6239  xlrec->nsubxacts, xlrec->xsub);
6240  }
6241  else if (info == XLOG_XACT_INVALIDATIONS)
6242  {
6243  /*
6244  * XXX we do ignore this for now, what matters are invalidations
6245  * written into the commit record.
6246  */
6247  }
6248  else
6249  elog(PANIC, "xact_redo: unknown op code %u", info);
6250 }
#define PANIC
Definition: elog.h:38
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1194
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1802
@ LW_EXCLUSIVE
Definition: lwlock.h:112
void ProcArrayApplyXidAssignment(TransactionId topxid, int nsubxids, TransactionId *subxids)
Definition: procarray.c:1302
XLogRecPtr EndRecPtr
Definition: xlogreader.h:207
XLogRecPtr ReadRecPtr
Definition: xlogreader.h:206
TransactionId xsub[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:215
void PrepareRedoRemove(TransactionId xid, bool giveWarning)
Definition: twophase.c:2525
void PrepareRedoAdd(char *buf, XLogRecPtr start_lsn, XLogRecPtr end_lsn, RepOriginId origin_id)
Definition: twophase.c:2455
static void xact_redo_commit(xl_xact_parsed_commit *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:5934
static void xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:6088
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:413
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:418
HotStandbyState standbyState
Definition: xlogutils.c:56
@ STANDBY_INITIALIZED
Definition: xlogutils.h:50

References Assert(), elog(), XLogReaderState::EndRecPtr, 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 5593 of file xact.c.

5594 {
5596 
5597  if (s->nChildXids == 0)
5598  *ptr = NULL;
5599  else
5600  *ptr = s->childXids;
5601 
5602  return s->nChildXids;
5603 }

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 5789 of file xact.c.

5795 {
5796  xl_xact_abort xlrec;
5797  xl_xact_xinfo xl_xinfo;
5798  xl_xact_subxacts xl_subxacts;
5799  xl_xact_relfilelocators xl_relfilelocators;
5800  xl_xact_stats_items xl_dropped_stats;
5801  xl_xact_twophase xl_twophase;
5802  xl_xact_dbinfo xl_dbinfo;
5803  xl_xact_origin xl_origin;
5804 
5805  uint8 info;
5806 
5807  Assert(CritSectionCount > 0);
5808 
5809  xl_xinfo.xinfo = 0;
5810 
5811  /* decide between a plain and 2pc abort */
5812  if (!TransactionIdIsValid(twophase_xid))
5813  info = XLOG_XACT_ABORT;
5814  else
5815  info = XLOG_XACT_ABORT_PREPARED;
5816 
5817 
5818  /* First figure out and collect all the information needed */
5819 
5820  xlrec.xact_time = abort_time;
5821 
5822  if ((xactflags & XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK))
5823  xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5824 
5825  if (nsubxacts > 0)
5826  {
5827  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5828  xl_subxacts.nsubxacts = nsubxacts;
5829  }
5830 
5831  if (nrels > 0)
5832  {
5834  xl_relfilelocators.nrels = nrels;
5835  info |= XLR_SPECIAL_REL_UPDATE;
5836  }
5837 
5838  if (ndroppedstats > 0)
5839  {
5840  xl_xinfo.xinfo |= XACT_XINFO_HAS_DROPPED_STATS;
5841  xl_dropped_stats.nitems = ndroppedstats;
5842  }
5843 
5844  if (TransactionIdIsValid(twophase_xid))
5845  {
5846  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5847  xl_twophase.xid = twophase_xid;
5848  Assert(twophase_gid != NULL);
5849 
5850  if (XLogLogicalInfoActive())
5851  xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
5852  }
5853 
5854  if (TransactionIdIsValid(twophase_xid) && XLogLogicalInfoActive())
5855  {
5856  xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5857  xl_dbinfo.dbId = MyDatabaseId;
5858  xl_dbinfo.tsId = MyDatabaseTableSpace;
5859  }
5860 
5861  /*
5862  * Dump transaction origin information only for abort prepared. We need
5863  * this during recovery to update the replication origin progress.
5864  */
5866  TransactionIdIsValid(twophase_xid))
5867  {
5868  xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
5869 
5872  }
5873 
5874  if (xl_xinfo.xinfo != 0)
5875  info |= XLOG_XACT_HAS_INFO;
5876 
5877  /* Then include all the collected data into the abort record. */
5878 
5879  XLogBeginInsert();
5880 
5881  XLogRegisterData((char *) (&xlrec), MinSizeOfXactAbort);
5882 
5883  if (xl_xinfo.xinfo != 0)
5884  XLogRegisterData((char *) (&xl_xinfo), sizeof(xl_xinfo));
5885 
5886  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5887  XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
5888 
5889  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5890  {
5891  XLogRegisterData((char *) (&xl_subxacts),
5893  XLogRegisterData((char *) subxacts,
5894  nsubxacts * sizeof(TransactionId));
5895  }
5896 
5897  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILELOCATORS)
5898  {
5899  XLogRegisterData((char *) (&xl_relfilelocators),
5901  XLogRegisterData((char *) rels,
5902  nrels * sizeof(RelFileLocator));
5903  }
5904 
5905  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
5906  {
5907  XLogRegisterData((char *) (&xl_dropped_stats),
5909  XLogRegisterData((char *) droppedstats,
5910  ndroppedstats * sizeof(xl_xact_stats_item));
5911  }
5912 
5913  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5914  {
5915  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5916  if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
5917  XLogRegisterData(unconstify(char *, twophase_gid), strlen(twophase_gid) + 1);
5918  }
5919 
5920  if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5921  XLogRegisterData((char *) (&xl_origin), sizeof(xl_xact_origin));
5922 
5923  if (TransactionIdIsValid(twophase_xid))
5925 
5926  return XLogInsert(RM_XACT_ID, info);
5927 }
#define unconstify(underlying_type, expr)
Definition: c.h:1181
Oid MyDatabaseTableSpace
Definition: globals.c:91
volatile uint32 CritSectionCount
Definition: globals.c:42
Oid MyDatabaseId
Definition: globals.c:89
TimestampTz replorigin_session_origin_timestamp
Definition: origin.c:158
RepOriginId replorigin_session_origin
Definition: origin.c:156
XLogRecPtr replorigin_session_origin_lsn
Definition: origin.c:157
#define InvalidRepOriginId
Definition: origin.h:33
#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK
Definition: xact.h:108
#define XACT_XINFO_HAS_AE_LOCKS
Definition: xact.h:187
#define XLOG_INCLUDE_ORIGIN
Definition: xlog.h:149
void XLogRegisterData(char *data, uint32 len)
Definition: xloginsert.c:351
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:451
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:433
void XLogBeginInsert(void)
Definition: xloginsert.c:150
#define XLR_SPECIAL_REL_UPDATE
Definition: xlogrecord.h:71

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, unconstify, 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 5617 of file xact.c.

5625 {
5626  xl_xact_commit xlrec;
5627  xl_xact_xinfo xl_xinfo;
5628  xl_xact_dbinfo xl_dbinfo;
5629  xl_xact_subxacts xl_subxacts;
5630  xl_xact_relfilelocators xl_relfilelocators;
5631  xl_xact_stats_items xl_dropped_stats;
5632  xl_xact_invals xl_invals;
5633  xl_xact_twophase xl_twophase;
5634  xl_xact_origin xl_origin;
5635  uint8 info;
5636 
5637  Assert(CritSectionCount > 0);
5638 
5639  xl_xinfo.xinfo = 0;
5640 
5641  /* decide between a plain and 2pc commit */
5642  if (!TransactionIdIsValid(twophase_xid))
5643  info = XLOG_XACT_COMMIT;
5644  else
5646 
5647  /* First figure out and collect all the information needed */
5648 
5649  xlrec.xact_time = commit_time;
5650 
5651  if (relcacheInval)
5653  if (forceSyncCommit)
5655  if ((xactflags & XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK))
5656  xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5657 
5658  /*
5659  * Check if the caller would like to ask standbys for immediate feedback
5660  * once this commit is applied.
5661  */
5664 
5665  /*
5666  * Relcache invalidations requires information about the current database
5667  * and so does logical decoding.
5668  */
5669  if (nmsgs > 0 || XLogLogicalInfoActive())
5670  {
5671  xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5672  xl_dbinfo.dbId = MyDatabaseId;
5673  xl_dbinfo.tsId = MyDatabaseTableSpace;
5674  }
5675 
5676  if (nsubxacts > 0)
5677  {
5678  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5679  xl_subxacts.nsubxacts = nsubxacts;
5680  }
5681 
5682  if (nrels > 0)
5683  {
5685  xl_relfilelocators.nrels = nrels;
5686  info |= XLR_SPECIAL_REL_UPDATE;
5687  }
5688 
5689  if (ndroppedstats > 0)
5690  {
5691  xl_xinfo.xinfo |= XACT_XINFO_HAS_DROPPED_STATS;
5692  xl_dropped_stats.nitems = ndroppedstats;
5693  }
5694 
5695  if (nmsgs > 0)
5696  {
5697  xl_xinfo.xinfo |= XACT_XINFO_HAS_INVALS;
5698  xl_invals.nmsgs = nmsgs;
5699  }
5700 
5701  if (TransactionIdIsValid(twophase_xid))
5702  {
5703  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5704  xl_twophase.xid = twophase_xid;
5705  Assert(twophase_gid != NULL);
5706 
5707  if (XLogLogicalInfoActive())
5708  xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
5709  }
5710 
5711  /* dump transaction origin information */
5713  {
5714  xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
5715 
5718  }
5719 
5720  if (xl_xinfo.xinfo != 0)
5721  info |= XLOG_XACT_HAS_INFO;
5722 
5723  /* Then include all the collected data into the commit record. */
5724 
5725  XLogBeginInsert();
5726 
5727  XLogRegisterData((char *) (&xlrec), sizeof(xl_xact_commit));
5728 
5729  if (xl_xinfo.xinfo != 0)
5730  XLogRegisterData((char *) (&xl_xinfo.xinfo), sizeof(xl_xinfo.xinfo));
5731 
5732  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5733  XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
5734 
5735  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5736  {
5737  XLogRegisterData((char *) (&xl_subxacts),
5739  XLogRegisterData((char *) subxacts,
5740  nsubxacts * sizeof(TransactionId));
5741  }
5742 
5743  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILELOCATORS)
5744  {
5745  XLogRegisterData((char *) (&xl_relfilelocators),
5747  XLogRegisterData((char *) rels,
5748  nrels * sizeof(RelFileLocator));
5749  }
5750 
5751  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
5752  {
5753  XLogRegisterData((char *) (&xl_dropped_stats),
5755  XLogRegisterData((char *) droppedstats,
5756  ndroppedstats * sizeof(xl_xact_stats_item));
5757  }
5758 
5759  if (xl_xinfo.xinfo & XACT_XINFO_HAS_INVALS)
5760  {
5761  XLogRegisterData((char *) (&xl_invals), MinSizeOfXactInvals);
5762  XLogRegisterData((char *) msgs,
5763  nmsgs * sizeof(SharedInvalidationMessage));
5764  }
5765 
5766  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5767  {
5768  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5769  if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
5770  XLogRegisterData(unconstify(char *, twophase_gid), strlen(twophase_gid) + 1);
5771  }
5772 
5773  if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5774  XLogRegisterData((char *) (&xl_origin), sizeof(xl_xact_origin));
5775 
5776  /* we allow filtering by xacts */
5778 
5779  return XLogInsert(RM_XACT_ID, info);
5780 }
int synchronous_commit
Definition: xact.c:86
#define XACT_COMPLETION_UPDATE_RELCACHE_FILE
Definition: xact.h:200
#define XACT_COMPLETION_FORCE_SYNC_COMMIT
Definition: xact.h:201
#define XACT_COMPLETION_APPLY_FEEDBACK
Definition: xact.h:199

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, unconstify, 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 83 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactIsoLevel

PGDLLIMPORT int DefaultXactIsoLevel
extern

Definition at line 77 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactReadOnly

PGDLLIMPORT bool DefaultXactReadOnly
extern

Definition at line 80 of file xact.c.

Referenced by StartTransaction().

◆ MyXactFlags

◆ synchronous_commit

PGDLLIMPORT int synchronous_commit
extern

Definition at line 86 of file xact.c.

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

◆ xact_is_sampled

PGDLLIMPORT bool xact_is_sampled
extern

Definition at line 289 of file xact.c.

Referenced by check_log_duration(), and StartTransaction().

◆ XactDeferrable

◆ XactIsoLevel

◆ XactReadOnly