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

3426 {
3427  /*
3428  * Repeatedly call AbortCurrentTransactionInternal() until all the work is
3429  * done.
3430  */
3432  {
3433  }
3434 }
static bool AbortCurrentTransactionInternal(void)
Definition: xact.c:3443

References AbortCurrentTransactionInternal().

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

◆ AbortOutOfAnyTransaction()

void AbortOutOfAnyTransaction ( void  )

Definition at line 4849 of file xact.c.

4850 {
4852 
4853  /* Ensure we're not running in a doomed memory context */
4854  AtAbort_Memory();
4855 
4856  /*
4857  * Get out of any transaction or nested transaction
4858  */
4859  do
4860  {
4861  switch (s->blockState)
4862  {
4863  case TBLOCK_DEFAULT:
4864  if (s->state == TRANS_DEFAULT)
4865  {
4866  /* Not in a transaction, do nothing */
4867  }
4868  else
4869  {
4870  /*
4871  * We can get here after an error during transaction start
4872  * (state will be TRANS_START). Need to clean up the
4873  * incompletely started transaction. First, adjust the
4874  * low-level state to suppress warning message from
4875  * AbortTransaction.
4876  */
4877  if (s->state == TRANS_START)
4878  s->state = TRANS_INPROGRESS;
4879  AbortTransaction();
4881  }
4882  break;
4883  case TBLOCK_STARTED:
4884  case TBLOCK_BEGIN:
4885  case TBLOCK_INPROGRESS:
4888  case TBLOCK_END:
4889  case TBLOCK_ABORT_PENDING:
4890  case TBLOCK_PREPARE:
4891  /* In a transaction, so clean up */
4892  AbortTransaction();
4895  break;
4896  case TBLOCK_ABORT:
4897  case TBLOCK_ABORT_END:
4898 
4899  /*
4900  * AbortTransaction is already done, still need Cleanup.
4901  * However, if we failed partway through running ROLLBACK,
4902  * there will be an active portal running that command, which
4903  * we need to shut down before doing CleanupTransaction.
4904  */
4905  AtAbort_Portals();
4908  break;
4909 
4910  /*
4911  * In a subtransaction, so clean it up and abort parent too
4912  */
4913  case TBLOCK_SUBBEGIN:
4914  case TBLOCK_SUBINPROGRESS:
4915  case TBLOCK_SUBRELEASE:
4916  case TBLOCK_SUBCOMMIT:
4918  case TBLOCK_SUBRESTART:
4921  s = CurrentTransactionState; /* changed by pop */
4922  break;
4923 
4924  case TBLOCK_SUBABORT:
4925  case TBLOCK_SUBABORT_END:
4927  /* As above, but AbortSubTransaction already done */
4928  if (s->curTransactionOwner)
4929  {
4930  /* As in TBLOCK_ABORT, might have a live portal to zap */
4935  }
4937  s = CurrentTransactionState; /* changed by pop */
4938  break;
4939  }
4940  } while (s->blockState != TBLOCK_DEFAULT);
4941 
4942  /* Should be out of all subxacts now */
4943  Assert(s->parent == NULL);
4944 
4945  /*
4946  * Revert to TopMemoryContext, to ensure we exit in a well-defined state
4947  * whether there were any transactions to close or not. (Callers that
4948  * don't intend to exit soon should switch to some other context to avoid
4949  * long-term memory leaks.)
4950  */
4952 }
#define Assert(condition)
Definition: c.h:858
MemoryContext TopMemoryContext
Definition: mcxt.c:149
void AtAbort_Portals(void)
Definition: portalmem.c:781
void AtSubAbort_Portals(SubTransactionId mySubid, SubTransactionId parentSubid, ResourceOwner myXactOwner, ResourceOwner parentXactOwner)
Definition: portalmem.c:979
MemoryContextSwitchTo(old_ctx)
TransState state
Definition: xact.c:197
SubTransactionId subTransactionId
Definition: xact.c:194
struct TransactionStateData * parent
Definition: xact.c:216
TBlockState blockState
Definition: xact.c:198
ResourceOwner curTransactionOwner
Definition: xact.c:202
static void CleanupSubTransaction(void)
Definition: xact.c:5364
static void CleanupTransaction(void)
Definition: xact.c:2983
@ TRANS_INPROGRESS
Definition: xact.c:143
@ TRANS_START
Definition: xact.c:142
@ TRANS_DEFAULT
Definition: xact.c:141
static void AbortSubTransaction(void)
Definition: xact.c:5205
static void AtAbort_Memory(void)
Definition: xact.c:1872
@ TBLOCK_DEFAULT
Definition: xact.c:158
@ TBLOCK_SUBABORT_END
Definition: xact.c:178
@ TBLOCK_STARTED
Definition: xact.c:159
@ TBLOCK_SUBCOMMIT
Definition: xact.c:176
@ TBLOCK_IMPLICIT_INPROGRESS
Definition: xact.c:164
@ TBLOCK_ABORT_END
Definition: xact.c:168
@ TBLOCK_PREPARE
Definition: xact.c:170
@ TBLOCK_ABORT_PENDING
Definition: xact.c:169
@ TBLOCK_ABORT
Definition: xact.c:167
@ TBLOCK_SUBRELEASE
Definition: xact.c:175
@ TBLOCK_SUBBEGIN
Definition: xact.c:173
@ TBLOCK_SUBABORT
Definition: xact.c:177
@ TBLOCK_SUBRESTART
Definition: xact.c:180
@ TBLOCK_INPROGRESS
Definition: xact.c:163
@ TBLOCK_END
Definition: xact.c:166
@ TBLOCK_PARALLEL_INPROGRESS
Definition: xact.c:165
@ TBLOCK_SUBABORT_RESTART
Definition: xact.c:181
@ TBLOCK_SUBABORT_PENDING
Definition: xact.c:179
@ TBLOCK_BEGIN
Definition: xact.c:162
@ TBLOCK_SUBINPROGRESS
Definition: xact.c:174
static void AbortTransaction(void)
Definition: xact.c:2787
static TransactionState CurrentTransactionState
Definition: xact.c:258

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

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

◆ BeginImplicitTransactionBlock()

void BeginImplicitTransactionBlock ( void  )

Definition at line 4313 of file xact.c.

4314 {
4316 
4317  /*
4318  * If we are in STARTED state (that is, no transaction block is open),
4319  * switch to IMPLICIT_INPROGRESS state, creating an implicit transaction
4320  * block.
4321  *
4322  * For caller convenience, we consider all other transaction states as
4323  * legal here; otherwise the caller would need its own state check, which
4324  * seems rather pointless.
4325  */
4326  if (s->blockState == TBLOCK_STARTED)
4328 }

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

Referenced by exec_simple_query().

◆ BeginInternalSubTransaction()

void BeginInternalSubTransaction ( const char *  name)

Definition at line 4681 of file xact.c.

4682 {
4684  bool save_ExitOnAnyError = ExitOnAnyError;
4685 
4686  /*
4687  * Errors within this function are improbable, but if one does happen we
4688  * force a FATAL exit. Callers generally aren't prepared to handle losing
4689  * control, and moreover our transaction state is probably corrupted if we
4690  * fail partway through; so an ordinary ERROR longjmp isn't okay.
4691  */
4692  ExitOnAnyError = true;
4693 
4694  /*
4695  * We do not check for parallel mode here. It's permissible to start and
4696  * end "internal" subtransactions while in parallel mode, so long as no
4697  * new XIDs or command IDs are assigned. Enforcement of that occurs in
4698  * AssignTransactionId() and CommandCounterIncrement().
4699  */
4700 
4701  switch (s->blockState)
4702  {
4703  case TBLOCK_STARTED:
4704  case TBLOCK_INPROGRESS:
4707  case TBLOCK_END:
4708  case TBLOCK_PREPARE:
4709  case TBLOCK_SUBINPROGRESS:
4710  /* Normal subtransaction start */
4711  PushTransaction();
4712  s = CurrentTransactionState; /* changed by push */
4713 
4714  /*
4715  * Savepoint names, like the TransactionState block itself, live
4716  * in TopTransactionContext.
4717  */
4718  if (name)
4720  break;
4721 
4722  /* These cases are invalid. */
4723  case TBLOCK_DEFAULT:
4724  case TBLOCK_BEGIN:
4725  case TBLOCK_SUBBEGIN:
4726  case TBLOCK_SUBRELEASE:
4727  case TBLOCK_SUBCOMMIT:
4728  case TBLOCK_ABORT:
4729  case TBLOCK_SUBABORT:
4730  case TBLOCK_ABORT_END:
4731  case TBLOCK_SUBABORT_END:
4732  case TBLOCK_ABORT_PENDING:
4734  case TBLOCK_SUBRESTART:
4736  elog(FATAL, "BeginInternalSubTransaction: unexpected state %s",
4738  break;
4739  }
4740 
4743 
4744  ExitOnAnyError = save_ExitOnAnyError;
4745 }
#define FATAL
Definition: elog.h:41
#define elog(elevel,...)
Definition: elog.h:224
bool ExitOnAnyError
Definition: globals.c:121
MemoryContext TopTransactionContext
Definition: mcxt.c:154
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1683
const char * name
static void PushTransaction(void)
Definition: xact.c:5397
void StartTransactionCommand(void)
Definition: xact.c:3033
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5688
void CommitTransactionCommand(void)
Definition: xact.c:3131

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

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

◆ BeginTransactionBlock()

void BeginTransactionBlock ( void  )

Definition at line 3911 of file xact.c.

3912 {
3914 
3915  switch (s->blockState)
3916  {
3917  /*
3918  * We are not inside a transaction block, so allow one to begin.
3919  */
3920  case TBLOCK_STARTED:
3921  s->blockState = TBLOCK_BEGIN;
3922  break;
3923 
3924  /*
3925  * BEGIN converts an implicit transaction block to a regular one.
3926  * (Note that we allow this even if we've already done some
3927  * commands, which is a bit odd but matches historical practice.)
3928  */
3930  s->blockState = TBLOCK_BEGIN;
3931  break;
3932 
3933  /*
3934  * Already a transaction block in progress.
3935  */
3936  case TBLOCK_INPROGRESS:
3938  case TBLOCK_SUBINPROGRESS:
3939  case TBLOCK_ABORT:
3940  case TBLOCK_SUBABORT:
3941  ereport(WARNING,
3942  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3943  errmsg("there is already a transaction in progress")));
3944  break;
3945 
3946  /* These cases are invalid. */
3947  case TBLOCK_DEFAULT:
3948  case TBLOCK_BEGIN:
3949  case TBLOCK_SUBBEGIN:
3950  case TBLOCK_END:
3951  case TBLOCK_SUBRELEASE:
3952  case TBLOCK_SUBCOMMIT:
3953  case TBLOCK_ABORT_END:
3954  case TBLOCK_SUBABORT_END:
3955  case TBLOCK_ABORT_PENDING:
3957  case TBLOCK_SUBRESTART:
3959  case TBLOCK_PREPARE:
3960  elog(FATAL, "BeginTransactionBlock: unexpected state %s",
3962  break;
3963  }
3964 }
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define WARNING
Definition: elog.h:36
#define ereport(elevel,...)
Definition: elog.h:149

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

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

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

Referenced by _SPI_execute_plan(), acquire_inherited_sample_rows(), addFkRecurseReferenced(), addFkRecurseReferencing(), AddRoleMems(), AlterPublicationOptions(), AlterRole(), ATAddCheckConstraint(), ATExecAddColumn(), ATExecAlterColumnType(), ATExecCmd(), ATExecDropColumn(), ATExecDropConstraint(), ATExecDropExpression(), ATExecDropIdentity(), ATExecMergePartitions(), ATExecSetAccessMethodNoStorage(), ATExecSetCompression(), ATExecSetExpression(), ATExecSetTableSpace(), ATExecSetTableSpaceNoStorage(), ATExecSplitPartition(), ATParseTransformCmd(), ATRewriteTables(), AttachPartitionEnsureIndexes(), btadjustmembers(), CloneFkReferencing(), CommitSubTransaction(), CommitTransactionCommandInternal(), copy_table_data(), create_ctas_internal(), create_toast_table(), CreateFKCheckTrigger(), createForeignKeyActionTriggers(), CreateForeignTable(), CreatePublication(), CreateRole(), CreateSchemaCommand(), CreateTriggerFiringOn(), DefineCollation(), DefineDomain(), DefineIndex(), DefineRelation(), DefineVirtualRelation(), deleteOneObject(), DetachPartitionFinalize(), do_analyze_rel(), DropClonedTriggersFromPartition(), 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(), RemoveRoleFromInitPriv(), RemoveRoleFromObjectPolicy(), RenumberEnumType(), ReplaceRoleInInitPriv(), replorigin_create(), replorigin_drop_by_name(), ri_PerformCheck(), SetDatabaseHasLoginEventTriggers(), SetDefaultACL(), SetMatViewPopulatedState(), shdepReassignOwned(), SPI_cursor_open_internal(), standard_ProcessUtility(), StoreConstraints(), StorePartitionBound(), tryAttachPartitionForeignKey(), vacuum(), and validatePartitionedIndex().

◆ CommitTransactionCommand()

void CommitTransactionCommand ( void  )

Definition at line 3131 of file xact.c.

3132 {
3133  /*
3134  * Repeatedly call CommitTransactionCommandInternal() until all the work
3135  * is done.
3136  */
3138  {
3139  }
3140 }
static bool CommitTransactionCommandInternal(void)
Definition: xact.c:3149

References CommitTransactionCommandInternal().

Referenced by _SPI_commit(), AllTablesyncsReady(), apply_handle_commit_internal(), apply_handle_commit_prepared(), apply_handle_prepare(), apply_handle_prepare_internal(), apply_handle_rollback_prepared(), apply_handle_stream_prepare(), ATExecDetachPartition(), autoprewarm_database_main(), bbsink_server_new(), BeginInternalSubTransaction(), BootstrapModeMain(), clear_subscription_skip_lsn(), cluster_multiple_rels(), DefineIndex(), DisableSubscriptionAndExit(), do_autovacuum(), EventTriggerOnLogin(), exec_replication_command(), finish_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(), synchronize_slots(), vacuum(), vacuum_rel(), validate_remote_info(), and worker_spi_main().

◆ DefineSavepoint()

void DefineSavepoint ( const char *  name)

Definition at line 4360 of file xact.c.

4361 {
4363 
4364  /*
4365  * Workers synchronize transaction state at the beginning of each parallel
4366  * operation, so we can't account for new subtransactions after that
4367  * point. (Note that this check will certainly error out if s->blockState
4368  * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4369  * below.)
4370  */
4372  ereport(ERROR,
4373  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4374  errmsg("cannot define savepoints during a parallel operation")));
4375 
4376  switch (s->blockState)
4377  {
4378  case TBLOCK_INPROGRESS:
4379  case TBLOCK_SUBINPROGRESS:
4380  /* Normal subtransaction start */
4381  PushTransaction();
4382  s = CurrentTransactionState; /* changed by push */
4383 
4384  /*
4385  * Savepoint names, like the TransactionState block itself, live
4386  * in TopTransactionContext.
4387  */
4388  if (name)
4390  break;
4391 
4392  /*
4393  * We disallow savepoint commands in implicit transaction blocks.
4394  * There would be no great difficulty in allowing them so far as
4395  * this module is concerned, but a savepoint seems inconsistent
4396  * with exec_simple_query's behavior of abandoning the whole query
4397  * string upon error. Also, the point of an implicit transaction
4398  * block (as opposed to a regular one) is to automatically close
4399  * after an error, so it's hard to see how a savepoint would fit
4400  * into that.
4401  *
4402  * The error messages for this are phrased as if there were no
4403  * active transaction block at all, which is historical but
4404  * perhaps could be improved.
4405  */
4407  ereport(ERROR,
4408  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4409  /* translator: %s represents an SQL statement name */
4410  errmsg("%s can only be used in transaction blocks",
4411  "SAVEPOINT")));
4412  break;
4413 
4414  /* These cases are invalid. */
4415  case TBLOCK_DEFAULT:
4416  case TBLOCK_STARTED:
4417  case TBLOCK_BEGIN:
4419  case TBLOCK_SUBBEGIN:
4420  case TBLOCK_END:
4421  case TBLOCK_SUBRELEASE:
4422  case TBLOCK_SUBCOMMIT:
4423  case TBLOCK_ABORT:
4424  case TBLOCK_SUBABORT:
4425  case TBLOCK_ABORT_END:
4426  case TBLOCK_SUBABORT_END:
4427  case TBLOCK_ABORT_PENDING:
4429  case TBLOCK_SUBRESTART:
4431  case TBLOCK_PREPARE:
4432  elog(FATAL, "DefineSavepoint: unexpected state %s",
4434  break;
4435  }
4436 }

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

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

◆ EndImplicitTransactionBlock()

void EndImplicitTransactionBlock ( void  )

Definition at line 4338 of file xact.c.

4339 {
4341 
4342  /*
4343  * If we are in IMPLICIT_INPROGRESS state, switch back to STARTED state,
4344  * allowing CommitTransactionCommand to commit whatever happened during
4345  * the implicit transaction block as though it were a single statement.
4346  *
4347  * For caller convenience, we consider all other transaction states as
4348  * legal here; otherwise the caller would need its own state check, which
4349  * seems rather pointless.
4350  */
4353 }

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

Referenced by exec_simple_query().

◆ EndParallelWorkerTransaction()

void EndParallelWorkerTransaction ( void  )

◆ EndTransactionBlock()

bool EndTransactionBlock ( bool  chain)

Definition at line 4031 of file xact.c.

4032 {
4034  bool result = false;
4035 
4036  switch (s->blockState)
4037  {
4038  /*
4039  * We are in a transaction block, so tell CommitTransactionCommand
4040  * to COMMIT.
4041  */
4042  case TBLOCK_INPROGRESS:
4043  s->blockState = TBLOCK_END;
4044  result = true;
4045  break;
4046 
4047  /*
4048  * We are in an implicit transaction block. If AND CHAIN was
4049  * specified, error. Otherwise commit, but issue a warning
4050  * because there was no explicit BEGIN before this.
4051  */
4053  if (chain)
4054  ereport(ERROR,
4055  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4056  /* translator: %s represents an SQL statement name */
4057  errmsg("%s can only be used in transaction blocks",
4058  "COMMIT AND CHAIN")));
4059  else
4060  ereport(WARNING,
4061  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4062  errmsg("there is no transaction in progress")));
4063  s->blockState = TBLOCK_END;
4064  result = true;
4065  break;
4066 
4067  /*
4068  * We are in a failed transaction block. Tell
4069  * CommitTransactionCommand it's time to exit the block.
4070  */
4071  case TBLOCK_ABORT:
4073  break;
4074 
4075  /*
4076  * We are in a live subtransaction block. Set up to subcommit all
4077  * open subtransactions and then commit the main transaction.
4078  */
4079  case TBLOCK_SUBINPROGRESS:
4080  while (s->parent != NULL)
4081  {
4082  if (s->blockState == TBLOCK_SUBINPROGRESS)
4084  else
4085  elog(FATAL, "EndTransactionBlock: unexpected state %s",
4087  s = s->parent;
4088  }
4089  if (s->blockState == TBLOCK_INPROGRESS)
4090  s->blockState = TBLOCK_END;
4091  else
4092  elog(FATAL, "EndTransactionBlock: unexpected state %s",
4094  result = true;
4095  break;
4096 
4097  /*
4098  * Here we are inside an aborted subtransaction. Treat the COMMIT
4099  * as ROLLBACK: set up to abort everything and exit the main
4100  * transaction.
4101  */
4102  case TBLOCK_SUBABORT:
4103  while (s->parent != NULL)
4104  {
4105  if (s->blockState == TBLOCK_SUBINPROGRESS)
4107  else if (s->blockState == TBLOCK_SUBABORT)
4109  else
4110  elog(FATAL, "EndTransactionBlock: unexpected state %s",
4112  s = s->parent;
4113  }
4114  if (s->blockState == TBLOCK_INPROGRESS)
4116  else if (s->blockState == TBLOCK_ABORT)
4118  else
4119  elog(FATAL, "EndTransactionBlock: unexpected state %s",
4121  break;
4122 
4123  /*
4124  * The user issued COMMIT when not inside a transaction. For
4125  * COMMIT without CHAIN, issue a WARNING, staying in
4126  * TBLOCK_STARTED state. The upcoming call to
4127  * CommitTransactionCommand() will then close the transaction and
4128  * put us back into the default state. For COMMIT AND CHAIN,
4129  * error.
4130  */
4131  case TBLOCK_STARTED:
4132  if (chain)
4133  ereport(ERROR,
4134  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4135  /* translator: %s represents an SQL statement name */
4136  errmsg("%s can only be used in transaction blocks",
4137  "COMMIT AND CHAIN")));
4138  else
4139  ereport(WARNING,
4140  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4141  errmsg("there is no transaction in progress")));
4142  result = true;
4143  break;
4144 
4145  /*
4146  * The user issued a COMMIT that somehow ran inside a parallel
4147  * worker. We can't cope with that.
4148  */
4150  ereport(FATAL,
4151  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4152  errmsg("cannot commit during a parallel operation")));
4153  break;
4154 
4155  /* These cases are invalid. */
4156  case TBLOCK_DEFAULT:
4157  case TBLOCK_BEGIN:
4158  case TBLOCK_SUBBEGIN:
4159  case TBLOCK_END:
4160  case TBLOCK_SUBRELEASE:
4161  case TBLOCK_SUBCOMMIT:
4162  case TBLOCK_ABORT_END:
4163  case TBLOCK_SUBABORT_END:
4164  case TBLOCK_ABORT_PENDING:
4166  case TBLOCK_SUBRESTART:
4168  case TBLOCK_PREPARE:
4169  elog(FATAL, "EndTransactionBlock: unexpected state %s",
4171  break;
4172  }
4173 
4175  s->blockState == TBLOCK_END ||
4176  s->blockState == TBLOCK_ABORT_END ||
4178 
4179  s->chain = chain;
4180 
4181  return result;
4182 }

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

5494 {
5495  TransactionState s;
5496  Size nxids = 0;
5498 
5499  for (s = CurrentTransactionState; s != NULL; s = s->parent)
5500  {
5502  nxids = add_size(nxids, 1);
5503  nxids = add_size(nxids, s->nChildXids);
5504  }
5505 
5506  return add_size(size, mul_size(sizeof(TransactionId), nxids));
5507 }
uint32 TransactionId
Definition: c.h:652
size_t Size
Definition: c.h:605
Size add_size(Size s1, Size s2)
Definition: shmem.c:493
Size mul_size(Size s1, Size s2)
Definition: shmem.c:510
static pg_noinline void Size size
Definition: slab.c:607
FullTransactionId fullTransactionId
Definition: xact.c:193
#define FullTransactionIdIsValid(x)
Definition: transam.h:55
#define SerializedTransactionStateHeaderSize
Definition: xact.c:237

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

Referenced by InitializeParallelDSM().

◆ ExitParallelMode()

◆ ForceSyncCommit()

void ForceSyncCommit ( void  )

Definition at line 1150 of file xact.c.

1151 {
1152  forceSyncCommit = true;
1153 }
static bool forceSyncCommit
Definition: xact.c:291

References forceSyncCommit.

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

◆ GetCurrentCommandId()

CommandId GetCurrentCommandId ( bool  used)

Definition at line 827 of file xact.c.

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

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

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

511 {
513 
516  return s->fullTransactionId;
517 }
static void AssignTransactionId(TransactionState s)
Definition: xact.c:633

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

◆ GetCurrentFullTransactionIdIfAny()

FullTransactionId GetCurrentFullTransactionIdIfAny ( void  )

Definition at line 528 of file xact.c.

529 {
531 }

References CurrentTransactionState, and TransactionStateData::fullTransactionId.

◆ GetCurrentStatementStartTimestamp()

TimestampTz GetCurrentStatementStartTimestamp ( void  )

Definition at line 877 of file xact.c.

878 {
879  return stmtStartTimestamp;
880 }
static TimestampTz stmtStartTimestamp
Definition: xact.c:279

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

869 {
870  return xactStartTimestamp;
871 }
static TimestampTz xactStartTimestamp
Definition: xact.c:278

References xactStartTimestamp.

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

◆ GetCurrentTransactionStopTimestamp()

TimestampTz GetCurrentTransactionStopTimestamp ( void  )

Definition at line 889 of file xact.c.

890 {
892 
893  /* should only be called after commit / abort processing */
894  Assert(s->state == TRANS_DEFAULT ||
895  s->state == TRANS_COMMIT ||
896  s->state == TRANS_ABORT ||
897  s->state == TRANS_PREPARE);
898 
899  if (xactStopTimestamp == 0)
901 
902  return xactStopTimestamp;
903 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1655
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:182
static TimestampTz xactStopTimestamp
Definition: xact.c:280
@ TRANS_COMMIT
Definition: xact.c:144
@ TRANS_ABORT
Definition: xact.c:145
@ TRANS_PREPARE
Definition: xact.c:146

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

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

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

Referenced by xid_age().

◆ GetTopFullTransactionId()

FullTransactionId GetTopFullTransactionId ( void  )

Definition at line 481 of file xact.c.

482 {
486 }
static TransactionStateData TopTransactionStateData
Definition: xact.c:245
static FullTransactionId XactTopFullTransactionId
Definition: xact.c:123

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

Referenced by pg_current_xact_id().

◆ GetTopFullTransactionIdIfAny()

FullTransactionId GetTopFullTransactionIdIfAny ( void  )

Definition at line 497 of file xact.c.

498 {
500 }

References XactTopFullTransactionId.

Referenced by pg_current_xact_id_if_assigned().

◆ GetTopTransactionId()

◆ GetTopTransactionIdIfAny()

◆ IsAbortedTransactionBlockState()

◆ IsInParallelMode()

◆ IsInTransactionBlock()

bool IsInTransactionBlock ( bool  isTopLevel)

Definition at line 3753 of file xact.c.

3754 {
3755  /*
3756  * Return true on same conditions that would make
3757  * PreventInTransactionBlock error out
3758  */
3759  if (IsTransactionBlock())
3760  return true;
3761 
3762  if (IsSubTransaction())
3763  return true;
3764 
3766  return true;
3767 
3768  if (!isTopLevel)
3769  return true;
3770 
3773  return true;
3774 
3775  return false;
3776 }
bool IsSubTransaction(void)
Definition: xact.c:5031
bool IsTransactionBlock(void)
Definition: xact.c:4958
int MyXactFlags
Definition: xact.c:134
#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 557 of file xact.c.

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

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

Referenced by MarkSubxactTopXidLogged(), and XLogRecordAssemble().

◆ IsTransactionBlock()

◆ IsTransactionOrTransactionBlock()

◆ IsTransactionState()

bool IsTransactionState ( void  )

Definition at line 385 of file xact.c.

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

References CurrentTransactionState, TransactionStateData::state, and TRANS_INPROGRESS.

Referenced by apply_handle_commit_internal(), apply_handle_origin(), assign_transaction_timeout(), begin_replication_step(), check_client_encoding(), check_default_table_access_method(), check_default_tablespace(), check_default_text_search_config(), check_role(), check_session_authorization(), check_temp_tablespaces(), check_transaction_isolation(), check_transaction_read_only(), clear_subscription_skip_lsn(), 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(), RelationFlushRelation(), RelationIdGetRelation(), RelationInitPhysicalAddr(), RelationReloadNailed(), replorigin_create(), replorigin_drop_by_name(), SearchCatCacheInternal(), SetMultiXactIdLimit(), SetTransactionIdLimit(), SnapBuildClearExportedSnapshot(), SocketBackend(), stream_stop_internal(), synchronize_slots(), and validate_remote_info().

◆ MarkCurrentTransactionIdLoggedIfAny()

void MarkCurrentTransactionIdLoggedIfAny ( void  )

◆ MarkSubxactTopXidLogged()

void MarkSubxactTopXidLogged ( void  )

Definition at line 589 of file xact.c.

590 {
592 
594 }
bool IsSubxactTopXidLogPending(void)
Definition: xact.c:557

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(), SummarizeXactRecord(), xact_decode(), xact_desc_abort(), and xact_redo().

◆ ParseCommitRecord()

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

Definition at line 35 of file xactdesc.c.

36 {
37  char *data = ((char *) xlrec) + MinSizeOfXactCommit;
38 
39  memset(parsed, 0, sizeof(*parsed));
40 
41  parsed->xinfo = 0; /* default, if no XLOG_XACT_HAS_INFO is
42  * present */
43 
44  parsed->xact_time = xlrec->xact_time;
45 
46  if (info & XLOG_XACT_HAS_INFO)
47  {
48  xl_xact_xinfo *xl_xinfo = (xl_xact_xinfo *) data;
49 
50  parsed->xinfo = xl_xinfo->xinfo;
51 
52  data += sizeof(xl_xact_xinfo);
53  }
54 
55  if (parsed->xinfo & XACT_XINFO_HAS_DBINFO)
56  {
57  xl_xact_dbinfo *xl_dbinfo = (xl_xact_dbinfo *) data;
58 
59  parsed->dbId = xl_dbinfo->dbId;
60  parsed->tsId = xl_dbinfo->tsId;
61 
62  data += sizeof(xl_xact_dbinfo);
63  }
64 
65  if (parsed->xinfo & XACT_XINFO_HAS_SUBXACTS)
66  {
67  xl_xact_subxacts *xl_subxacts = (xl_xact_subxacts *) data;
68 
69  parsed->nsubxacts = xl_subxacts->nsubxacts;
70  parsed->subxacts = xl_subxacts->subxacts;
71 
73  data += parsed->nsubxacts * sizeof(TransactionId);
74  }
75 
77  {
79 
80  parsed->nrels = xl_rellocators->nrels;
81  parsed->xlocators = xl_rellocators->xlocators;
82 
84  data += xl_rellocators->nrels * sizeof(RelFileLocator);
85  }
86 
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(), SummarizeXactRecord(), xact_decode(), xact_desc_commit(), and xact_redo().

◆ ParsePrepareRecord()

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

Definition at line 239 of file xactdesc.c.

240 {
241  char *bufptr;
242 
243  bufptr = ((char *) xlrec) + MAXALIGN(sizeof(xl_xact_prepare));
244 
245  memset(parsed, 0, sizeof(*parsed));
246 
247  parsed->xact_time = xlrec->prepared_at;
248  parsed->origin_lsn = xlrec->origin_lsn;
249  parsed->origin_timestamp = xlrec->origin_timestamp;
250  parsed->twophase_xid = xlrec->xid;
251  parsed->dbId = xlrec->database;
252  parsed->nsubxacts = xlrec->nsubxacts;
253  parsed->nrels = xlrec->ncommitrels;
254  parsed->nabortrels = xlrec->nabortrels;
255  parsed->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:811
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 3979 of file xact.c.

3980 {
3981  TransactionState s;
3982  bool result;
3983 
3984  /* Set up to commit the current transaction */
3985  result = EndTransactionBlock(false);
3986 
3987  /* If successful, change outer tblock state to PREPARE */
3988  if (result)
3989  {
3991 
3992  while (s->parent != NULL)
3993  s = s->parent;
3994 
3995  if (s->blockState == TBLOCK_END)
3996  {
3997  /* Save GID where PrepareTransaction can find it again */
3999 
4001  }
4002  else
4003  {
4004  /*
4005  * ignore case where we are not in a transaction;
4006  * EndTransactionBlock already issued a warning.
4007  */
4010  /* Don't send back a PREPARE result tag... */
4011  result = false;
4012  }
4013  }
4014 
4015  return result;
4016 }
static char * prepareGID
Definition: xact.c:286
bool EndTransactionBlock(bool chain)
Definition: xact.c:4031

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

3623 {
3624  /*
3625  * xact block already started?
3626  */
3627  if (IsTransactionBlock())
3628  ereport(ERROR,
3629  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3630  /* translator: %s represents an SQL statement name */
3631  errmsg("%s cannot run inside a transaction block",
3632  stmtType)));
3633 
3634  /*
3635  * subtransaction?
3636  */
3637  if (IsSubTransaction())
3638  ereport(ERROR,
3639  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3640  /* translator: %s represents an SQL statement name */
3641  errmsg("%s cannot run inside a subtransaction",
3642  stmtType)));
3643 
3644  /*
3645  * inside a pipeline that has started an implicit transaction?
3646  */
3648  ereport(ERROR,
3649  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3650  /* translator: %s represents an SQL statement name */
3651  errmsg("%s cannot be executed within a pipeline",
3652  stmtType)));
3653 
3654  /*
3655  * inside a function call?
3656  */
3657  if (!isTopLevel)
3658  ereport(ERROR,
3659  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3660  /* translator: %s represents an SQL statement name */
3661  errmsg("%s cannot be executed from a function", stmtType)));
3662 
3663  /* If we got past IsTransactionBlock test, should be in default state */
3666  elog(FATAL, "cannot prevent transaction chain");
3667 
3668  /* All okay. Set the flag to make sure the right thing happens later. */
3670 }
#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(), CheckAlterSubOption(), cluster(), CreateSubscription(), DiscardAll(), DropSubscription(), exec_replication_command(), ExecDropStmt(), ExecReindex(), ProcessUtilitySlow(), ReindexPartitions(), standard_ProcessUtility(), and vacuum().

◆ RegisterSubXactCallback()

void RegisterSubXactCallback ( SubXactCallback  callback,
void *  arg 
)

Definition at line 3851 of file xact.c.

3852 {
3853  SubXactCallbackItem *item;
3854 
3855  item = (SubXactCallbackItem *)
3857  item->callback = callback;
3858  item->arg = arg;
3859  item->next = SubXact_callbacks;
3860  SubXact_callbacks = item;
3861 }
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1181
void * arg
struct SubXactCallbackItem * next
Definition: xact.c:320
SubXactCallback callback
Definition: xact.c:321
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46
static SubXactCallbackItem * SubXact_callbacks
Definition: xact.c:325

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

3792 {
3793  XactCallbackItem *item;
3794 
3795  item = (XactCallbackItem *)
3797  item->callback = callback;
3798  item->arg = arg;
3799  item->next = Xact_callbacks;
3800  Xact_callbacks = item;
3801 }
struct XactCallbackItem * next
Definition: xact.c:308
void * arg
Definition: xact.c:310
XactCallback callback
Definition: xact.c:309
static XactCallbackItem * Xact_callbacks
Definition: xact.c:313

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

4756 {
4758 
4759  /*
4760  * We do not check for parallel mode here. It's permissible to start and
4761  * end "internal" subtransactions while in parallel mode, so long as no
4762  * new XIDs or command IDs are assigned.
4763  */
4764 
4765  if (s->blockState != TBLOCK_SUBINPROGRESS)
4766  elog(ERROR, "ReleaseCurrentSubTransaction: unexpected state %s",
4768  Assert(s->state == TRANS_INPROGRESS);
4771  s = CurrentTransactionState; /* changed by pop */
4772  Assert(s->state == TRANS_INPROGRESS);
4773 }
MemoryContext CurTransactionContext
Definition: mcxt.c:155
static void CommitSubTransaction(void)
Definition: xact.c:5091

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

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

◆ ReleaseSavepoint()

void ReleaseSavepoint ( const char *  name)

Definition at line 4445 of file xact.c.

4446 {
4448  TransactionState target,
4449  xact;
4450 
4451  /*
4452  * Workers synchronize transaction state at the beginning of each parallel
4453  * operation, so we can't account for transaction state change after that
4454  * point. (Note that this check will certainly error out if s->blockState
4455  * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4456  * below.)
4457  */
4459  ereport(ERROR,
4460  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4461  errmsg("cannot release savepoints during a parallel operation")));
4462 
4463  switch (s->blockState)
4464  {
4465  /*
4466  * We can't release a savepoint if there is no savepoint defined.
4467  */
4468  case TBLOCK_INPROGRESS:
4469  ereport(ERROR,
4470  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4471  errmsg("savepoint \"%s\" does not exist", name)));
4472  break;
4473 
4475  /* See comment about implicit transactions in DefineSavepoint */
4476  ereport(ERROR,
4477  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4478  /* translator: %s represents an SQL statement name */
4479  errmsg("%s can only be used in transaction blocks",
4480  "RELEASE SAVEPOINT")));
4481  break;
4482 
4483  /*
4484  * We are in a non-aborted subtransaction. This is the only valid
4485  * case.
4486  */
4487  case TBLOCK_SUBINPROGRESS:
4488  break;
4489 
4490  /* These cases are invalid. */
4491  case TBLOCK_DEFAULT:
4492  case TBLOCK_STARTED:
4493  case TBLOCK_BEGIN:
4495  case TBLOCK_SUBBEGIN:
4496  case TBLOCK_END:
4497  case TBLOCK_SUBRELEASE:
4498  case TBLOCK_SUBCOMMIT:
4499  case TBLOCK_ABORT:
4500  case TBLOCK_SUBABORT:
4501  case TBLOCK_ABORT_END:
4502  case TBLOCK_SUBABORT_END:
4503  case TBLOCK_ABORT_PENDING:
4505  case TBLOCK_SUBRESTART:
4507  case TBLOCK_PREPARE:
4508  elog(FATAL, "ReleaseSavepoint: unexpected state %s",
4510  break;
4511  }
4512 
4513  for (target = s; PointerIsValid(target); target = target->parent)
4514  {
4515  if (PointerIsValid(target->name) && strcmp(target->name, name) == 0)
4516  break;
4517  }
4518 
4519  if (!PointerIsValid(target))
4520  ereport(ERROR,
4521  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4522  errmsg("savepoint \"%s\" does not exist", name)));
4523 
4524  /* disallow crossing savepoint level boundaries */
4525  if (target->savepointLevel != s->savepointLevel)
4526  ereport(ERROR,
4527  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4528  errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
4529 
4530  /*
4531  * Mark "commit pending" all subtransactions up to the target
4532  * subtransaction. The actual commits will happen when control gets to
4533  * CommitTransactionCommand.
4534  */
4535  xact = CurrentTransactionState;
4536  for (;;)
4537  {
4539  xact->blockState = TBLOCK_SUBRELEASE;
4540  if (xact == target)
4541  break;
4542  xact = xact->parent;
4543  Assert(PointerIsValid(xact));
4544  }
4545 }
#define PointerIsValid(pointer)
Definition: c.h:763

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

3701 {
3702  CheckTransactionBlock(isTopLevel, true, stmtType);
3703 }
static void CheckTransactionBlock(bool isTopLevel, bool throwError, const char *stmtType)
Definition: xact.c:3709

References CheckTransactionBlock().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

◆ RestoreTransactionCharacteristics()

◆ RollbackAndReleaseCurrentSubTransaction()

void RollbackAndReleaseCurrentSubTransaction ( void  )

Definition at line 4783 of file xact.c.

4784 {
4786 
4787  /*
4788  * We do not check for parallel mode here. It's permissible to start and
4789  * end "internal" subtransactions while in parallel mode, so long as no
4790  * new XIDs or command IDs are assigned.
4791  */
4792 
4793  switch (s->blockState)
4794  {
4795  /* Must be in a subtransaction */
4796  case TBLOCK_SUBINPROGRESS:
4797  case TBLOCK_SUBABORT:
4798  break;
4799 
4800  /* These cases are invalid. */
4801  case TBLOCK_DEFAULT:
4802  case TBLOCK_STARTED:
4803  case TBLOCK_BEGIN:
4806  case TBLOCK_SUBBEGIN:
4807  case TBLOCK_INPROGRESS:
4808  case TBLOCK_END:
4809  case TBLOCK_SUBRELEASE:
4810  case TBLOCK_SUBCOMMIT:
4811  case TBLOCK_ABORT:
4812  case TBLOCK_ABORT_END:
4813  case TBLOCK_SUBABORT_END:
4814  case TBLOCK_ABORT_PENDING:
4816  case TBLOCK_SUBRESTART:
4818  case TBLOCK_PREPARE:
4819  elog(FATAL, "RollbackAndReleaseCurrentSubTransaction: unexpected state %s",
4821  break;
4822  }
4823 
4824  /*
4825  * Abort the current subtransaction, if needed.
4826  */
4827  if (s->blockState == TBLOCK_SUBINPROGRESS)
4829 
4830  /* And clean it up, too */
4832 
4833  s = CurrentTransactionState; /* changed by pop */
4835  s->blockState == TBLOCK_INPROGRESS ||
4838  s->blockState == TBLOCK_STARTED);
4839 }

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

4555 {
4557  TransactionState target,
4558  xact;
4559 
4560  /*
4561  * Workers synchronize transaction state at the beginning of each parallel
4562  * operation, so we can't account for transaction state change after that
4563  * point. (Note that this check will certainly error out if s->blockState
4564  * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4565  * below.)
4566  */
4568  ereport(ERROR,
4569  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4570  errmsg("cannot rollback to savepoints during a parallel operation")));
4571 
4572  switch (s->blockState)
4573  {
4574  /*
4575  * We can't rollback to a savepoint if there is no savepoint
4576  * defined.
4577  */
4578  case TBLOCK_INPROGRESS:
4579  case TBLOCK_ABORT:
4580  ereport(ERROR,
4581  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4582  errmsg("savepoint \"%s\" does not exist", name)));
4583  break;
4584 
4586  /* See comment about implicit transactions in DefineSavepoint */
4587  ereport(ERROR,
4588  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4589  /* translator: %s represents an SQL statement name */
4590  errmsg("%s can only be used in transaction blocks",
4591  "ROLLBACK TO SAVEPOINT")));
4592  break;
4593 
4594  /*
4595  * There is at least one savepoint, so proceed.
4596  */
4597  case TBLOCK_SUBINPROGRESS:
4598  case TBLOCK_SUBABORT:
4599  break;
4600 
4601  /* These cases are invalid. */
4602  case TBLOCK_DEFAULT:
4603  case TBLOCK_STARTED:
4604  case TBLOCK_BEGIN:
4606  case TBLOCK_SUBBEGIN:
4607  case TBLOCK_END:
4608  case TBLOCK_SUBRELEASE:
4609  case TBLOCK_SUBCOMMIT:
4610  case TBLOCK_ABORT_END:
4611  case TBLOCK_SUBABORT_END:
4612  case TBLOCK_ABORT_PENDING:
4614  case TBLOCK_SUBRESTART:
4616  case TBLOCK_PREPARE:
4617  elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4619  break;
4620  }
4621 
4622  for (target = s; PointerIsValid(target); target = target->parent)
4623  {
4624  if (PointerIsValid(target->name) && strcmp(target->name, name) == 0)
4625  break;
4626  }
4627 
4628  if (!PointerIsValid(target))
4629  ereport(ERROR,
4630  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4631  errmsg("savepoint \"%s\" does not exist", name)));
4632 
4633  /* disallow crossing savepoint level boundaries */
4634  if (target->savepointLevel != s->savepointLevel)
4635  ereport(ERROR,
4636  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4637  errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
4638 
4639  /*
4640  * Mark "abort pending" all subtransactions up to the target
4641  * subtransaction. The actual aborts will happen when control gets to
4642  * CommitTransactionCommand.
4643  */
4644  xact = CurrentTransactionState;
4645  for (;;)
4646  {
4647  if (xact == target)
4648  break;
4649  if (xact->blockState == TBLOCK_SUBINPROGRESS)
4651  else if (xact->blockState == TBLOCK_SUBABORT)
4653  else
4654  elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4656  xact = xact->parent;
4657  Assert(PointerIsValid(xact));
4658  }
4659 
4660  /* And mark the target as "restart pending" */
4661  if (xact->blockState == TBLOCK_SUBINPROGRESS)
4662  xact->blockState = TBLOCK_SUBRESTART;
4663  else if (xact->blockState == TBLOCK_SUBABORT)
4665  else
4666  elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4668 }

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

5522 {
5523  TransactionState s;
5524  Size nxids = 0;
5525  Size i = 0;
5526  TransactionId *workspace;
5528 
5529  result = (SerializedTransactionState *) start_address;
5530 
5531  result->xactIsoLevel = XactIsoLevel;
5532  result->xactDeferrable = XactDeferrable;
5534  result->currentFullTransactionId =
5537 
5538  /*
5539  * If we're running in a parallel worker and launching a parallel worker
5540  * of our own, we can just pass along the information that was passed to
5541  * us.
5542  */
5543  if (nParallelCurrentXids > 0)
5544  {
5546  memcpy(&result->parallelCurrentXids[0], ParallelCurrentXids,
5548  return;
5549  }
5550 
5551  /*
5552  * OK, we need to generate a sorted list of XIDs that our workers should
5553  * view as current. First, figure out how many there are.
5554  */
5555  for (s = CurrentTransactionState; s != NULL; s = s->parent)
5556  {
5558  nxids = add_size(nxids, 1);
5559  nxids = add_size(nxids, s->nChildXids);
5560  }
5562  <= maxsize);
5563 
5564  /* Copy them to our scratch space. */
5565  workspace = palloc(nxids * sizeof(TransactionId));
5566  for (s = CurrentTransactionState; s != NULL; s = s->parent)
5567  {
5569  workspace[i++] = XidFromFullTransactionId(s->fullTransactionId);
5570  if (s->nChildXids > 0)
5571  memcpy(&workspace[i], s->childXids,
5572  s->nChildXids * sizeof(TransactionId));
5573  i += s->nChildXids;
5574  }
5575  Assert(i == nxids);
5576 
5577  /* Sort them. */
5578  qsort(workspace, nxids, sizeof(TransactionId), xidComparator);
5579 
5580  /* Copy data into output area. */
5581  result->nParallelCurrentXids = nxids;
5582  memcpy(&result->parallelCurrentXids[0], workspace,
5583  nxids * sizeof(TransactionId));
5584 }
int i
Definition: isn.c:73
void * palloc(Size size)
Definition: mcxt.c:1317
#define qsort(a, b, c, d)
Definition: port.h:453
FullTransactionId currentFullTransactionId
Definition: xact.c:230
FullTransactionId topFullTransactionId
Definition: xact.c:229
CommandId currentCommandId
Definition: xact.c:231
TransactionId parallelCurrentXids[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.c:233
TransactionId * childXids
Definition: xact.c:204
static int nParallelCurrentXids
Definition: xact.c:124
static TransactionId * ParallelCurrentXids
Definition: xact.c:125
int xidComparator(const void *arg1, const void *arg2)
Definition: xid.c:139

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

858 {
860  xactStartTimestamp = xact_ts;
861  stmtStartTimestamp = stmt_ts;
862 }

References Assert, IsParallelWorker, stmtStartTimestamp, and xactStartTimestamp.

Referenced by ParallelWorkerMain().

◆ StartParallelWorkerTransaction()

void StartParallelWorkerTransaction ( char *  tstatespace)

Definition at line 5592 of file xact.c.

5593 {
5595 
5597  StartTransaction();
5598 
5599  tstate = (SerializedTransactionState *) tstatespace;
5600  XactIsoLevel = tstate->xactIsoLevel;
5601  XactDeferrable = tstate->xactDeferrable;
5604  tstate->currentFullTransactionId;
5608 
5610 }
static void StartTransaction(void)
Definition: xact.c:2052

References Assert, TransactionStateData::blockState, SerializedTransactionState::currentCommandId, currentCommandId, SerializedTransactionState::currentFullTransactionId, CurrentTransactionState, TransactionStateData::fullTransactionId, nParallelCurrentXids, SerializedTransactionState::nParallelCurrentXids, ParallelCurrentXids, SerializedTransactionState::parallelCurrentXids, StartTransaction(), TBLOCK_DEFAULT, TBLOCK_PARALLEL_INPROGRESS, SerializedTransactionState::topFullTransactionId, XactDeferrable, SerializedTransactionState::xactDeferrable, XactIsoLevel, SerializedTransactionState::xactIsoLevel, and XactTopFullTransactionId.

Referenced by ParallelWorkerMain().

◆ StartTransactionCommand()

void StartTransactionCommand ( void  )

Definition at line 3033 of file xact.c.

3034 {
3036 
3037  switch (s->blockState)
3038  {
3039  /*
3040  * if we aren't in a transaction block, we just do our usual start
3041  * transaction.
3042  */
3043  case TBLOCK_DEFAULT:
3044  StartTransaction();
3046  break;
3047 
3048  /*
3049  * We are somewhere in a transaction block or subtransaction and
3050  * about to start a new command. For now we do nothing, but
3051  * someday we may do command-local resource initialization. (Note
3052  * that any needed CommandCounterIncrement was done by the
3053  * previous CommitTransactionCommand.)
3054  */
3055  case TBLOCK_INPROGRESS:
3057  case TBLOCK_SUBINPROGRESS:
3058  break;
3059 
3060  /*
3061  * Here we are in a failed transaction block (one of the commands
3062  * caused an abort) so we do nothing but remain in the abort
3063  * state. Eventually we will get a ROLLBACK command which will
3064  * get us out of this state. (It is up to other code to ensure
3065  * that no commands other than ROLLBACK will be processed in these
3066  * states.)
3067  */
3068  case TBLOCK_ABORT:
3069  case TBLOCK_SUBABORT:
3070  break;
3071 
3072  /* These cases are invalid. */
3073  case TBLOCK_STARTED:
3074  case TBLOCK_BEGIN:
3076  case TBLOCK_SUBBEGIN:
3077  case TBLOCK_END:
3078  case TBLOCK_SUBRELEASE:
3079  case TBLOCK_SUBCOMMIT:
3080  case TBLOCK_ABORT_END:
3081  case TBLOCK_SUBABORT_END:
3082  case TBLOCK_ABORT_PENDING:
3084  case TBLOCK_SUBRESTART:
3086  case TBLOCK_PREPARE:
3087  elog(ERROR, "StartTransactionCommand: unexpected state %s",
3089  break;
3090  }
3091 
3092  /*
3093  * We must switch to CurTransactionContext before returning. This is
3094  * already done if we called StartTransaction, otherwise not.
3095  */
3096  Assert(CurTransactionContext != NULL);
3098 }

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

Referenced by _SPI_commit(), _SPI_rollback(), apply_handle_commit_internal(), ATExecDetachPartition(), autoprewarm_database_main(), bbsink_server_new(), begin_replication_step(), BeginInternalSubTransaction(), BootstrapModeMain(), clear_subscription_skip_lsn(), cluster(), cluster_multiple_rels(), DefineIndex(), DisableSubscriptionAndExit(), do_autovacuum(), EventTriggerOnLogin(), exec_replication_command(), FetchTableStates(), 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(), synchronize_slots(), vacuum(), vacuum_rel(), validate_remote_info(), and worker_spi_main().

◆ SubTransactionIsActive()

bool SubTransactionIsActive ( SubTransactionId  subxid)

Definition at line 803 of file xact.c.

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

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

Referenced by fmgr_sql().

◆ TransactionBlockStatusCode()

char TransactionBlockStatusCode ( void  )

Definition at line 4990 of file xact.c.

4991 {
4993 
4994  switch (s->blockState)
4995  {
4996  case TBLOCK_DEFAULT:
4997  case TBLOCK_STARTED:
4998  return 'I'; /* idle --- not in transaction */
4999  case TBLOCK_BEGIN:
5000  case TBLOCK_SUBBEGIN:
5001  case TBLOCK_INPROGRESS:
5004  case TBLOCK_SUBINPROGRESS:
5005  case TBLOCK_END:
5006  case TBLOCK_SUBRELEASE:
5007  case TBLOCK_SUBCOMMIT:
5008  case TBLOCK_PREPARE:
5009  return 'T'; /* in transaction */
5010  case TBLOCK_ABORT:
5011  case TBLOCK_SUBABORT:
5012  case TBLOCK_ABORT_END:
5013  case TBLOCK_SUBABORT_END:
5014  case TBLOCK_ABORT_PENDING:
5016  case TBLOCK_SUBRESTART:
5018  return 'E'; /* in failed transaction */
5019  }
5020 
5021  /* should never get here */
5022  elog(FATAL, "invalid transaction block state: %s",
5024  return 0; /* keep compiler quiet */
5025 }

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

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

◆ UnregisterSubXactCallback()

void UnregisterSubXactCallback ( SubXactCallback  callback,
void *  arg 
)

Definition at line 3864 of file xact.c.

3865 {
3866  SubXactCallbackItem *item;
3867  SubXactCallbackItem *prev;
3868 
3869  prev = NULL;
3870  for (item = SubXact_callbacks; item; prev = item, item = item->next)
3871  {
3872  if (item->callback == callback && item->arg == arg)
3873  {
3874  if (prev)
3875  prev->next = item->next;
3876  else
3877  SubXact_callbacks = item->next;
3878  pfree(item);
3879  break;
3880  }
3881  }
3882 }
void pfree(void *pointer)
Definition: mcxt.c:1521

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

◆ UnregisterXactCallback()

void UnregisterXactCallback ( XactCallback  callback,
void *  arg 
)

Definition at line 3804 of file xact.c.

3805 {
3806  XactCallbackItem *item;
3807  XactCallbackItem *prev;
3808 
3809  prev = NULL;
3810  for (item = Xact_callbacks; item; prev = item, item = item->next)
3811  {
3812  if (item->callback == callback && item->arg == arg)
3813  {
3814  if (prev)
3815  prev->next = item->next;
3816  else
3817  Xact_callbacks = item->next;
3818  pfree(item);
3819  break;
3820  }
3821  }
3822 }

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

◆ UserAbortTransactionBlock()

void UserAbortTransactionBlock ( bool  chain)

Definition at line 4191 of file xact.c.

4192 {
4194 
4195  switch (s->blockState)
4196  {
4197  /*
4198  * We are inside a transaction block and we got a ROLLBACK command
4199  * from the user, so tell CommitTransactionCommand to abort and
4200  * exit the transaction block.
4201  */
4202  case TBLOCK_INPROGRESS:
4204  break;
4205 
4206  /*
4207  * We are inside a failed transaction block and we got a ROLLBACK
4208  * command from the user. Abort processing is already done, so
4209  * CommitTransactionCommand just has to cleanup and go back to
4210  * idle state.
4211  */
4212  case TBLOCK_ABORT:
4214  break;
4215 
4216  /*
4217  * We are inside a subtransaction. Mark everything up to top
4218  * level as exitable.
4219  */
4220  case TBLOCK_SUBINPROGRESS:
4221  case TBLOCK_SUBABORT:
4222  while (s->parent != NULL)
4223  {
4224  if (s->blockState == TBLOCK_SUBINPROGRESS)
4226  else if (s->blockState == TBLOCK_SUBABORT)
4228  else
4229  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4231  s = s->parent;
4232  }
4233  if (s->blockState == TBLOCK_INPROGRESS)
4235  else if (s->blockState == TBLOCK_ABORT)
4237  else
4238  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4240  break;
4241 
4242  /*
4243  * The user issued ABORT when not inside a transaction. For
4244  * ROLLBACK without CHAIN, issue a WARNING and go to abort state.
4245  * The upcoming call to CommitTransactionCommand() will then put
4246  * us back into the default state. For ROLLBACK AND CHAIN, error.
4247  *
4248  * We do the same thing with ABORT inside an implicit transaction,
4249  * although in this case we might be rolling back actual database
4250  * state changes. (It's debatable whether we should issue a
4251  * WARNING in this case, but we have done so historically.)
4252  */
4253  case TBLOCK_STARTED:
4255  if (chain)
4256  ereport(ERROR,
4257  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4258  /* translator: %s represents an SQL statement name */
4259  errmsg("%s can only be used in transaction blocks",
4260  "ROLLBACK AND CHAIN")));
4261  else
4262  ereport(WARNING,
4263  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4264  errmsg("there is no transaction in progress")));
4266  break;
4267 
4268  /*
4269  * The user issued an ABORT that somehow ran inside a parallel
4270  * worker. We can't cope with that.
4271  */
4273  ereport(FATAL,
4274  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4275  errmsg("cannot abort during a parallel operation")));
4276  break;
4277 
4278  /* These cases are invalid. */
4279  case TBLOCK_DEFAULT:
4280  case TBLOCK_BEGIN:
4281  case TBLOCK_SUBBEGIN:
4282  case TBLOCK_END:
4283  case TBLOCK_SUBRELEASE:
4284  case TBLOCK_SUBCOMMIT:
4285  case TBLOCK_ABORT_END:
4286  case TBLOCK_SUBABORT_END:
4287  case TBLOCK_ABORT_PENDING:
4289  case TBLOCK_SUBRESTART:
4291  case TBLOCK_PREPARE:
4292  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4294  break;
4295  }
4296 
4299 
4300  s->chain = chain;
4301 }

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

3695 {
3696  CheckTransactionBlock(isTopLevel, false, stmtType);
3697 }

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:504
static char * buf
Definition: pg_test_fsync.c:73
#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:97
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 6344 of file xact.c.

6345 {
6346  uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
6347 
6348  /* Backup blocks are not used in xact records */
6349  Assert(!XLogRecHasAnyBlockRefs(record));
6350 
6351  if (info == XLOG_XACT_COMMIT)
6352  {
6353  xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6354  xl_xact_parsed_commit parsed;
6355 
6356  ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6357  xact_redo_commit(&parsed, XLogRecGetXid(record),
6358  record->EndRecPtr, XLogRecGetOrigin(record));
6359  }
6360  else if (info == XLOG_XACT_COMMIT_PREPARED)
6361  {
6362  xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6363  xl_xact_parsed_commit parsed;
6364 
6365  ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6366  xact_redo_commit(&parsed, parsed.twophase_xid,
6367  record->EndRecPtr, XLogRecGetOrigin(record));
6368 
6369  /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6370  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6371  PrepareRedoRemove(parsed.twophase_xid, false);
6372  LWLockRelease(TwoPhaseStateLock);
6373  }
6374  else if (info == XLOG_XACT_ABORT)
6375  {
6376  xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6377  xl_xact_parsed_abort parsed;
6378 
6379  ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6380  xact_redo_abort(&parsed, XLogRecGetXid(record),
6381  record->EndRecPtr, XLogRecGetOrigin(record));
6382  }
6383  else if (info == XLOG_XACT_ABORT_PREPARED)
6384  {
6385  xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6386  xl_xact_parsed_abort parsed;
6387 
6388  ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6389  xact_redo_abort(&parsed, parsed.twophase_xid,
6390  record->EndRecPtr, XLogRecGetOrigin(record));
6391 
6392  /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6393  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6394  PrepareRedoRemove(parsed.twophase_xid, false);
6395  LWLockRelease(TwoPhaseStateLock);
6396  }
6397  else if (info == XLOG_XACT_PREPARE)
6398  {
6399  /*
6400  * Store xid and start/end pointers of the WAL record in TwoPhaseState
6401  * gxact entry.
6402  */
6403  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6405  record->ReadRecPtr,
6406  record->EndRecPtr,
6407  XLogRecGetOrigin(record));
6408  LWLockRelease(TwoPhaseStateLock);
6409  }
6410  else if (info == XLOG_XACT_ASSIGNMENT)
6411  {
6413 
6416  xlrec->nsubxacts, xlrec->xsub);
6417  }
6418  else if (info == XLOG_XACT_INVALIDATIONS)
6419  {
6420  /*
6421  * XXX we do ignore this for now, what matters are invalidations
6422  * written into the commit record.
6423  */
6424  }
6425  else
6426  elog(PANIC, "xact_redo: unknown op code %u", info);
6427 }
#define PANIC
Definition: elog.h:42
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1168
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1781
@ LW_EXCLUSIVE
Definition: lwlock.h:114
void ProcArrayApplyXidAssignment(TransactionId topxid, int nsubxids, TransactionId *subxids)
Definition: procarray.c:1318
XLogRecPtr EndRecPtr
Definition: xlogreader.h:207
XLogRecPtr ReadRecPtr
Definition: xlogreader.h:206
TransactionId xsub[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:222
void PrepareRedoRemove(TransactionId xid, bool giveWarning)
Definition: twophase.c:2581
void PrepareRedoAdd(char *buf, XLogRecPtr start_lsn, XLogRecPtr end_lsn, RepOriginId origin_id)
Definition: twophase.c:2479
static void xact_redo_commit(xl_xact_parsed_commit *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:6111
static void xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:6265
void ParseCommitRecord(uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *parsed)
Definition: xactdesc.c:35
void ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
Definition: xactdesc.c:141
#define XLogRecGetXid(decoder)
Definition: xlogreader.h:412
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:417
HotStandbyState standbyState
Definition: xlogutils.c:53
@ STANDBY_INITIALIZED
Definition: xlogutils.h:53

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

5772 {
5774 
5775  if (s->nChildXids == 0)
5776  *ptr = NULL;
5777  else
5778  *ptr = s->childXids;
5779 
5780  return s->nChildXids;
5781 }

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

5973 {
5974  xl_xact_abort xlrec;
5975  xl_xact_xinfo xl_xinfo;
5976  xl_xact_subxacts xl_subxacts;
5977  xl_xact_relfilelocators xl_relfilelocators;
5978  xl_xact_stats_items xl_dropped_stats;
5979  xl_xact_twophase xl_twophase;
5980  xl_xact_dbinfo xl_dbinfo;
5981  xl_xact_origin xl_origin;
5982 
5983  uint8 info;
5984 
5985  Assert(CritSectionCount > 0);
5986 
5987  xl_xinfo.xinfo = 0;
5988 
5989  /* decide between a plain and 2pc abort */
5990  if (!TransactionIdIsValid(twophase_xid))
5991  info = XLOG_XACT_ABORT;
5992  else
5993  info = XLOG_XACT_ABORT_PREPARED;
5994 
5995 
5996  /* First figure out and collect all the information needed */
5997 
5998  xlrec.xact_time = abort_time;
5999 
6000  if ((xactflags & XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK))
6001  xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
6002 
6003  if (nsubxacts > 0)
6004  {
6005  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
6006  xl_subxacts.nsubxacts = nsubxacts;
6007  }
6008 
6009  if (nrels > 0)
6010  {
6012  xl_relfilelocators.nrels = nrels;
6013  info |= XLR_SPECIAL_REL_UPDATE;
6014  }
6015 
6016  if (ndroppedstats > 0)
6017  {
6018  xl_xinfo.xinfo |= XACT_XINFO_HAS_DROPPED_STATS;
6019  xl_dropped_stats.nitems = ndroppedstats;
6020  }
6021 
6022  if (TransactionIdIsValid(twophase_xid))
6023  {
6024  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
6025  xl_twophase.xid = twophase_xid;
6026  Assert(twophase_gid != NULL);
6027 
6028  if (XLogLogicalInfoActive())
6029  xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
6030  }
6031 
6032  if (TransactionIdIsValid(twophase_xid) && XLogLogicalInfoActive())
6033  {
6034  xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
6035  xl_dbinfo.dbId = MyDatabaseId;
6036  xl_dbinfo.tsId = MyDatabaseTableSpace;
6037  }
6038 
6039  /*
6040  * Dump transaction origin information. We need this during recovery to
6041  * update the replication origin progress.
6042  */
6044  {
6045  xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
6046 
6049  }
6050 
6051  if (xl_xinfo.xinfo != 0)
6052  info |= XLOG_XACT_HAS_INFO;
6053 
6054  /* Then include all the collected data into the abort record. */
6055 
6056  XLogBeginInsert();
6057 
6058  XLogRegisterData((char *) (&xlrec), MinSizeOfXactAbort);
6059 
6060  if (xl_xinfo.xinfo != 0)
6061  XLogRegisterData((char *) (&xl_xinfo), sizeof(xl_xinfo));
6062 
6063  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
6064  XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
6065 
6066  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
6067  {
6068  XLogRegisterData((char *) (&xl_subxacts),
6070  XLogRegisterData((char *) subxacts,
6071  nsubxacts * sizeof(TransactionId));
6072  }
6073 
6074  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILELOCATORS)
6075  {
6076  XLogRegisterData((char *) (&xl_relfilelocators),
6078  XLogRegisterData((char *) rels,
6079  nrels * sizeof(RelFileLocator));
6080  }
6081 
6082  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
6083  {
6084  XLogRegisterData((char *) (&xl_dropped_stats),
6086  XLogRegisterData((char *) droppedstats,
6087  ndroppedstats * sizeof(xl_xact_stats_item));
6088  }
6089 
6090  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
6091  {
6092  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
6093  if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
6094  XLogRegisterData(unconstify(char *, twophase_gid), strlen(twophase_gid) + 1);
6095  }
6096 
6097  if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
6098  XLogRegisterData((char *) (&xl_origin), sizeof(xl_xact_origin));
6099 
6100  /* Include the replication origin */
6102 
6103  return XLogInsert(RM_XACT_ID, info);
6104 }
#define unconstify(underlying_type, expr)
Definition: c.h:1245
Oid MyDatabaseTableSpace
Definition: globals.c:94
volatile uint32 CritSectionCount
Definition: globals.c:44
Oid MyDatabaseId
Definition: globals.c:92
TimestampTz replorigin_session_origin_timestamp
Definition: origin.c:157
RepOriginId replorigin_session_origin
Definition: origin.c:155
XLogRecPtr replorigin_session_origin_lsn
Definition: origin.c:156
#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:154
void XLogRegisterData(char *data, uint32 len)
Definition: xloginsert.c:364
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:474
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:456
void XLogBeginInsert(void)
Definition: xloginsert.c:149
#define XLR_SPECIAL_REL_UPDATE
Definition: xlogrecord.h:82

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

5803 {
5804  xl_xact_commit xlrec;
5805  xl_xact_xinfo xl_xinfo;
5806  xl_xact_dbinfo xl_dbinfo;
5807  xl_xact_subxacts xl_subxacts;
5808  xl_xact_relfilelocators xl_relfilelocators;
5809  xl_xact_stats_items xl_dropped_stats;
5810  xl_xact_invals xl_invals;
5811  xl_xact_twophase xl_twophase;
5812  xl_xact_origin xl_origin;
5813  uint8 info;
5814 
5815  Assert(CritSectionCount > 0);
5816 
5817  xl_xinfo.xinfo = 0;
5818 
5819  /* decide between a plain and 2pc commit */
5820  if (!TransactionIdIsValid(twophase_xid))
5821  info = XLOG_XACT_COMMIT;
5822  else
5824 
5825  /* First figure out and collect all the information needed */
5826 
5827  xlrec.xact_time = commit_time;
5828 
5829  if (relcacheInval)
5831  if (forceSyncCommit)
5833  if ((xactflags & XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK))
5834  xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5835 
5836  /*
5837  * Check if the caller would like to ask standbys for immediate feedback
5838  * once this commit is applied.
5839  */
5842 
5843  /*
5844  * Relcache invalidations requires information about the current database
5845  * and so does logical decoding.
5846  */
5847  if (nmsgs > 0 || XLogLogicalInfoActive())
5848  {
5849  xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5850  xl_dbinfo.dbId = MyDatabaseId;
5851  xl_dbinfo.tsId = MyDatabaseTableSpace;
5852  }
5853 
5854  if (nsubxacts > 0)
5855  {
5856  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5857  xl_subxacts.nsubxacts = nsubxacts;
5858  }
5859 
5860  if (nrels > 0)
5861  {
5863  xl_relfilelocators.nrels = nrels;
5864  info |= XLR_SPECIAL_REL_UPDATE;
5865  }
5866 
5867  if (ndroppedstats > 0)
5868  {
5869  xl_xinfo.xinfo |= XACT_XINFO_HAS_DROPPED_STATS;
5870  xl_dropped_stats.nitems = ndroppedstats;
5871  }
5872 
5873  if (nmsgs > 0)
5874  {
5875  xl_xinfo.xinfo |= XACT_XINFO_HAS_INVALS;
5876  xl_invals.nmsgs = nmsgs;
5877  }
5878 
5879  if (TransactionIdIsValid(twophase_xid))
5880  {
5881  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5882  xl_twophase.xid = twophase_xid;
5883  Assert(twophase_gid != NULL);
5884 
5885  if (XLogLogicalInfoActive())
5886  xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
5887  }
5888 
5889  /* dump transaction origin information */
5891  {
5892  xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
5893 
5896  }
5897 
5898  if (xl_xinfo.xinfo != 0)
5899  info |= XLOG_XACT_HAS_INFO;
5900 
5901  /* Then include all the collected data into the commit record. */
5902 
5903  XLogBeginInsert();
5904 
5905  XLogRegisterData((char *) (&xlrec), sizeof(xl_xact_commit));
5906 
5907  if (xl_xinfo.xinfo != 0)
5908  XLogRegisterData((char *) (&xl_xinfo.xinfo), sizeof(xl_xinfo.xinfo));
5909 
5910  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5911  XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
5912 
5913  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5914  {
5915  XLogRegisterData((char *) (&xl_subxacts),
5917  XLogRegisterData((char *) subxacts,
5918  nsubxacts * sizeof(TransactionId));
5919  }
5920 
5921  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILELOCATORS)
5922  {
5923  XLogRegisterData((char *) (&xl_relfilelocators),
5925  XLogRegisterData((char *) rels,
5926  nrels * sizeof(RelFileLocator));
5927  }
5928 
5929  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
5930  {
5931  XLogRegisterData((char *) (&xl_dropped_stats),
5933  XLogRegisterData((char *) droppedstats,
5934  ndroppedstats * sizeof(xl_xact_stats_item));
5935  }
5936 
5937  if (xl_xinfo.xinfo & XACT_XINFO_HAS_INVALS)
5938  {
5939  XLogRegisterData((char *) (&xl_invals), MinSizeOfXactInvals);
5940  XLogRegisterData((char *) msgs,
5941  nmsgs * sizeof(SharedInvalidationMessage));
5942  }
5943 
5944  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5945  {
5946  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5947  if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
5948  XLogRegisterData(unconstify(char *, twophase_gid), strlen(twophase_gid) + 1);
5949  }
5950 
5951  if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5952  XLogRegisterData((char *) (&xl_origin), sizeof(xl_xact_origin));
5953 
5954  /* we allow filtering by xacts */
5956 
5957  return XLogInsert(RM_XACT_ID, info);
5958 }
int synchronous_commit
Definition: xact.c:85
#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 82 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactIsoLevel

PGDLLIMPORT int DefaultXactIsoLevel
extern

Definition at line 76 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactReadOnly

PGDLLIMPORT bool DefaultXactReadOnly
extern

Definition at line 79 of file xact.c.

Referenced by StartTransaction().

◆ MyXactFlags

◆ synchronous_commit

PGDLLIMPORT int synchronous_commit
extern

Definition at line 85 of file xact.c.

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

◆ xact_is_sampled

PGDLLIMPORT bool xact_is_sampled
extern

Definition at line 294 of file xact.c.

Referenced by check_log_duration(), and StartTransaction().

◆ XactDeferrable

◆ XactIsoLevel

◆ XactReadOnly