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

Go to the source code of this file.

Data Structures

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

Macros

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

Typedefs

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

Enumerations

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

Functions

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

Variables

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

Macro Definition Documentation

◆ GIDSIZE

#define GIDSIZE   200

Definition at line 31 of file xact.h.

◆ IsolationIsSerializable

#define IsolationIsSerializable ( )    (XactIsoLevel == XACT_SERIALIZABLE)

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

◆ MinSizeOfXactAssignment

#define MinSizeOfXactAssignment   offsetof(xl_xact_assignment, xsub)

Definition at line 225 of file xact.h.

◆ MinSizeOfXactCommit

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

Definition at line 328 of file xact.h.

◆ MinSizeOfXactInvals

#define MinSizeOfXactInvals   offsetof(xl_xact_invals, msgs)

Definition at line 301 of file xact.h.

◆ MinSizeOfXactRelfileLocators

#define MinSizeOfXactRelfileLocators   offsetof(xl_xact_relfilelocators, xlocators)

Definition at line 273 of file xact.h.

◆ MinSizeOfXactStatsItems

#define MinSizeOfXactStatsItems   offsetof(xl_xact_stats_items, items)

Definition at line 294 of file xact.h.

◆ MinSizeOfXactSubxacts

#define MinSizeOfXactSubxacts   offsetof(xl_xact_subxacts, subxacts)

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

◆ XACT_COMPLETION_FORCE_SYNC_COMMIT

#define XACT_COMPLETION_FORCE_SYNC_COMMIT   (1U << 31)

Definition at line 208 of file xact.h.

◆ XACT_COMPLETION_UPDATE_RELCACHE_FILE

#define XACT_COMPLETION_UPDATE_RELCACHE_FILE   (1U << 30)

Definition at line 207 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_FLAGS_PIPELINING

#define XACT_FLAGS_PIPELINING   (1U << 3)

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

◆ XACT_XINFO_HAS_DBINFO

#define XACT_XINFO_HAS_DBINFO   (1U << 0)

Definition at line 188 of file xact.h.

◆ XACT_XINFO_HAS_DROPPED_STATS

#define XACT_XINFO_HAS_DROPPED_STATS   (1U << 8)

Definition at line 196 of file xact.h.

◆ XACT_XINFO_HAS_GID

#define XACT_XINFO_HAS_GID   (1U << 7)

Definition at line 195 of file xact.h.

◆ XACT_XINFO_HAS_INVALS

#define XACT_XINFO_HAS_INVALS   (1U << 3)

Definition at line 191 of file xact.h.

◆ XACT_XINFO_HAS_ORIGIN

#define XACT_XINFO_HAS_ORIGIN   (1U << 5)

Definition at line 193 of file xact.h.

◆ XACT_XINFO_HAS_RELFILELOCATORS

#define XACT_XINFO_HAS_RELFILELOCATORS   (1U << 2)

Definition at line 190 of file xact.h.

◆ XACT_XINFO_HAS_SUBXACTS

#define XACT_XINFO_HAS_SUBXACTS   (1U << 1)

Definition at line 189 of file xact.h.

◆ XACT_XINFO_HAS_TWOPHASE

#define XACT_XINFO_HAS_TWOPHASE   (1U << 4)

Definition at line 192 of file xact.h.

◆ XactCompletionApplyFeedback

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

Definition at line 211 of file xact.h.

◆ XactCompletionForceSyncCommit

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

Definition at line 215 of file xact.h.

◆ XactCompletionRelcacheInitFileInval

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

Definition at line 213 of file xact.h.

◆ XLOG_XACT_ABORT

#define XLOG_XACT_ABORT   0x20

Definition at line 171 of file xact.h.

◆ XLOG_XACT_ABORT_PREPARED

#define XLOG_XACT_ABORT_PREPARED   0x40

Definition at line 173 of file xact.h.

◆ XLOG_XACT_ASSIGNMENT

#define XLOG_XACT_ASSIGNMENT   0x50

Definition at line 174 of file xact.h.

◆ XLOG_XACT_COMMIT

#define XLOG_XACT_COMMIT   0x00

Definition at line 169 of file xact.h.

◆ XLOG_XACT_COMMIT_PREPARED

#define XLOG_XACT_COMMIT_PREPARED   0x30

Definition at line 172 of file xact.h.

◆ XLOG_XACT_HAS_INFO

#define XLOG_XACT_HAS_INFO   0x80

Definition at line 182 of file xact.h.

◆ XLOG_XACT_INVALIDATIONS

#define XLOG_XACT_INVALIDATIONS   0x60

Definition at line 175 of file xact.h.

◆ XLOG_XACT_OPMASK

#define XLOG_XACT_OPMASK   0x70

Definition at line 179 of file xact.h.

◆ XLOG_XACT_PREPARE

#define XLOG_XACT_PREPARE   0x10

Definition at line 170 of file xact.h.

Typedef Documentation

◆ SavedTransactionCharacteristics

◆ SubXactCallback

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

Definition at line 148 of file xact.h.

◆ XactCallback

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

Definition at line 138 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 402 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 140 of file xact.h.

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

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

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

Function Documentation

◆ AbortCurrentTransaction()

void AbortCurrentTransaction ( void  )

Definition at line 3305 of file xact.c.

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

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(), pa_stream_abort(), PostgresMain(), ReorderBufferImmediateInvalidation(), ReorderBufferProcessTXN(), and SnapBuildClearExportedSnapshot().

◆ AbortOutOfAnyTransaction()

void AbortOutOfAnyTransaction ( void  )

Definition at line 4712 of file xact.c.

4713 {
4715 
4716  /* Ensure we're not running in a doomed memory context */
4717  AtAbort_Memory();
4718 
4719  /*
4720  * Get out of any transaction or nested transaction
4721  */
4722  do
4723  {
4724  switch (s->blockState)
4725  {
4726  case TBLOCK_DEFAULT:
4727  if (s->state == TRANS_DEFAULT)
4728  {
4729  /* Not in a transaction, do nothing */
4730  }
4731  else
4732  {
4733  /*
4734  * We can get here after an error during transaction start
4735  * (state will be TRANS_START). Need to clean up the
4736  * incompletely started transaction. First, adjust the
4737  * low-level state to suppress warning message from
4738  * AbortTransaction.
4739  */
4740  if (s->state == TRANS_START)
4741  s->state = TRANS_INPROGRESS;
4742  AbortTransaction();
4744  }
4745  break;
4746  case TBLOCK_STARTED:
4747  case TBLOCK_BEGIN:
4748  case TBLOCK_INPROGRESS:
4751  case TBLOCK_END:
4752  case TBLOCK_ABORT_PENDING:
4753  case TBLOCK_PREPARE:
4754  /* In a transaction, so clean up */
4755  AbortTransaction();
4758  break;
4759  case TBLOCK_ABORT:
4760  case TBLOCK_ABORT_END:
4761 
4762  /*
4763  * AbortTransaction is already done, still need Cleanup.
4764  * However, if we failed partway through running ROLLBACK,
4765  * there will be an active portal running that command, which
4766  * we need to shut down before doing CleanupTransaction.
4767  */
4768  AtAbort_Portals();
4771  break;
4772 
4773  /*
4774  * In a subtransaction, so clean it up and abort parent too
4775  */
4776  case TBLOCK_SUBBEGIN:
4777  case TBLOCK_SUBINPROGRESS:
4778  case TBLOCK_SUBRELEASE:
4779  case TBLOCK_SUBCOMMIT:
4781  case TBLOCK_SUBRESTART:
4784  s = CurrentTransactionState; /* changed by pop */
4785  break;
4786 
4787  case TBLOCK_SUBABORT:
4788  case TBLOCK_SUBABORT_END:
4790  /* As above, but AbortSubTransaction already done */
4791  if (s->curTransactionOwner)
4792  {
4793  /* As in TBLOCK_ABORT, might have a live portal to zap */
4798  }
4800  s = CurrentTransactionState; /* changed by pop */
4801  break;
4802  }
4803  } while (s->blockState != TBLOCK_DEFAULT);
4804 
4805  /* Should be out of all subxacts now */
4806  Assert(s->parent == NULL);
4807 
4808  /* If we didn't actually have anything to do, revert to TopMemoryContext */
4809  AtCleanup_Memory();
4810 }
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:192
struct TransactionStateData * parent
Definition: xact.c:212
ResourceOwner curTransactionOwner
Definition: xact.c:200
static void AtCleanup_Memory(void)
Definition: xact.c:1922
static void AtAbort_Memory(void)
Definition: xact.c:1832

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

4173 {
4175 
4176  /*
4177  * If we are in STARTED state (that is, no transaction block is open),
4178  * switch to IMPLICIT_INPROGRESS state, creating an implicit transaction
4179  * block.
4180  *
4181  * For caller convenience, we consider all other transaction states as
4182  * legal here; otherwise the caller would need its own state check, which
4183  * seems rather pointless.
4184  */
4185  if (s->blockState == TBLOCK_STARTED)
4187 }

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

Referenced by exec_simple_query().

◆ BeginInternalSubTransaction()

void BeginInternalSubTransaction ( const char *  name)

Definition at line 4540 of file xact.c.

4541 {
4543 
4544  /*
4545  * Workers synchronize transaction state at the beginning of each parallel
4546  * operation, so we can't account for new subtransactions after that
4547  * point. We might be able to make an exception for the type of
4548  * subtransaction established by this function, which is typically used in
4549  * contexts where we're going to release or roll back the subtransaction
4550  * before proceeding further, so that no enduring change to the
4551  * transaction state occurs. For now, however, we prohibit this case along
4552  * with all the others.
4553  */
4554  if (IsInParallelMode())
4555  ereport(ERROR,
4556  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4557  errmsg("cannot start subtransactions during a parallel operation")));
4558 
4559  switch (s->blockState)
4560  {
4561  case TBLOCK_STARTED:
4562  case TBLOCK_INPROGRESS:
4564  case TBLOCK_END:
4565  case TBLOCK_PREPARE:
4566  case TBLOCK_SUBINPROGRESS:
4567  /* Normal subtransaction start */
4568  PushTransaction();
4569  s = CurrentTransactionState; /* changed by push */
4570 
4571  /*
4572  * Savepoint names, like the TransactionState block itself, live
4573  * in TopTransactionContext.
4574  */
4575  if (name)
4577  break;
4578 
4579  /* These cases are invalid. */
4580  case TBLOCK_DEFAULT:
4581  case TBLOCK_BEGIN:
4583  case TBLOCK_SUBBEGIN:
4584  case TBLOCK_SUBRELEASE:
4585  case TBLOCK_SUBCOMMIT:
4586  case TBLOCK_ABORT:
4587  case TBLOCK_SUBABORT:
4588  case TBLOCK_ABORT_END:
4589  case TBLOCK_SUBABORT_END:
4590  case TBLOCK_ABORT_PENDING:
4592  case TBLOCK_SUBRESTART:
4594  elog(FATAL, "BeginInternalSubTransaction: unexpected state %s",
4596  break;
4597  }
4598 
4601 }
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define FATAL
Definition: elog.h:41
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
MemoryContext TopTransactionContext
Definition: mcxt.c:146
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1631
const char * name
static void PushTransaction(void)
Definition: xact.c:5249
void StartTransactionCommand(void)
Definition: xact.c:2937
bool IsInParallelMode(void)
Definition: xact.c:1069
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5529
void CommitTransactionCommand(void)
Definition: xact.c:3034

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

3771 {
3773 
3774  switch (s->blockState)
3775  {
3776  /*
3777  * We are not inside a transaction block, so allow one to begin.
3778  */
3779  case TBLOCK_STARTED:
3780  s->blockState = TBLOCK_BEGIN;
3781  break;
3782 
3783  /*
3784  * BEGIN converts an implicit transaction block to a regular one.
3785  * (Note that we allow this even if we've already done some
3786  * commands, which is a bit odd but matches historical practice.)
3787  */
3789  s->blockState = TBLOCK_BEGIN;
3790  break;
3791 
3792  /*
3793  * Already a transaction block in progress.
3794  */
3795  case TBLOCK_INPROGRESS:
3797  case TBLOCK_SUBINPROGRESS:
3798  case TBLOCK_ABORT:
3799  case TBLOCK_SUBABORT:
3800  ereport(WARNING,
3801  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3802  errmsg("there is already a transaction in progress")));
3803  break;
3804 
3805  /* These cases are invalid. */
3806  case TBLOCK_DEFAULT:
3807  case TBLOCK_BEGIN:
3808  case TBLOCK_SUBBEGIN:
3809  case TBLOCK_END:
3810  case TBLOCK_SUBRELEASE:
3811  case TBLOCK_SUBCOMMIT:
3812  case TBLOCK_ABORT_END:
3813  case TBLOCK_SUBABORT_END:
3814  case TBLOCK_ABORT_PENDING:
3816  case TBLOCK_SUBRESTART:
3818  case TBLOCK_PREPARE:
3819  elog(FATAL, "BeginTransactionBlock: unexpected state %s",
3821  break;
3822  }
3823 }
#define WARNING
Definition: elog.h:36

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

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

◆ CommandCounterIncrement()

void CommandCounterIncrement ( void  )

Definition at line 1078 of file xact.c.

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

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(), ATAddCheckNNConstraint(), ATExecAddColumn(), ATExecAlterColumnType(), ATExecCmd(), ATExecDropColumn(), ATExecDropExpression(), ATExecDropIdentity(), ATExecSetCompression(), ATExecSetTableSpace(), ATExecSetTableSpaceNoStorage(), ATInheritAdjustNotNulls(), 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(), DefineIndex(), DefineRelation(), DefineVirtualRelation(), deleteOneObject(), DetachPartitionFinalize(), DropClonedTriggersFromPartition(), dropconstraint_internal(), DropRole(), end_replication_step(), EventTriggerDDLCommandEnd(), EventTriggerDDLCommandStart(), EventTriggerInvoke(), EventTriggerSQLDrop(), EventTriggerTableRewrite(), exec_eval_simple_expr(), exec_execute_message(), exec_parse_message(), exec_simple_query(), ExecGrant_common(), ExecGrant_Largeobject(), ExecGrant_Parameter(), ExecGrant_Relation(), execute_sql_string(), ExplainOnePlan(), finish_heap_swap(), fmgr_sql(), hashadjustmembers(), ImportForeignSchema(), index_build(), index_create(), IndexSetParentIndex(), InitTempTableNamespace(), inv_create(), inv_drop(), inv_truncate(), inv_write(), LogicalRepSyncTableStart(), make_new_heap(), makeConfigurationDependencies(), moveArrayTypeName(), objectNamesToOids(), OperatorShellMake(), OperatorUpd(), pg_import_system_collations(), PortalRunMulti(), ProcedureCreate(), process_syncing_tables_for_apply(), ProcessUtilitySlow(), recordExtensionInitPrivWorker(), reindex_index(), reindex_relation(), ReindexRelationConcurrently(), RelationSetNewRelfilenumber(), RemoveRoleFromObjectPolicy(), RenumberEnumType(), replorigin_create(), replorigin_drop_by_name(), ri_PerformCheck(), SetDefaultACL(), SetMatViewPopulatedState(), shdepReassignOwned(), SPI_cursor_open_internal(), standard_ProcessUtility(), StoreConstraints(), StorePartitionBound(), tryAttachPartitionForeignKey(), vacuum(), and validatePartitionedIndex().

◆ CommitTransactionCommand()

void CommitTransactionCommand ( void  )

Definition at line 3034 of file xact.c.

3035 {
3038 
3039  /* Must save in case we need to restore below */
3041 
3042  switch (s->blockState)
3043  {
3044  /*
3045  * These shouldn't happen. TBLOCK_DEFAULT means the previous
3046  * StartTransactionCommand didn't set the STARTED state
3047  * appropriately, while TBLOCK_PARALLEL_INPROGRESS should be ended
3048  * by EndParallelWorkerTransaction(), not this function.
3049  */
3050  case TBLOCK_DEFAULT:
3052  elog(FATAL, "CommitTransactionCommand: unexpected state %s",
3054  break;
3055 
3056  /*
3057  * If we aren't in a transaction block, just do our usual
3058  * transaction commit, and return to the idle state.
3059  */
3060  case TBLOCK_STARTED:
3063  break;
3064 
3065  /*
3066  * We are completing a "BEGIN TRANSACTION" command, so we change
3067  * to the "transaction block in progress" state and return. (We
3068  * assume the BEGIN did nothing to the database, so we need no
3069  * CommandCounterIncrement.)
3070  */
3071  case TBLOCK_BEGIN:
3073  break;
3074 
3075  /*
3076  * This is the case when we have finished executing a command
3077  * someplace within a transaction block. We increment the command
3078  * counter and return.
3079  */
3080  case TBLOCK_INPROGRESS:
3082  case TBLOCK_SUBINPROGRESS:
3084  break;
3085 
3086  /*
3087  * We are completing a "COMMIT" command. Do it and return to the
3088  * idle state.
3089  */
3090  case TBLOCK_END:
3093  if (s->chain)
3094  {
3095  StartTransaction();
3097  s->chain = false;
3099  }
3100  break;
3101 
3102  /*
3103  * Here we are in the middle of a transaction block but one of the
3104  * commands caused an abort so we do nothing but remain in the
3105  * abort state. Eventually we will get a ROLLBACK command.
3106  */
3107  case TBLOCK_ABORT:
3108  case TBLOCK_SUBABORT:
3109  break;
3110 
3111  /*
3112  * Here we were in an aborted transaction block and we just got
3113  * the ROLLBACK command from the user, so clean up the
3114  * already-aborted transaction and return to the idle state.
3115  */
3116  case TBLOCK_ABORT_END:
3119  if (s->chain)
3120  {
3121  StartTransaction();
3123  s->chain = false;
3125  }
3126  break;
3127 
3128  /*
3129  * Here we were in a perfectly good transaction block but the user
3130  * told us to ROLLBACK anyway. We have to abort the transaction
3131  * and then clean up.
3132  */
3133  case TBLOCK_ABORT_PENDING:
3134  AbortTransaction();
3137  if (s->chain)
3138  {
3139  StartTransaction();
3141  s->chain = false;
3143  }
3144  break;
3145 
3146  /*
3147  * We are completing a "PREPARE TRANSACTION" command. Do it and
3148  * return to the idle state.
3149  */
3150  case TBLOCK_PREPARE:
3153  break;
3154 
3155  /*
3156  * The user issued a SAVEPOINT inside a transaction block. Start a
3157  * subtransaction. (DefineSavepoint already did PushTransaction,
3158  * so as to have someplace to put the SUBBEGIN state.)
3159  */
3160  case TBLOCK_SUBBEGIN:
3163  break;
3164 
3165  /*
3166  * The user issued a RELEASE command, so we end the current
3167  * subtransaction and return to the parent transaction. The parent
3168  * might be ended too, so repeat till we find an INPROGRESS
3169  * transaction or subtransaction.
3170  */
3171  case TBLOCK_SUBRELEASE:
3172  do
3173  {
3175  s = CurrentTransactionState; /* changed by pop */
3176  } while (s->blockState == TBLOCK_SUBRELEASE);
3177 
3180  break;
3181 
3182  /*
3183  * The user issued a COMMIT, so we end the current subtransaction
3184  * hierarchy and perform final commit. We do this by rolling up
3185  * any subtransactions into their parent, which leads to O(N^2)
3186  * operations with respect to resource owners - this isn't that
3187  * bad until we approach a thousands of savepoints but is
3188  * necessary for correctness should after triggers create new
3189  * resource owners.
3190  */
3191  case TBLOCK_SUBCOMMIT:
3192  do
3193  {
3195  s = CurrentTransactionState; /* changed by pop */
3196  } while (s->blockState == TBLOCK_SUBCOMMIT);
3197  /* If we had a COMMIT command, finish off the main xact too */
3198  if (s->blockState == TBLOCK_END)
3199  {
3200  Assert(s->parent == NULL);
3203  if (s->chain)
3204  {
3205  StartTransaction();
3207  s->chain = false;
3209  }
3210  }
3211  else if (s->blockState == TBLOCK_PREPARE)
3212  {
3213  Assert(s->parent == NULL);
3216  }
3217  else
3218  elog(ERROR, "CommitTransactionCommand: unexpected state %s",
3220  break;
3221 
3222  /*
3223  * The current already-failed subtransaction is ending due to a
3224  * ROLLBACK or ROLLBACK TO command, so pop it and recursively
3225  * examine the parent (which could be in any of several states).
3226  */
3227  case TBLOCK_SUBABORT_END:
3230  break;
3231 
3232  /*
3233  * As above, but it's not dead yet, so abort first.
3234  */
3239  break;
3240 
3241  /*
3242  * The current subtransaction is the target of a ROLLBACK TO
3243  * command. Abort and pop it, then start a new subtransaction
3244  * with the same name.
3245  */
3246  case TBLOCK_SUBRESTART:
3247  {
3248  char *name;
3249  int savepointLevel;
3250 
3251  /* save name and keep Cleanup from freeing it */
3252  name = s->name;
3253  s->name = NULL;
3254  savepointLevel = s->savepointLevel;
3255 
3258 
3259  DefineSavepoint(NULL);
3260  s = CurrentTransactionState; /* changed by push */
3261  s->name = name;
3262  s->savepointLevel = savepointLevel;
3263 
3264  /* This is the same as TBLOCK_SUBBEGIN case */
3268  }
3269  break;
3270 
3271  /*
3272  * Same as above, but the subtransaction had already failed, so we
3273  * don't need AbortSubTransaction.
3274  */
3276  {
3277  char *name;
3278  int savepointLevel;
3279 
3280  /* save name and keep Cleanup from freeing it */
3281  name = s->name;
3282  s->name = NULL;
3283  savepointLevel = s->savepointLevel;
3284 
3286 
3287  DefineSavepoint(NULL);
3288  s = CurrentTransactionState; /* changed by push */
3289  s->name = name;
3290  s->savepointLevel = savepointLevel;
3291 
3292  /* This is the same as TBLOCK_SUBBEGIN case */
3296  }
3297  break;
3298  }
3299 }
void SaveTransactionCharacteristics(SavedTransactionCharacteristics *s)
Definition: xact.c:3014
void RestoreTransactionCharacteristics(const SavedTransactionCharacteristics *s)
Definition: xact.c:3022
static void StartTransaction(void)
Definition: xact.c:1993
void DefineSavepoint(const char *name)
Definition: xact.c:4219
static void CommitSubTransaction(void)
Definition: xact.c:4949
void CommandCounterIncrement(void)
Definition: xact.c:1078
static void CommitTransaction(void)
Definition: xact.c:2152
static void PrepareTransaction(void)
Definition: xact.c:2412
static void StartSubTransaction(void)
Definition: xact.c:4912

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_prepare(), 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(), InitializeLogRepWorker(), InitPostgres(), LogicalRepSyncTableStart(), maybe_reread_subscription(), movedb(), pa_start_subtrans(), pa_stream_abort(), ParallelApplyWorkerMain(), ParallelWorkerMain(), pg_attribute_noreturn(), process_syncing_tables_for_apply(), process_syncing_tables_for_sync(), ProcessCatchupInterrupt(), ProcessIncomingNotify(), ReindexMultipleInternal(), ReindexRelationConcurrently(), RemoveTempRelationsCallback(), run_apply_worker(), shell_check_detail(), stream_abort_internal(), stream_stop_internal(), vacuum(), vacuum_rel(), and worker_spi_main().

◆ DefineSavepoint()

void DefineSavepoint ( const char *  name)

Definition at line 4219 of file xact.c.

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

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

◆ EndImplicitTransactionBlock()

void EndImplicitTransactionBlock ( void  )

Definition at line 4197 of file xact.c.

4198 {
4200 
4201  /*
4202  * If we are in IMPLICIT_INPROGRESS state, switch back to STARTED state,
4203  * allowing CommitTransactionCommand to commit whatever happened during
4204  * the implicit transaction block as though it were a single statement.
4205  *
4206  * For caller convenience, we consider all other transaction states as
4207  * legal here; otherwise the caller would need its own state check, which
4208  * seems rather pointless.
4209  */
4212 }

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

Referenced by exec_simple_query().

◆ EndParallelWorkerTransaction()

◆ EndTransactionBlock()

bool EndTransactionBlock ( bool  chain)

Definition at line 3890 of file xact.c.

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

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

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

◆ EnterParallelMode()

void EnterParallelMode ( void  )

◆ EstimateTransactionStateSpace()

Size EstimateTransactionStateSpace ( void  )

Definition at line 5343 of file xact.c.

5344 {
5345  TransactionState s;
5346  Size nxids = 0;
5348 
5349  for (s = CurrentTransactionState; s != NULL; s = s->parent)
5350  {
5352  nxids = add_size(nxids, 1);
5353  nxids = add_size(nxids, s->nChildXids);
5354  }
5355 
5356  return add_size(size, mul_size(sizeof(TransactionId), nxids));
5357 }
uint32 TransactionId
Definition: c.h:641
size_t Size
Definition: c.h:594
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:191
#define FullTransactionIdIsValid(x)
Definition: transam.h:55
#define SerializedTransactionStateHeaderSize
Definition: xact.c:233

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

1129 {
1130  forceSyncCommit = true;
1131 }
static bool forceSyncCommit
Definition: xact.c:287

References forceSyncCommit.

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

◆ GetCurrentCommandId()

CommandId GetCurrentCommandId ( bool  used)

Definition at line 818 of file xact.c.

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

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

504 {
506 
509  return s->fullTransactionId;
510 }
static void AssignTransactionId(TransactionState s)
Definition: xact.c:626

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

◆ GetCurrentFullTransactionIdIfAny()

FullTransactionId GetCurrentFullTransactionIdIfAny ( void  )

Definition at line 521 of file xact.c.

522 {
524 }

References CurrentTransactionState, and TransactionStateData::fullTransactionId.

◆ GetCurrentStatementStartTimestamp()

TimestampTz GetCurrentStatementStartTimestamp ( void  )

Definition at line 864 of file xact.c.

865 {
866  return stmtStartTimestamp;
867 }
static TimestampTz stmtStartTimestamp
Definition: xact.c:275

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

856 {
857  return xactStartTimestamp;
858 }
static TimestampTz xactStartTimestamp
Definition: xact.c:274

References xactStartTimestamp.

Referenced by GetCurrentTimeUsec(), GetSQLCurrentTimestamp(), GetSQLLocalTimestamp(), InitializeParallelDSM(), now(), pg_timezone_abbrevs(), and timetz_zone().

◆ GetCurrentTransactionStopTimestamp()

TimestampTz GetCurrentTransactionStopTimestamp ( void  )

Definition at line 876 of file xact.c.

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

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

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

◆ GetStableLatestTransactionId()

TransactionId GetStableLatestTransactionId ( void  )

Definition at line 598 of file xact.c.

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

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

Referenced by xid_age().

◆ GetTopFullTransactionId()

FullTransactionId GetTopFullTransactionId ( void  )

Definition at line 474 of file xact.c.

475 {
479 }
static TransactionStateData TopTransactionStateData
Definition: xact.c:241
static FullTransactionId XactTopFullTransactionId
Definition: xact.c:125

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

Referenced by pg_current_xact_id().

◆ GetTopFullTransactionIdIfAny()

FullTransactionId GetTopFullTransactionIdIfAny ( void  )

Definition at line 490 of file xact.c.

491 {
493 }

References XactTopFullTransactionId.

Referenced by pg_current_xact_id_if_assigned().

◆ GetTopTransactionId()

◆ GetTopTransactionIdIfAny()

◆ IsAbortedTransactionBlockState()

◆ IsInParallelMode()

◆ IsInTransactionBlock()

bool IsInTransactionBlock ( bool  isTopLevel)

Definition at line 3612 of file xact.c.

3613 {
3614  /*
3615  * Return true on same conditions that would make
3616  * PreventInTransactionBlock error out
3617  */
3618  if (IsTransactionBlock())
3619  return true;
3620 
3621  if (IsSubTransaction())
3622  return true;
3623 
3625  return true;
3626 
3627  if (!isTopLevel)
3628  return true;
3629 
3632  return true;
3633 
3634  return false;
3635 }
bool IsSubTransaction(void)
Definition: xact.c:4889
bool IsTransactionBlock(void)
Definition: xact.c:4816
int MyXactFlags
Definition: xact.c:136
#define XACT_FLAGS_PIPELINING
Definition: xact.h:121

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

Referenced by vacuum().

◆ IsSubTransaction()

◆ IsSubxactTopXidLogPending()

bool IsSubxactTopXidLogPending ( void  )

Definition at line 550 of file xact.c.

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

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

Referenced by MarkSubxactTopXidLogged(), and XLogRecordAssemble().

◆ IsTransactionBlock()

◆ IsTransactionOrTransactionBlock()

◆ IsTransactionState()

bool IsTransactionState ( void  )

Definition at line 378 of file xact.c.

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

References CurrentTransactionState, TransactionStateData::state, and TRANS_INPROGRESS.

Referenced by apply_handle_commit_internal(), apply_handle_origin(), 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(), ensure_last_message(), FetchTableStates(), InitializeClientEncoding(), IsSubxactTopXidLogPending(), LogicalRepApplyLoop(), LogLogicalMessage(), maybe_reread_subscription(), pa_send_data(), pa_start_subtrans(), 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(), SocketBackend(), and stream_stop_internal().

◆ MarkCurrentTransactionIdLoggedIfAny()

void MarkCurrentTransactionIdLoggedIfAny ( void  )

◆ MarkSubxactTopXidLogged()

void MarkSubxactTopXidLogged ( void  )

Definition at line 582 of file xact.c.

583 {
585 
587 }
bool IsSubxactTopXidLogPending(void)
Definition: xact.c:550

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:332
Oid tsId
Definition: xact.h:258
Oid dbId
Definition: xact.h:257
TimestampTz origin_timestamp
Definition: xact.h:311
XLogRecPtr origin_lsn
Definition: xact.h:310
xl_xact_stats_item * stats
Definition: xact.h:419
RelFileLocator * xlocators
Definition: xact.h:416
TransactionId twophase_xid
Definition: xact.h:421
TimestampTz xact_time
Definition: xact.h:406
TransactionId * subxacts
Definition: xact.h:413
XLogRecPtr origin_lsn
Definition: xact.h:424
char twophase_gid[GIDSIZE]
Definition: xact.h:422
TimestampTz origin_timestamp
Definition: xact.h:425
RelFileLocator xlocators[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:271
xl_xact_stats_item items[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:292
TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:264
int nsubxacts
Definition: xact.h:263
TransactionId xid
Definition: xact.h:305
uint32 xinfo
Definition: xact.h:252
struct xl_xact_stats_item xl_xact_stats_item
#define MinSizeOfXactSubxacts
Definition: xact.h:266
struct xl_xact_dbinfo xl_xact_dbinfo
#define XACT_XINFO_HAS_GID
Definition: xact.h:195
struct xl_xact_origin xl_xact_origin
#define XACT_XINFO_HAS_ORIGIN
Definition: xact.h:193
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:192
#define MinSizeOfXactRelfileLocators
Definition: xact.h:273
#define MinSizeOfXactStatsItems
Definition: xact.h:294
#define XACT_XINFO_HAS_RELFILELOCATORS
Definition: xact.h:190
#define MinSizeOfXactAbort
Definition: xact.h:344
struct xl_xact_xinfo xl_xact_xinfo
#define XACT_XINFO_HAS_DBINFO
Definition: xact.h:188
struct xl_xact_twophase xl_xact_twophase
#define XLOG_XACT_HAS_INFO
Definition: xact.h:182
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:189
#define XACT_XINFO_HAS_DROPPED_STATS
Definition: xact.h:196

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:316
SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:299
int nmsgs
Definition: xact.h:298
xl_xact_stats_item * stats
Definition: xact.h:386
TimestampTz xact_time
Definition: xact.h:373
TransactionId twophase_xid
Definition: xact.h:391
RelFileLocator * xlocators
Definition: xact.h:383
TimestampTz origin_timestamp
Definition: xact.h:399
TransactionId * subxacts
Definition: xact.h:380
char twophase_gid[GIDSIZE]
Definition: xact.h:392
XLogRecPtr origin_lsn
Definition: xact.h:398
SharedInvalidationMessage * msgs
Definition: xact.h:389
#define MinSizeOfXactInvals
Definition: xact.h:301
#define MinSizeOfXactCommit
Definition: xact.h:328
#define XACT_XINFO_HAS_INVALS
Definition: xact.h:191

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:800
RelFileLocator * abortlocators
Definition: xact.h:394
xl_xact_stats_item * abortstats
Definition: xact.h:396
TimestampTz prepared_at
Definition: xact.h:352
int32 nabortrels
Definition: xact.h:356
int32 ninvalmsgs
Definition: xact.h:359
int32 ncommitstats
Definition: xact.h:357
TimestampTz origin_timestamp
Definition: xact.h:363
uint16 gidlen
Definition: xact.h:361
int32 nabortstats
Definition: xact.h:358
Oid database
Definition: xact.h:351
XLogRecPtr origin_lsn
Definition: xact.h:362
int32 ncommitrels
Definition: xact.h:355
TransactionId xid
Definition: xact.h:350
int32 nsubxacts
Definition: xact.h:354

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

3839 {
3840  TransactionState s;
3841  bool result;
3842 
3843  /* Set up to commit the current transaction */
3844  result = EndTransactionBlock(false);
3845 
3846  /* If successful, change outer tblock state to PREPARE */
3847  if (result)
3848  {
3850 
3851  while (s->parent != NULL)
3852  s = s->parent;
3853 
3854  if (s->blockState == TBLOCK_END)
3855  {
3856  /* Save GID where PrepareTransaction can find it again */
3858 
3860  }
3861  else
3862  {
3863  /*
3864  * ignore case where we are not in a transaction;
3865  * EndTransactionBlock already issued a warning.
3866  */
3869  /* Don't send back a PREPARE result tag... */
3870  result = false;
3871  }
3872  }
3873 
3874  return result;
3875 }
static char * prepareGID
Definition: xact.c:282
bool EndTransactionBlock(bool chain)
Definition: xact.c:3890

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

3482 {
3483  /*
3484  * xact block already started?
3485  */
3486  if (IsTransactionBlock())
3487  ereport(ERROR,
3488  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3489  /* translator: %s represents an SQL statement name */
3490  errmsg("%s cannot run inside a transaction block",
3491  stmtType)));
3492 
3493  /*
3494  * subtransaction?
3495  */
3496  if (IsSubTransaction())
3497  ereport(ERROR,
3498  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3499  /* translator: %s represents an SQL statement name */
3500  errmsg("%s cannot run inside a subtransaction",
3501  stmtType)));
3502 
3503  /*
3504  * inside a pipeline that has started an implicit transaction?
3505  */
3507  ereport(ERROR,
3508  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3509  /* translator: %s represents an SQL statement name */
3510  errmsg("%s cannot be executed within a pipeline",
3511  stmtType)));
3512 
3513  /*
3514  * inside a function call?
3515  */
3516  if (!isTopLevel)
3517  ereport(ERROR,
3518  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3519  /* translator: %s represents an SQL statement name */
3520  errmsg("%s cannot be executed from a function", stmtType)));
3521 
3522  /* If we got past IsTransactionBlock test, should be in default state */
3525  elog(FATAL, "cannot prevent transaction chain");
3526 
3527  /* All okay. Set the flag to make sure the right thing happens later. */
3529 }
#define XACT_FLAGS_NEEDIMMEDIATECOMMIT
Definition: xact.h:114

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

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

3711 {
3712  SubXactCallbackItem *item;
3713 
3714  item = (SubXactCallbackItem *)
3716  item->callback = callback;
3717  item->arg = arg;
3718  item->next = SubXact_callbacks;
3719  SubXact_callbacks = item;
3720 }
MemoryContext TopMemoryContext
Definition: mcxt.c:141
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1021
void * arg
struct SubXactCallbackItem * next
Definition: xact.c:316
SubXactCallback callback
Definition: xact.c:317
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46
static SubXactCallbackItem * SubXact_callbacks
Definition: xact.c:321

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

3651 {
3652  XactCallbackItem *item;
3653 
3654  item = (XactCallbackItem *)
3656  item->callback = callback;
3657  item->arg = arg;
3658  item->next = Xact_callbacks;
3659  Xact_callbacks = item;
3660 }
struct XactCallbackItem * next
Definition: xact.c:304
void * arg
Definition: xact.c:306
XactCallback callback
Definition: xact.c:305
static XactCallbackItem * Xact_callbacks
Definition: xact.c:309

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

4612 {
4614 
4615  /*
4616  * Workers synchronize transaction state at the beginning of each parallel
4617  * operation, so we can't account for commit of subtransactions after that
4618  * point. This should not happen anyway. Code calling this would
4619  * typically have called BeginInternalSubTransaction() first, failing
4620  * there.
4621  */
4622  if (IsInParallelMode())
4623  ereport(ERROR,
4624  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4625  errmsg("cannot commit subtransactions during a parallel operation")));
4626 
4627  if (s->blockState != TBLOCK_SUBINPROGRESS)
4628  elog(ERROR, "ReleaseCurrentSubTransaction: unexpected state %s",
4630  Assert(s->state == TRANS_INPROGRESS);
4633  s = CurrentTransactionState; /* changed by pop */
4634  Assert(s->state == TRANS_INPROGRESS);
4635 }
MemoryContext CurTransactionContext
Definition: mcxt.c:147
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138

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

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

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

3560 {
3561  CheckTransactionBlock(isTopLevel, true, stmtType);
3562 }
static void CheckTransactionBlock(bool isTopLevel, bool throwError, const char *stmtType)
Definition: xact.c:3568

References CheckTransactionBlock().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

◆ RestoreTransactionCharacteristics()

◆ RollbackAndReleaseCurrentSubTransaction()

void RollbackAndReleaseCurrentSubTransaction ( void  )

Definition at line 4645 of file xact.c.

4646 {
4648 
4649  /*
4650  * Unlike ReleaseCurrentSubTransaction(), this is nominally permitted
4651  * during parallel operations. That's because we may be in the leader,
4652  * recovering from an error thrown while we were in parallel mode. We
4653  * won't reach here in a worker, because BeginInternalSubTransaction()
4654  * will have failed.
4655  */
4656 
4657  switch (s->blockState)
4658  {
4659  /* Must be in a subtransaction */
4660  case TBLOCK_SUBINPROGRESS:
4661  case TBLOCK_SUBABORT:
4662  break;
4663 
4664  /* These cases are invalid. */
4665  case TBLOCK_DEFAULT:
4666  case TBLOCK_STARTED:
4667  case TBLOCK_BEGIN:
4670  case TBLOCK_SUBBEGIN:
4671  case TBLOCK_INPROGRESS:
4672  case TBLOCK_END:
4673  case TBLOCK_SUBRELEASE:
4674  case TBLOCK_SUBCOMMIT:
4675  case TBLOCK_ABORT:
4676  case TBLOCK_ABORT_END:
4677  case TBLOCK_SUBABORT_END:
4678  case TBLOCK_ABORT_PENDING:
4680  case TBLOCK_SUBRESTART:
4682  case TBLOCK_PREPARE:
4683  elog(FATAL, "RollbackAndReleaseCurrentSubTransaction: unexpected state %s",
4685  break;
4686  }
4687 
4688  /*
4689  * Abort the current subtransaction, if needed.
4690  */
4691  if (s->blockState == TBLOCK_SUBINPROGRESS)
4693 
4694  /* And clean it up, too */
4696 
4697  s = CurrentTransactionState; /* changed by pop */
4699  s->blockState == TBLOCK_INPROGRESS ||
4701  s->blockState == TBLOCK_STARTED);
4702 }

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

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

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

◆ SaveTransactionCharacteristics()

◆ SerializeTransactionState()

void SerializeTransactionState ( Size  maxsize,
char *  start_address 
)

Definition at line 5371 of file xact.c.

5372 {
5373  TransactionState s;
5374  Size nxids = 0;
5375  Size i = 0;
5376  TransactionId *workspace;
5378 
5379  result = (SerializedTransactionState *) start_address;
5380 
5381  result->xactIsoLevel = XactIsoLevel;
5382  result->xactDeferrable = XactDeferrable;
5384  result->currentFullTransactionId =
5387 
5388  /*
5389  * If we're running in a parallel worker and launching a parallel worker
5390  * of our own, we can just pass along the information that was passed to
5391  * us.
5392  */
5393  if (nParallelCurrentXids > 0)
5394  {
5396  memcpy(&result->parallelCurrentXids[0], ParallelCurrentXids,
5398  return;
5399  }
5400 
5401  /*
5402  * OK, we need to generate a sorted list of XIDs that our workers should
5403  * view as current. First, figure out how many there are.
5404  */
5405  for (s = CurrentTransactionState; s != NULL; s = s->parent)
5406  {
5408  nxids = add_size(nxids, 1);
5409  nxids = add_size(nxids, s->nChildXids);
5410  }
5412  <= maxsize);
5413 
5414  /* Copy them to our scratch space. */
5415  workspace = palloc(nxids * sizeof(TransactionId));
5416  for (s = CurrentTransactionState; s != NULL; s = s->parent)
5417  {
5419  workspace[i++] = XidFromFullTransactionId(s->fullTransactionId);
5420  if (s->nChildXids > 0)
5421  memcpy(&workspace[i], s->childXids,
5422  s->nChildXids * sizeof(TransactionId));
5423  i += s->nChildXids;
5424  }
5425  Assert(i == nxids);
5426 
5427  /* Sort them. */
5428  qsort(workspace, nxids, sizeof(TransactionId), xidComparator);
5429 
5430  /* Copy data into output area. */
5431  result->nParallelCurrentXids = nxids;
5432  memcpy(&result->parallelCurrentXids[0], workspace,
5433  nxids * sizeof(TransactionId));
5434 }
int i
Definition: isn.c:73
void * palloc(Size size)
Definition: mcxt.c:1226
#define qsort(a, b, c, d)
Definition: port.h:445
FullTransactionId currentFullTransactionId
Definition: xact.c:226
FullTransactionId topFullTransactionId
Definition: xact.c:225
CommandId currentCommandId
Definition: xact.c:227
TransactionId parallelCurrentXids[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.c:229
TransactionId * childXids
Definition: xact.c:201
static int nParallelCurrentXids
Definition: xact.c:126
static TransactionId * ParallelCurrentXids
Definition: xact.c:127
int xidComparator(const void *arg1, const void *arg2)
Definition: xid.c:138

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

845 {
847  xactStartTimestamp = xact_ts;
848  stmtStartTimestamp = stmt_ts;
849 }

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

Referenced by ParallelWorkerMain().

◆ StartParallelWorkerTransaction()

void StartParallelWorkerTransaction ( char *  tstatespace)

◆ StartTransactionCommand()

void StartTransactionCommand ( void  )

Definition at line 2937 of file xact.c.

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

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

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

◆ SubTransactionIsActive()

bool SubTransactionIsActive ( SubTransactionId  subxid)

Definition at line 794 of file xact.c.

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

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

Referenced by fmgr_sql().

◆ TransactionBlockStatusCode()

char TransactionBlockStatusCode ( void  )

Definition at line 4848 of file xact.c.

4849 {
4851 
4852  switch (s->blockState)
4853  {
4854  case TBLOCK_DEFAULT:
4855  case TBLOCK_STARTED:
4856  return 'I'; /* idle --- not in transaction */
4857  case TBLOCK_BEGIN:
4858  case TBLOCK_SUBBEGIN:
4859  case TBLOCK_INPROGRESS:
4862  case TBLOCK_SUBINPROGRESS:
4863  case TBLOCK_END:
4864  case TBLOCK_SUBRELEASE:
4865  case TBLOCK_SUBCOMMIT:
4866  case TBLOCK_PREPARE:
4867  return 'T'; /* in transaction */
4868  case TBLOCK_ABORT:
4869  case TBLOCK_SUBABORT:
4870  case TBLOCK_ABORT_END:
4871  case TBLOCK_SUBABORT_END:
4872  case TBLOCK_ABORT_PENDING:
4874  case TBLOCK_SUBRESTART:
4876  return 'E'; /* in failed transaction */
4877  }
4878 
4879  /* should never get here */
4880  elog(FATAL, "invalid transaction block state: %s",
4882  return 0; /* keep compiler quiet */
4883 }

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

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

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

Referenced by compute_new_xmax_infomask(), Do_MultiXactIdWait(), DoesMultiXactIdConflict(), ExecCheckTupleVisible(), ExecMergeMatched(), ExecOnConflictUpdate(), FreezeMultiXactId(), 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 3723 of file xact.c.

3724 {
3725  SubXactCallbackItem *item;
3726  SubXactCallbackItem *prev;
3727 
3728  prev = NULL;
3729  for (item = SubXact_callbacks; item; prev = item, item = item->next)
3730  {
3731  if (item->callback == callback && item->arg == arg)
3732  {
3733  if (prev)
3734  prev->next = item->next;
3735  else
3736  SubXact_callbacks = item->next;
3737  pfree(item);
3738  break;
3739  }
3740  }
3741 }
void pfree(void *pointer)
Definition: mcxt.c:1456

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

◆ UnregisterXactCallback()

void UnregisterXactCallback ( XactCallback  callback,
void *  arg 
)

Definition at line 3663 of file xact.c.

3664 {
3665  XactCallbackItem *item;
3666  XactCallbackItem *prev;
3667 
3668  prev = NULL;
3669  for (item = Xact_callbacks; item; prev = item, item = item->next)
3670  {
3671  if (item->callback == callback && item->arg == arg)
3672  {
3673  if (prev)
3674  prev->next = item->next;
3675  else
3676  Xact_callbacks = item->next;
3677  pfree(item);
3678  break;
3679  }
3680  }
3681 }

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

◆ UserAbortTransactionBlock()

void UserAbortTransactionBlock ( bool  chain)

Definition at line 4050 of file xact.c.

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

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

3554 {
3555  CheckTransactionBlock(isTopLevel, false, stmtType);
3556 }

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:493
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:220
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:172
#define XLOG_XACT_INVALIDATIONS
Definition: xact.h:175
#define XLOG_XACT_PREPARE
Definition: xact.h:170
#define XLOG_XACT_COMMIT
Definition: xact.h:169
#define XLOG_XACT_OPMASK
Definition: xact.h:179
#define XLOG_XACT_ABORT
Definition: xact.h:171
#define XLOG_XACT_ASSIGNMENT
Definition: xact.h:174
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:173
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:413
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:410
#define XLogRecGetData(decoder)
Definition: xlogreader.h:415

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

◆ xact_identify()

const char* xact_identify ( uint8  info)

Definition at line 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 6185 of file xact.c.

6186 {
6187  uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
6188 
6189  /* Backup blocks are not used in xact records */
6190  Assert(!XLogRecHasAnyBlockRefs(record));
6191 
6192  if (info == XLOG_XACT_COMMIT)
6193  {
6194  xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6195  xl_xact_parsed_commit parsed;
6196 
6197  ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6198  xact_redo_commit(&parsed, XLogRecGetXid(record),
6199  record->EndRecPtr, XLogRecGetOrigin(record));
6200  }
6201  else if (info == XLOG_XACT_COMMIT_PREPARED)
6202  {
6203  xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6204  xl_xact_parsed_commit parsed;
6205 
6206  ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6207  xact_redo_commit(&parsed, parsed.twophase_xid,
6208  record->EndRecPtr, XLogRecGetOrigin(record));
6209 
6210  /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6211  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6212  PrepareRedoRemove(parsed.twophase_xid, false);
6213  LWLockRelease(TwoPhaseStateLock);
6214  }
6215  else if (info == XLOG_XACT_ABORT)
6216  {
6217  xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6218  xl_xact_parsed_abort parsed;
6219 
6220  ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6221  xact_redo_abort(&parsed, XLogRecGetXid(record),
6222  record->EndRecPtr, XLogRecGetOrigin(record));
6223  }
6224  else if (info == XLOG_XACT_ABORT_PREPARED)
6225  {
6226  xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6227  xl_xact_parsed_abort parsed;
6228 
6229  ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6230  xact_redo_abort(&parsed, parsed.twophase_xid,
6231  record->EndRecPtr, XLogRecGetOrigin(record));
6232 
6233  /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6234  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6235  PrepareRedoRemove(parsed.twophase_xid, false);
6236  LWLockRelease(TwoPhaseStateLock);
6237  }
6238  else if (info == XLOG_XACT_PREPARE)
6239  {
6240  /*
6241  * Store xid and start/end pointers of the WAL record in TwoPhaseState
6242  * gxact entry.
6243  */
6244  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6246  record->ReadRecPtr,
6247  record->EndRecPtr,
6248  XLogRecGetOrigin(record));
6249  LWLockRelease(TwoPhaseStateLock);
6250  }
6251  else if (info == XLOG_XACT_ASSIGNMENT)
6252  {
6254 
6257  xlrec->nsubxacts, xlrec->xsub);
6258  }
6259  else if (info == XLOG_XACT_INVALIDATIONS)
6260  {
6261  /*
6262  * XXX we do ignore this for now, what matters are invalidations
6263  * written into the commit record.
6264  */
6265  }
6266  else
6267  elog(PANIC, "xact_redo: unknown op code %u", info);
6268 }
#define PANIC
Definition: elog.h:42
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1195
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1808
@ LW_EXCLUSIVE
Definition: lwlock.h:116
void ProcArrayApplyXidAssignment(TransactionId topxid, int nsubxids, TransactionId *subxids)
Definition: procarray.c:1299
XLogRecPtr EndRecPtr
Definition: xlogreader.h:207
XLogRecPtr ReadRecPtr
Definition: xlogreader.h:206
TransactionId xsub[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:222
void PrepareRedoRemove(TransactionId xid, bool giveWarning)
Definition: twophase.c:2558
void PrepareRedoAdd(char *buf, XLogRecPtr start_lsn, XLogRecPtr end_lsn, RepOriginId origin_id)
Definition: twophase.c:2456
static void xact_redo_commit(xl_xact_parsed_commit *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:5952
static void xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:6106
void ParseCommitRecord(uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *parsed)
Definition: xactdesc.c:35
void ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
Definition: xactdesc.c:141
#define XLogRecGetXid(decoder)
Definition: xlogreader.h:412
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:417
HotStandbyState standbyState
Definition: xlogutils.c: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 5612 of file xact.c.

5613 {
5615 
5616  if (s->nChildXids == 0)
5617  *ptr = NULL;
5618  else
5619  *ptr = s->childXids;
5620 
5621  return s->nChildXids;
5622 }

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

5814 {
5815  xl_xact_abort xlrec;
5816  xl_xact_xinfo xl_xinfo;
5817  xl_xact_subxacts xl_subxacts;
5818  xl_xact_relfilelocators xl_relfilelocators;
5819  xl_xact_stats_items xl_dropped_stats;
5820  xl_xact_twophase xl_twophase;
5821  xl_xact_dbinfo xl_dbinfo;
5822  xl_xact_origin xl_origin;
5823 
5824  uint8 info;
5825 
5826  Assert(CritSectionCount > 0);
5827 
5828  xl_xinfo.xinfo = 0;
5829 
5830  /* decide between a plain and 2pc abort */
5831  if (!TransactionIdIsValid(twophase_xid))
5832  info = XLOG_XACT_ABORT;
5833  else
5834  info = XLOG_XACT_ABORT_PREPARED;
5835 
5836 
5837  /* First figure out and collect all the information needed */
5838 
5839  xlrec.xact_time = abort_time;
5840 
5841  if ((xactflags & XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK))
5842  xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5843 
5844  if (nsubxacts > 0)
5845  {
5846  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5847  xl_subxacts.nsubxacts = nsubxacts;
5848  }
5849 
5850  if (nrels > 0)
5851  {
5853  xl_relfilelocators.nrels = nrels;
5854  info |= XLR_SPECIAL_REL_UPDATE;
5855  }
5856 
5857  if (ndroppedstats > 0)
5858  {
5859  xl_xinfo.xinfo |= XACT_XINFO_HAS_DROPPED_STATS;
5860  xl_dropped_stats.nitems = ndroppedstats;
5861  }
5862 
5863  if (TransactionIdIsValid(twophase_xid))
5864  {
5865  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5866  xl_twophase.xid = twophase_xid;
5867  Assert(twophase_gid != NULL);
5868 
5869  if (XLogLogicalInfoActive())
5870  xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
5871  }
5872 
5873  if (TransactionIdIsValid(twophase_xid) && XLogLogicalInfoActive())
5874  {
5875  xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5876  xl_dbinfo.dbId = MyDatabaseId;
5877  xl_dbinfo.tsId = MyDatabaseTableSpace;
5878  }
5879 
5880  /*
5881  * Dump transaction origin information. We need this during recovery to
5882  * update the replication origin progress.
5883  */
5885  {
5886  xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
5887 
5890  }
5891 
5892  if (xl_xinfo.xinfo != 0)
5893  info |= XLOG_XACT_HAS_INFO;
5894 
5895  /* Then include all the collected data into the abort record. */
5896 
5897  XLogBeginInsert();
5898 
5899  XLogRegisterData((char *) (&xlrec), MinSizeOfXactAbort);
5900 
5901  if (xl_xinfo.xinfo != 0)
5902  XLogRegisterData((char *) (&xl_xinfo), sizeof(xl_xinfo));
5903 
5904  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5905  XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
5906 
5907  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5908  {
5909  XLogRegisterData((char *) (&xl_subxacts),
5911  XLogRegisterData((char *) subxacts,
5912  nsubxacts * sizeof(TransactionId));
5913  }
5914 
5915  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILELOCATORS)
5916  {
5917  XLogRegisterData((char *) (&xl_relfilelocators),
5919  XLogRegisterData((char *) rels,
5920  nrels * sizeof(RelFileLocator));
5921  }
5922 
5923  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
5924  {
5925  XLogRegisterData((char *) (&xl_dropped_stats),
5927  XLogRegisterData((char *) droppedstats,
5928  ndroppedstats * sizeof(xl_xact_stats_item));
5929  }
5930 
5931  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5932  {
5933  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5934  if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
5935  XLogRegisterData(unconstify(char *, twophase_gid), strlen(twophase_gid) + 1);
5936  }
5937 
5938  if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5939  XLogRegisterData((char *) (&xl_origin), sizeof(xl_xact_origin));
5940 
5941  /* Include the replication origin */
5943 
5944  return XLogInsert(RM_XACT_ID, info);
5945 }
#define unconstify(underlying_type, expr)
Definition: c.h:1255
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:194
#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:461
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:443
void XLogBeginInsert(void)
Definition: xloginsert.c:150
#define XLR_SPECIAL_REL_UPDATE
Definition: xlogrecord.h:82

References Assert(), CritSectionCount, xl_xact_dbinfo::dbId, InvalidRepOriginId, MinSizeOfXactAbort, MinSizeOfXactRelfileLocators, MinSizeOfXactStatsItems, MinSizeOfXactSubxacts, MyDatabaseId, MyDatabaseTableSpace, xl_xact_stats_items::nitems, xl_xact_relfilelocators::nrels, xl_xact_subxacts::nsubxacts, xl_xact_origin::origin_lsn, xl_xact_origin::origin_timestamp, replorigin_session_origin, replorigin_session_origin_lsn, replorigin_session_origin_timestamp, TransactionIdIsValid, xl_xact_dbinfo::tsId, 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 5636 of file xact.c.

5644 {
5645  xl_xact_commit xlrec;
5646  xl_xact_xinfo xl_xinfo;
5647  xl_xact_dbinfo xl_dbinfo;
5648  xl_xact_subxacts xl_subxacts;
5649  xl_xact_relfilelocators xl_relfilelocators;
5650  xl_xact_stats_items xl_dropped_stats;
5651  xl_xact_invals xl_invals;
5652  xl_xact_twophase xl_twophase;
5653  xl_xact_origin xl_origin;
5654  uint8 info;
5655 
5656  Assert(CritSectionCount > 0);
5657 
5658  xl_xinfo.xinfo = 0;
5659 
5660  /* decide between a plain and 2pc commit */
5661  if (!TransactionIdIsValid(twophase_xid))
5662  info = XLOG_XACT_COMMIT;
5663  else
5665 
5666  /* First figure out and collect all the information needed */
5667 
5668  xlrec.xact_time = commit_time;
5669 
5670  if (relcacheInval)
5672  if (forceSyncCommit)
5674  if ((xactflags & XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK))
5675  xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5676 
5677  /*
5678  * Check if the caller would like to ask standbys for immediate feedback
5679  * once this commit is applied.
5680  */
5683 
5684  /*
5685  * Relcache invalidations requires information about the current database
5686  * and so does logical decoding.
5687  */
5688  if (nmsgs > 0 || XLogLogicalInfoActive())
5689  {
5690  xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5691  xl_dbinfo.dbId = MyDatabaseId;
5692  xl_dbinfo.tsId = MyDatabaseTableSpace;
5693  }
5694 
5695  if (nsubxacts > 0)
5696  {
5697  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5698  xl_subxacts.nsubxacts = nsubxacts;
5699  }
5700 
5701  if (nrels > 0)
5702  {
5704  xl_relfilelocators.nrels = nrels;
5705  info |= XLR_SPECIAL_REL_UPDATE;
5706  }
5707 
5708  if (ndroppedstats > 0)
5709  {
5710  xl_xinfo.xinfo |= XACT_XINFO_HAS_DROPPED_STATS;
5711  xl_dropped_stats.nitems = ndroppedstats;
5712  }
5713 
5714  if (nmsgs > 0)
5715  {
5716  xl_xinfo.xinfo |= XACT_XINFO_HAS_INVALS;
5717  xl_invals.nmsgs = nmsgs;
5718  }
5719 
5720  if (TransactionIdIsValid(twophase_xid))
5721  {
5722  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5723  xl_twophase.xid = twophase_xid;
5724  Assert(twophase_gid != NULL);
5725 
5726  if (XLogLogicalInfoActive())
5727  xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
5728  }
5729 
5730  /* dump transaction origin information */
5732  {
5733  xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
5734 
5737  }
5738 
5739  if (xl_xinfo.xinfo != 0)
5740  info |= XLOG_XACT_HAS_INFO;
5741 
5742  /* Then include all the collected data into the commit record. */
5743 
5744  XLogBeginInsert();
5745 
5746  XLogRegisterData((char *) (&xlrec), sizeof(xl_xact_commit));
5747 
5748  if (xl_xinfo.xinfo != 0)
5749  XLogRegisterData((char *) (&xl_xinfo.xinfo), sizeof(xl_xinfo.xinfo));
5750 
5751  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5752  XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
5753 
5754  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5755  {
5756  XLogRegisterData((char *) (&xl_subxacts),
5758  XLogRegisterData((char *) subxacts,
5759  nsubxacts * sizeof(TransactionId));
5760  }
5761 
5762  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILELOCATORS)
5763  {
5764  XLogRegisterData((char *) (&xl_relfilelocators),
5766  XLogRegisterData((char *) rels,
5767  nrels * sizeof(RelFileLocator));
5768  }
5769 
5770  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
5771  {
5772  XLogRegisterData((char *) (&xl_dropped_stats),
5774  XLogRegisterData((char *) droppedstats,
5775  ndroppedstats * sizeof(xl_xact_stats_item));
5776  }
5777 
5778  if (xl_xinfo.xinfo & XACT_XINFO_HAS_INVALS)
5779  {
5780  XLogRegisterData((char *) (&xl_invals), MinSizeOfXactInvals);
5781  XLogRegisterData((char *) msgs,
5782  nmsgs * sizeof(SharedInvalidationMessage));
5783  }
5784 
5785  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5786  {
5787  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5788  if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
5789  XLogRegisterData(unconstify(char *, twophase_gid), strlen(twophase_gid) + 1);
5790  }
5791 
5792  if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5793  XLogRegisterData((char *) (&xl_origin), sizeof(xl_xact_origin));
5794 
5795  /* we allow filtering by xacts */
5797 
5798  return XLogInsert(RM_XACT_ID, info);
5799 }
int synchronous_commit
Definition: xact.c:87
#define XACT_COMPLETION_UPDATE_RELCACHE_FILE
Definition: xact.h:207
#define XACT_COMPLETION_FORCE_SYNC_COMMIT
Definition: xact.h:208
#define XACT_COMPLETION_APPLY_FEEDBACK
Definition: xact.h:206

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

Referenced by StartTransaction().

◆ DefaultXactIsoLevel

PGDLLIMPORT int DefaultXactIsoLevel
extern

Definition at line 78 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactReadOnly

PGDLLIMPORT bool DefaultXactReadOnly
extern

Definition at line 81 of file xact.c.

Referenced by StartTransaction().

◆ MyXactFlags

◆ synchronous_commit

PGDLLIMPORT int synchronous_commit
extern

Definition at line 87 of file xact.c.

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

◆ xact_is_sampled

PGDLLIMPORT bool xact_is_sampled
extern

Definition at line 290 of file xact.c.

Referenced by check_log_duration(), and StartTransaction().

◆ XactDeferrable

◆ XactIsoLevel

◆ XactReadOnly