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

3388 {
3389  /*
3390  * Repeatedly call AbortCurrentTransactionInternal() until all the work is
3391  * done.
3392  */
3394  {
3395  }
3396 }
static bool AbortCurrentTransactionInternal(void)
Definition: xact.c:3405

References AbortCurrentTransactionInternal().

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

◆ AbortOutOfAnyTransaction()

void AbortOutOfAnyTransaction ( void  )

Definition at line 4811 of file xact.c.

4812 {
4814 
4815  /* Ensure we're not running in a doomed memory context */
4816  AtAbort_Memory();
4817 
4818  /*
4819  * Get out of any transaction or nested transaction
4820  */
4821  do
4822  {
4823  switch (s->blockState)
4824  {
4825  case TBLOCK_DEFAULT:
4826  if (s->state == TRANS_DEFAULT)
4827  {
4828  /* Not in a transaction, do nothing */
4829  }
4830  else
4831  {
4832  /*
4833  * We can get here after an error during transaction start
4834  * (state will be TRANS_START). Need to clean up the
4835  * incompletely started transaction. First, adjust the
4836  * low-level state to suppress warning message from
4837  * AbortTransaction.
4838  */
4839  if (s->state == TRANS_START)
4840  s->state = TRANS_INPROGRESS;
4841  AbortTransaction();
4843  }
4844  break;
4845  case TBLOCK_STARTED:
4846  case TBLOCK_BEGIN:
4847  case TBLOCK_INPROGRESS:
4850  case TBLOCK_END:
4851  case TBLOCK_ABORT_PENDING:
4852  case TBLOCK_PREPARE:
4853  /* In a transaction, so clean up */
4854  AbortTransaction();
4857  break;
4858  case TBLOCK_ABORT:
4859  case TBLOCK_ABORT_END:
4860 
4861  /*
4862  * AbortTransaction is already done, still need Cleanup.
4863  * However, if we failed partway through running ROLLBACK,
4864  * there will be an active portal running that command, which
4865  * we need to shut down before doing CleanupTransaction.
4866  */
4867  AtAbort_Portals();
4870  break;
4871 
4872  /*
4873  * In a subtransaction, so clean it up and abort parent too
4874  */
4875  case TBLOCK_SUBBEGIN:
4876  case TBLOCK_SUBINPROGRESS:
4877  case TBLOCK_SUBRELEASE:
4878  case TBLOCK_SUBCOMMIT:
4880  case TBLOCK_SUBRESTART:
4883  s = CurrentTransactionState; /* changed by pop */
4884  break;
4885 
4886  case TBLOCK_SUBABORT:
4887  case TBLOCK_SUBABORT_END:
4889  /* As above, but AbortSubTransaction already done */
4890  if (s->curTransactionOwner)
4891  {
4892  /* As in TBLOCK_ABORT, might have a live portal to zap */
4897  }
4899  s = CurrentTransactionState; /* changed by pop */
4900  break;
4901  }
4902  } while (s->blockState != TBLOCK_DEFAULT);
4903 
4904  /* Should be out of all subxacts now */
4905  Assert(s->parent == NULL);
4906 
4907  /* If we didn't actually have anything to do, revert to TopMemoryContext */
4908  AtCleanup_Memory();
4909 }
#define Assert(condition)
Definition: c.h:858
void AtAbort_Portals(void)
Definition: portalmem.c:781
void AtSubAbort_Portals(SubTransactionId mySubid, SubTransactionId parentSubid, ResourceOwner myXactOwner, ResourceOwner parentXactOwner)
Definition: portalmem.c:979
TransState state
Definition: xact.c:197
SubTransactionId subTransactionId
Definition: xact.c:194
struct TransactionStateData * parent
Definition: xact.c:215
TBlockState blockState
Definition: xact.c:198
ResourceOwner curTransactionOwner
Definition: xact.c:202
static void CleanupSubTransaction(void)
Definition: xact.c:5334
static void CleanupTransaction(void)
Definition: xact.c:2945
@ TRANS_INPROGRESS
Definition: xact.c:143
@ TRANS_START
Definition: xact.c:142
@ TRANS_DEFAULT
Definition: xact.c:141
static void AtCleanup_Memory(void)
Definition: xact.c:1943
static void AbortSubTransaction(void)
Definition: xact.c:5162
static void AtAbort_Memory(void)
Definition: xact.c:1853
@ 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:2749
static TransactionState CurrentTransactionState
Definition: xact.c:257

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

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

◆ BeginImplicitTransactionBlock()

void BeginImplicitTransactionBlock ( void  )

Definition at line 4275 of file xact.c.

4276 {
4278 
4279  /*
4280  * If we are in STARTED state (that is, no transaction block is open),
4281  * switch to IMPLICIT_INPROGRESS state, creating an implicit transaction
4282  * block.
4283  *
4284  * For caller convenience, we consider all other transaction states as
4285  * legal here; otherwise the caller would need its own state check, which
4286  * seems rather pointless.
4287  */
4288  if (s->blockState == TBLOCK_STARTED)
4290 }

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

Referenced by exec_simple_query().

◆ BeginInternalSubTransaction()

void BeginInternalSubTransaction ( const char *  name)

Definition at line 4643 of file xact.c.

4644 {
4646  bool save_ExitOnAnyError = ExitOnAnyError;
4647 
4648  /*
4649  * Errors within this function are improbable, but if one does happen we
4650  * force a FATAL exit. Callers generally aren't prepared to handle losing
4651  * control, and moreover our transaction state is probably corrupted if we
4652  * fail partway through; so an ordinary ERROR longjmp isn't okay.
4653  */
4654  ExitOnAnyError = true;
4655 
4656  /*
4657  * We do not check for parallel mode here. It's permissible to start and
4658  * end "internal" subtransactions while in parallel mode, so long as no
4659  * new XIDs or command IDs are assigned. Enforcement of that occurs in
4660  * AssignTransactionId() and CommandCounterIncrement().
4661  */
4662 
4663  switch (s->blockState)
4664  {
4665  case TBLOCK_STARTED:
4666  case TBLOCK_INPROGRESS:
4669  case TBLOCK_END:
4670  case TBLOCK_PREPARE:
4671  case TBLOCK_SUBINPROGRESS:
4672  /* Normal subtransaction start */
4673  PushTransaction();
4674  s = CurrentTransactionState; /* changed by push */
4675 
4676  /*
4677  * Savepoint names, like the TransactionState block itself, live
4678  * in TopTransactionContext.
4679  */
4680  if (name)
4682  break;
4683 
4684  /* These cases are invalid. */
4685  case TBLOCK_DEFAULT:
4686  case TBLOCK_BEGIN:
4687  case TBLOCK_SUBBEGIN:
4688  case TBLOCK_SUBRELEASE:
4689  case TBLOCK_SUBCOMMIT:
4690  case TBLOCK_ABORT:
4691  case TBLOCK_SUBABORT:
4692  case TBLOCK_ABORT_END:
4693  case TBLOCK_SUBABORT_END:
4694  case TBLOCK_ABORT_PENDING:
4696  case TBLOCK_SUBRESTART:
4698  elog(FATAL, "BeginInternalSubTransaction: unexpected state %s",
4700  break;
4701  }
4702 
4705 
4706  ExitOnAnyError = save_ExitOnAnyError;
4707 }
#define FATAL
Definition: elog.h:41
#define elog(elevel,...)
Definition: elog.h:224
bool ExitOnAnyError
Definition: globals.c:120
MemoryContext TopTransactionContext
Definition: mcxt.c:154
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1682
const char * name
static void PushTransaction(void)
Definition: xact.c:5367
void StartTransactionCommand(void)
Definition: xact.c:2995
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5658
void CommitTransactionCommand(void)
Definition: xact.c:3093

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

3874 {
3876 
3877  switch (s->blockState)
3878  {
3879  /*
3880  * We are not inside a transaction block, so allow one to begin.
3881  */
3882  case TBLOCK_STARTED:
3883  s->blockState = TBLOCK_BEGIN;
3884  break;
3885 
3886  /*
3887  * BEGIN converts an implicit transaction block to a regular one.
3888  * (Note that we allow this even if we've already done some
3889  * commands, which is a bit odd but matches historical practice.)
3890  */
3892  s->blockState = TBLOCK_BEGIN;
3893  break;
3894 
3895  /*
3896  * Already a transaction block in progress.
3897  */
3898  case TBLOCK_INPROGRESS:
3900  case TBLOCK_SUBINPROGRESS:
3901  case TBLOCK_ABORT:
3902  case TBLOCK_SUBABORT:
3903  ereport(WARNING,
3904  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3905  errmsg("there is already a transaction in progress")));
3906  break;
3907 
3908  /* These cases are invalid. */
3909  case TBLOCK_DEFAULT:
3910  case TBLOCK_BEGIN:
3911  case TBLOCK_SUBBEGIN:
3912  case TBLOCK_END:
3913  case TBLOCK_SUBRELEASE:
3914  case TBLOCK_SUBCOMMIT:
3915  case TBLOCK_ABORT_END:
3916  case TBLOCK_SUBABORT_END:
3917  case TBLOCK_ABORT_PENDING:
3919  case TBLOCK_SUBRESTART:
3921  case TBLOCK_PREPARE:
3922  elog(FATAL, "BeginTransactionBlock: unexpected state %s",
3924  break;
3925  }
3926 }
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#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 1097 of file xact.c.

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

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

◆ CommitTransactionCommand()

void CommitTransactionCommand ( void  )

Definition at line 3093 of file xact.c.

3094 {
3095  /*
3096  * Repeatedly call CommitTransactionCommandInternal() until all the work
3097  * is done.
3098  */
3100  {
3101  }
3102 }
static bool CommitTransactionCommandInternal(void)
Definition: xact.c:3111

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

4323 {
4325 
4326  /*
4327  * Workers synchronize transaction state at the beginning of each parallel
4328  * operation, so we can't account for new subtransactions after that
4329  * point. (Note that this check will certainly error out if s->blockState
4330  * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4331  * below.)
4332  */
4334  ereport(ERROR,
4335  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4336  errmsg("cannot define savepoints during a parallel operation")));
4337 
4338  switch (s->blockState)
4339  {
4340  case TBLOCK_INPROGRESS:
4341  case TBLOCK_SUBINPROGRESS:
4342  /* Normal subtransaction start */
4343  PushTransaction();
4344  s = CurrentTransactionState; /* changed by push */
4345 
4346  /*
4347  * Savepoint names, like the TransactionState block itself, live
4348  * in TopTransactionContext.
4349  */
4350  if (name)
4352  break;
4353 
4354  /*
4355  * We disallow savepoint commands in implicit transaction blocks.
4356  * There would be no great difficulty in allowing them so far as
4357  * this module is concerned, but a savepoint seems inconsistent
4358  * with exec_simple_query's behavior of abandoning the whole query
4359  * string upon error. Also, the point of an implicit transaction
4360  * block (as opposed to a regular one) is to automatically close
4361  * after an error, so it's hard to see how a savepoint would fit
4362  * into that.
4363  *
4364  * The error messages for this are phrased as if there were no
4365  * active transaction block at all, which is historical but
4366  * perhaps could be improved.
4367  */
4369  ereport(ERROR,
4370  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4371  /* translator: %s represents an SQL statement name */
4372  errmsg("%s can only be used in transaction blocks",
4373  "SAVEPOINT")));
4374  break;
4375 
4376  /* These cases are invalid. */
4377  case TBLOCK_DEFAULT:
4378  case TBLOCK_STARTED:
4379  case TBLOCK_BEGIN:
4381  case TBLOCK_SUBBEGIN:
4382  case TBLOCK_END:
4383  case TBLOCK_SUBRELEASE:
4384  case TBLOCK_SUBCOMMIT:
4385  case TBLOCK_ABORT:
4386  case TBLOCK_SUBABORT:
4387  case TBLOCK_ABORT_END:
4388  case TBLOCK_SUBABORT_END:
4389  case TBLOCK_ABORT_PENDING:
4391  case TBLOCK_SUBRESTART:
4393  case TBLOCK_PREPARE:
4394  elog(FATAL, "DefineSavepoint: unexpected state %s",
4396  break;
4397  }
4398 }

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

4301 {
4303 
4304  /*
4305  * If we are in IMPLICIT_INPROGRESS state, switch back to STARTED state,
4306  * allowing CommitTransactionCommand to commit whatever happened during
4307  * the implicit transaction block as though it were a single statement.
4308  *
4309  * For caller convenience, we consider all other transaction states as
4310  * legal here; otherwise the caller would need its own state check, which
4311  * seems rather pointless.
4312  */
4315 }

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

3994 {
3996  bool result = false;
3997 
3998  switch (s->blockState)
3999  {
4000  /*
4001  * We are in a transaction block, so tell CommitTransactionCommand
4002  * to COMMIT.
4003  */
4004  case TBLOCK_INPROGRESS:
4005  s->blockState = TBLOCK_END;
4006  result = true;
4007  break;
4008 
4009  /*
4010  * We are in an implicit transaction block. If AND CHAIN was
4011  * specified, error. Otherwise commit, but issue a warning
4012  * because there was no explicit BEGIN before this.
4013  */
4015  if (chain)
4016  ereport(ERROR,
4017  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4018  /* translator: %s represents an SQL statement name */
4019  errmsg("%s can only be used in transaction blocks",
4020  "COMMIT AND CHAIN")));
4021  else
4022  ereport(WARNING,
4023  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4024  errmsg("there is no transaction in progress")));
4025  s->blockState = TBLOCK_END;
4026  result = true;
4027  break;
4028 
4029  /*
4030  * We are in a failed transaction block. Tell
4031  * CommitTransactionCommand it's time to exit the block.
4032  */
4033  case TBLOCK_ABORT:
4035  break;
4036 
4037  /*
4038  * We are in a live subtransaction block. Set up to subcommit all
4039  * open subtransactions and then commit the main transaction.
4040  */
4041  case TBLOCK_SUBINPROGRESS:
4042  while (s->parent != NULL)
4043  {
4044  if (s->blockState == TBLOCK_SUBINPROGRESS)
4046  else
4047  elog(FATAL, "EndTransactionBlock: unexpected state %s",
4049  s = s->parent;
4050  }
4051  if (s->blockState == TBLOCK_INPROGRESS)
4052  s->blockState = TBLOCK_END;
4053  else
4054  elog(FATAL, "EndTransactionBlock: unexpected state %s",
4056  result = true;
4057  break;
4058 
4059  /*
4060  * Here we are inside an aborted subtransaction. Treat the COMMIT
4061  * as ROLLBACK: set up to abort everything and exit the main
4062  * transaction.
4063  */
4064  case TBLOCK_SUBABORT:
4065  while (s->parent != NULL)
4066  {
4067  if (s->blockState == TBLOCK_SUBINPROGRESS)
4069  else if (s->blockState == TBLOCK_SUBABORT)
4071  else
4072  elog(FATAL, "EndTransactionBlock: unexpected state %s",
4074  s = s->parent;
4075  }
4076  if (s->blockState == TBLOCK_INPROGRESS)
4078  else if (s->blockState == TBLOCK_ABORT)
4080  else
4081  elog(FATAL, "EndTransactionBlock: unexpected state %s",
4083  break;
4084 
4085  /*
4086  * The user issued COMMIT when not inside a transaction. For
4087  * COMMIT without CHAIN, issue a WARNING, staying in
4088  * TBLOCK_STARTED state. The upcoming call to
4089  * CommitTransactionCommand() will then close the transaction and
4090  * put us back into the default state. For COMMIT AND CHAIN,
4091  * error.
4092  */
4093  case TBLOCK_STARTED:
4094  if (chain)
4095  ereport(ERROR,
4096  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4097  /* translator: %s represents an SQL statement name */
4098  errmsg("%s can only be used in transaction blocks",
4099  "COMMIT AND CHAIN")));
4100  else
4101  ereport(WARNING,
4102  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4103  errmsg("there is no transaction in progress")));
4104  result = true;
4105  break;
4106 
4107  /*
4108  * The user issued a COMMIT that somehow ran inside a parallel
4109  * worker. We can't cope with that.
4110  */
4112  ereport(FATAL,
4113  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4114  errmsg("cannot commit during a parallel operation")));
4115  break;
4116 
4117  /* These cases are invalid. */
4118  case TBLOCK_DEFAULT:
4119  case TBLOCK_BEGIN:
4120  case TBLOCK_SUBBEGIN:
4121  case TBLOCK_END:
4122  case TBLOCK_SUBRELEASE:
4123  case TBLOCK_SUBCOMMIT:
4124  case TBLOCK_ABORT_END:
4125  case TBLOCK_SUBABORT_END:
4126  case TBLOCK_ABORT_PENDING:
4128  case TBLOCK_SUBRESTART:
4130  case TBLOCK_PREPARE:
4131  elog(FATAL, "EndTransactionBlock: unexpected state %s",
4133  break;
4134  }
4135 
4137  s->blockState == TBLOCK_END ||
4138  s->blockState == TBLOCK_ABORT_END ||
4140 
4141  s->chain = chain;
4142 
4143  return result;
4144 }

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

5464 {
5465  TransactionState s;
5466  Size nxids = 0;
5468 
5469  for (s = CurrentTransactionState; s != NULL; s = s->parent)
5470  {
5472  nxids = add_size(nxids, 1);
5473  nxids = add_size(nxids, s->nChildXids);
5474  }
5475 
5476  return add_size(size, mul_size(sizeof(TransactionId), nxids));
5477 }
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:236

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

1150 {
1151  forceSyncCommit = true;
1152 }
static bool forceSyncCommit
Definition: xact.c:290

References forceSyncCommit.

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

◆ GetCurrentCommandId()

CommandId GetCurrentCommandId ( bool  used)

Definition at line 826 of file xact.c.

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

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

510 {
512 
515  return s->fullTransactionId;
516 }
static void AssignTransactionId(TransactionState s)
Definition: xact.c:632

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

◆ GetCurrentFullTransactionIdIfAny()

FullTransactionId GetCurrentFullTransactionIdIfAny ( void  )

Definition at line 527 of file xact.c.

528 {
530 }

References CurrentTransactionState, and TransactionStateData::fullTransactionId.

◆ GetCurrentStatementStartTimestamp()

TimestampTz GetCurrentStatementStartTimestamp ( void  )

Definition at line 876 of file xact.c.

877 {
878  return stmtStartTimestamp;
879 }
static TimestampTz stmtStartTimestamp
Definition: xact.c:278

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

868 {
869  return xactStartTimestamp;
870 }
static TimestampTz xactStartTimestamp
Definition: xact.c:277

References xactStartTimestamp.

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

◆ GetCurrentTransactionStopTimestamp()

TimestampTz GetCurrentTransactionStopTimestamp ( void  )

Definition at line 888 of file xact.c.

889 {
891 
892  /* should only be called after commit / abort processing */
893  Assert(s->state == TRANS_DEFAULT ||
894  s->state == TRANS_COMMIT ||
895  s->state == TRANS_ABORT ||
896  s->state == TRANS_PREPARE);
897 
898  if (xactStopTimestamp == 0)
900 
901  return xactStopTimestamp;
902 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1654
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:182
static TimestampTz xactStopTimestamp
Definition: xact.c:279
@ 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 604 of file xact.c.

605 {
607  static TransactionId stablexid = InvalidTransactionId;
608 
609  if (lxid != MyProc->vxid.lxid)
610  {
611  lxid = MyProc->vxid.lxid;
612  stablexid = GetTopTransactionIdIfAny();
613  if (!TransactionIdIsValid(stablexid))
614  stablexid = ReadNextTransactionId();
615  }
616 
617  Assert(TransactionIdIsValid(stablexid));
618 
619  return stablexid;
620 }
uint32 LocalTransactionId
Definition: c.h:654
#define InvalidLocalTransactionId
Definition: lock.h:65
PGPROC * MyProc
Definition: proc.c:66
LocalTransactionId lxid
Definition: proc.h:196
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:438

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

Referenced by xid_age().

◆ GetTopFullTransactionId()

FullTransactionId GetTopFullTransactionId ( void  )

Definition at line 480 of file xact.c.

481 {
485 }
static TransactionStateData TopTransactionStateData
Definition: xact.c:244
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 496 of file xact.c.

497 {
499 }

References XactTopFullTransactionId.

Referenced by pg_current_xact_id_if_assigned().

◆ GetTopTransactionId()

◆ GetTopTransactionIdIfAny()

◆ IsAbortedTransactionBlockState()

◆ IsInParallelMode()

◆ IsInTransactionBlock()

bool IsInTransactionBlock ( bool  isTopLevel)

Definition at line 3715 of file xact.c.

3716 {
3717  /*
3718  * Return true on same conditions that would make
3719  * PreventInTransactionBlock error out
3720  */
3721  if (IsTransactionBlock())
3722  return true;
3723 
3724  if (IsSubTransaction())
3725  return true;
3726 
3728  return true;
3729 
3730  if (!isTopLevel)
3731  return true;
3732 
3735  return true;
3736 
3737  return false;
3738 }
bool IsSubTransaction(void)
Definition: xact.c:4988
bool IsTransactionBlock(void)
Definition: xact.c:4915
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 556 of file xact.c.

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

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

Referenced by MarkSubxactTopXidLogged(), and XLogRecordAssemble().

◆ IsTransactionBlock()

◆ IsTransactionOrTransactionBlock()

◆ IsTransactionState()

bool IsTransactionState ( void  )

Definition at line 384 of file xact.c.

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

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

589 {
591 
593 }
bool IsSubxactTopXidLogPending(void)
Definition: xact.c:556

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

3942 {
3943  TransactionState s;
3944  bool result;
3945 
3946  /* Set up to commit the current transaction */
3947  result = EndTransactionBlock(false);
3948 
3949  /* If successful, change outer tblock state to PREPARE */
3950  if (result)
3951  {
3953 
3954  while (s->parent != NULL)
3955  s = s->parent;
3956 
3957  if (s->blockState == TBLOCK_END)
3958  {
3959  /* Save GID where PrepareTransaction can find it again */
3961 
3963  }
3964  else
3965  {
3966  /*
3967  * ignore case where we are not in a transaction;
3968  * EndTransactionBlock already issued a warning.
3969  */
3972  /* Don't send back a PREPARE result tag... */
3973  result = false;
3974  }
3975  }
3976 
3977  return result;
3978 }
static char * prepareGID
Definition: xact.c:285
bool EndTransactionBlock(bool chain)
Definition: xact.c:3993

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

3585 {
3586  /*
3587  * xact block already started?
3588  */
3589  if (IsTransactionBlock())
3590  ereport(ERROR,
3591  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3592  /* translator: %s represents an SQL statement name */
3593  errmsg("%s cannot run inside a transaction block",
3594  stmtType)));
3595 
3596  /*
3597  * subtransaction?
3598  */
3599  if (IsSubTransaction())
3600  ereport(ERROR,
3601  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3602  /* translator: %s represents an SQL statement name */
3603  errmsg("%s cannot run inside a subtransaction",
3604  stmtType)));
3605 
3606  /*
3607  * inside a pipeline that has started an implicit transaction?
3608  */
3610  ereport(ERROR,
3611  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3612  /* translator: %s represents an SQL statement name */
3613  errmsg("%s cannot be executed within a pipeline",
3614  stmtType)));
3615 
3616  /*
3617  * inside a function call?
3618  */
3619  if (!isTopLevel)
3620  ereport(ERROR,
3621  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3622  /* translator: %s represents an SQL statement name */
3623  errmsg("%s cannot be executed from a function", stmtType)));
3624 
3625  /* If we got past IsTransactionBlock test, should be in default state */
3628  elog(FATAL, "cannot prevent transaction chain");
3629 
3630  /* All okay. Set the flag to make sure the right thing happens later. */
3632 }
#define XACT_FLAGS_NEEDIMMEDIATECOMMIT
Definition: xact.h:114

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

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

◆ RegisterSubXactCallback()

void RegisterSubXactCallback ( SubXactCallback  callback,
void *  arg 
)

Definition at line 3813 of file xact.c.

3814 {
3815  SubXactCallbackItem *item;
3816 
3817  item = (SubXactCallbackItem *)
3819  item->callback = callback;
3820  item->arg = arg;
3821  item->next = SubXact_callbacks;
3822  SubXact_callbacks = item;
3823 }
MemoryContext TopMemoryContext
Definition: mcxt.c:149
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1180
void * arg
struct SubXactCallbackItem * next
Definition: xact.c:319
SubXactCallback callback
Definition: xact.c:320
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46
static SubXactCallbackItem * SubXact_callbacks
Definition: xact.c:324

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

3754 {
3755  XactCallbackItem *item;
3756 
3757  item = (XactCallbackItem *)
3759  item->callback = callback;
3760  item->arg = arg;
3761  item->next = Xact_callbacks;
3762  Xact_callbacks = item;
3763 }
struct XactCallbackItem * next
Definition: xact.c:307
void * arg
Definition: xact.c:309
XactCallback callback
Definition: xact.c:308
static XactCallbackItem * Xact_callbacks
Definition: xact.c:312

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

4718 {
4720 
4721  /*
4722  * We do not check for parallel mode here. It's permissible to start and
4723  * end "internal" subtransactions while in parallel mode, so long as no
4724  * new XIDs or command IDs are assigned.
4725  */
4726 
4727  if (s->blockState != TBLOCK_SUBINPROGRESS)
4728  elog(ERROR, "ReleaseCurrentSubTransaction: unexpected state %s",
4730  Assert(s->state == TRANS_INPROGRESS);
4733  s = CurrentTransactionState; /* changed by pop */
4734  Assert(s->state == TRANS_INPROGRESS);
4735 }
MemoryContext CurTransactionContext
Definition: mcxt.c:155
MemoryContextSwitchTo(old_ctx)
static void CommitSubTransaction(void)
Definition: xact.c:5048

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

4408 {
4410  TransactionState target,
4411  xact;
4412 
4413  /*
4414  * Workers synchronize transaction state at the beginning of each parallel
4415  * operation, so we can't account for transaction state change after that
4416  * point. (Note that this check will certainly error out if s->blockState
4417  * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4418  * below.)
4419  */
4421  ereport(ERROR,
4422  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4423  errmsg("cannot release savepoints during a parallel operation")));
4424 
4425  switch (s->blockState)
4426  {
4427  /*
4428  * We can't release a savepoint if there is no savepoint defined.
4429  */
4430  case TBLOCK_INPROGRESS:
4431  ereport(ERROR,
4432  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4433  errmsg("savepoint \"%s\" does not exist", name)));
4434  break;
4435 
4437  /* See comment about implicit transactions in DefineSavepoint */
4438  ereport(ERROR,
4439  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4440  /* translator: %s represents an SQL statement name */
4441  errmsg("%s can only be used in transaction blocks",
4442  "RELEASE SAVEPOINT")));
4443  break;
4444 
4445  /*
4446  * We are in a non-aborted subtransaction. This is the only valid
4447  * case.
4448  */
4449  case TBLOCK_SUBINPROGRESS:
4450  break;
4451 
4452  /* These cases are invalid. */
4453  case TBLOCK_DEFAULT:
4454  case TBLOCK_STARTED:
4455  case TBLOCK_BEGIN:
4457  case TBLOCK_SUBBEGIN:
4458  case TBLOCK_END:
4459  case TBLOCK_SUBRELEASE:
4460  case TBLOCK_SUBCOMMIT:
4461  case TBLOCK_ABORT:
4462  case TBLOCK_SUBABORT:
4463  case TBLOCK_ABORT_END:
4464  case TBLOCK_SUBABORT_END:
4465  case TBLOCK_ABORT_PENDING:
4467  case TBLOCK_SUBRESTART:
4469  case TBLOCK_PREPARE:
4470  elog(FATAL, "ReleaseSavepoint: unexpected state %s",
4472  break;
4473  }
4474 
4475  for (target = s; PointerIsValid(target); target = target->parent)
4476  {
4477  if (PointerIsValid(target->name) && strcmp(target->name, name) == 0)
4478  break;
4479  }
4480 
4481  if (!PointerIsValid(target))
4482  ereport(ERROR,
4483  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4484  errmsg("savepoint \"%s\" does not exist", name)));
4485 
4486  /* disallow crossing savepoint level boundaries */
4487  if (target->savepointLevel != s->savepointLevel)
4488  ereport(ERROR,
4489  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4490  errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
4491 
4492  /*
4493  * Mark "commit pending" all subtransactions up to the target
4494  * subtransaction. The actual commits will happen when control gets to
4495  * CommitTransactionCommand.
4496  */
4497  xact = CurrentTransactionState;
4498  for (;;)
4499  {
4501  xact->blockState = TBLOCK_SUBRELEASE;
4502  if (xact == target)
4503  break;
4504  xact = xact->parent;
4505  Assert(PointerIsValid(xact));
4506  }
4507 }
#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 3662 of file xact.c.

3663 {
3664  CheckTransactionBlock(isTopLevel, true, stmtType);
3665 }
static void CheckTransactionBlock(bool isTopLevel, bool throwError, const char *stmtType)
Definition: xact.c:3671

References CheckTransactionBlock().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

◆ RestoreTransactionCharacteristics()

◆ RollbackAndReleaseCurrentSubTransaction()

void RollbackAndReleaseCurrentSubTransaction ( void  )

Definition at line 4745 of file xact.c.

4746 {
4748 
4749  /*
4750  * We do not check for parallel mode here. It's permissible to start and
4751  * end "internal" subtransactions while in parallel mode, so long as no
4752  * new XIDs or command IDs are assigned.
4753  */
4754 
4755  switch (s->blockState)
4756  {
4757  /* Must be in a subtransaction */
4758  case TBLOCK_SUBINPROGRESS:
4759  case TBLOCK_SUBABORT:
4760  break;
4761 
4762  /* These cases are invalid. */
4763  case TBLOCK_DEFAULT:
4764  case TBLOCK_STARTED:
4765  case TBLOCK_BEGIN:
4768  case TBLOCK_SUBBEGIN:
4769  case TBLOCK_INPROGRESS:
4770  case TBLOCK_END:
4771  case TBLOCK_SUBRELEASE:
4772  case TBLOCK_SUBCOMMIT:
4773  case TBLOCK_ABORT:
4774  case TBLOCK_ABORT_END:
4775  case TBLOCK_SUBABORT_END:
4776  case TBLOCK_ABORT_PENDING:
4778  case TBLOCK_SUBRESTART:
4780  case TBLOCK_PREPARE:
4781  elog(FATAL, "RollbackAndReleaseCurrentSubTransaction: unexpected state %s",
4783  break;
4784  }
4785 
4786  /*
4787  * Abort the current subtransaction, if needed.
4788  */
4789  if (s->blockState == TBLOCK_SUBINPROGRESS)
4791 
4792  /* And clean it up, too */
4794 
4795  s = CurrentTransactionState; /* changed by pop */
4797  s->blockState == TBLOCK_INPROGRESS ||
4800  s->blockState == TBLOCK_STARTED);
4801 }

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

4517 {
4519  TransactionState target,
4520  xact;
4521 
4522  /*
4523  * Workers synchronize transaction state at the beginning of each parallel
4524  * operation, so we can't account for transaction state change after that
4525  * point. (Note that this check will certainly error out if s->blockState
4526  * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4527  * below.)
4528  */
4530  ereport(ERROR,
4531  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4532  errmsg("cannot rollback to savepoints during a parallel operation")));
4533 
4534  switch (s->blockState)
4535  {
4536  /*
4537  * We can't rollback to a savepoint if there is no savepoint
4538  * defined.
4539  */
4540  case TBLOCK_INPROGRESS:
4541  case TBLOCK_ABORT:
4542  ereport(ERROR,
4543  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4544  errmsg("savepoint \"%s\" does not exist", name)));
4545  break;
4546 
4548  /* See comment about implicit transactions in DefineSavepoint */
4549  ereport(ERROR,
4550  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4551  /* translator: %s represents an SQL statement name */
4552  errmsg("%s can only be used in transaction blocks",
4553  "ROLLBACK TO SAVEPOINT")));
4554  break;
4555 
4556  /*
4557  * There is at least one savepoint, so proceed.
4558  */
4559  case TBLOCK_SUBINPROGRESS:
4560  case TBLOCK_SUBABORT:
4561  break;
4562 
4563  /* These cases are invalid. */
4564  case TBLOCK_DEFAULT:
4565  case TBLOCK_STARTED:
4566  case TBLOCK_BEGIN:
4568  case TBLOCK_SUBBEGIN:
4569  case TBLOCK_END:
4570  case TBLOCK_SUBRELEASE:
4571  case TBLOCK_SUBCOMMIT:
4572  case TBLOCK_ABORT_END:
4573  case TBLOCK_SUBABORT_END:
4574  case TBLOCK_ABORT_PENDING:
4576  case TBLOCK_SUBRESTART:
4578  case TBLOCK_PREPARE:
4579  elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4581  break;
4582  }
4583 
4584  for (target = s; PointerIsValid(target); target = target->parent)
4585  {
4586  if (PointerIsValid(target->name) && strcmp(target->name, name) == 0)
4587  break;
4588  }
4589 
4590  if (!PointerIsValid(target))
4591  ereport(ERROR,
4592  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4593  errmsg("savepoint \"%s\" does not exist", name)));
4594 
4595  /* disallow crossing savepoint level boundaries */
4596  if (target->savepointLevel != s->savepointLevel)
4597  ereport(ERROR,
4598  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4599  errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
4600 
4601  /*
4602  * Mark "abort pending" all subtransactions up to the target
4603  * subtransaction. The actual aborts will happen when control gets to
4604  * CommitTransactionCommand.
4605  */
4606  xact = CurrentTransactionState;
4607  for (;;)
4608  {
4609  if (xact == target)
4610  break;
4611  if (xact->blockState == TBLOCK_SUBINPROGRESS)
4613  else if (xact->blockState == TBLOCK_SUBABORT)
4615  else
4616  elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4618  xact = xact->parent;
4619  Assert(PointerIsValid(xact));
4620  }
4621 
4622  /* And mark the target as "restart pending" */
4623  if (xact->blockState == TBLOCK_SUBINPROGRESS)
4624  xact->blockState = TBLOCK_SUBRESTART;
4625  else if (xact->blockState == TBLOCK_SUBABORT)
4627  else
4628  elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4630 }

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

5492 {
5493  TransactionState s;
5494  Size nxids = 0;
5495  Size i = 0;
5496  TransactionId *workspace;
5498 
5499  result = (SerializedTransactionState *) start_address;
5500 
5501  result->xactIsoLevel = XactIsoLevel;
5502  result->xactDeferrable = XactDeferrable;
5504  result->currentFullTransactionId =
5507 
5508  /*
5509  * If we're running in a parallel worker and launching a parallel worker
5510  * of our own, we can just pass along the information that was passed to
5511  * us.
5512  */
5513  if (nParallelCurrentXids > 0)
5514  {
5516  memcpy(&result->parallelCurrentXids[0], ParallelCurrentXids,
5518  return;
5519  }
5520 
5521  /*
5522  * OK, we need to generate a sorted list of XIDs that our workers should
5523  * view as current. First, figure out how many there are.
5524  */
5525  for (s = CurrentTransactionState; s != NULL; s = s->parent)
5526  {
5528  nxids = add_size(nxids, 1);
5529  nxids = add_size(nxids, s->nChildXids);
5530  }
5532  <= maxsize);
5533 
5534  /* Copy them to our scratch space. */
5535  workspace = palloc(nxids * sizeof(TransactionId));
5536  for (s = CurrentTransactionState; s != NULL; s = s->parent)
5537  {
5539  workspace[i++] = XidFromFullTransactionId(s->fullTransactionId);
5540  if (s->nChildXids > 0)
5541  memcpy(&workspace[i], s->childXids,
5542  s->nChildXids * sizeof(TransactionId));
5543  i += s->nChildXids;
5544  }
5545  Assert(i == nxids);
5546 
5547  /* Sort them. */
5548  qsort(workspace, nxids, sizeof(TransactionId), xidComparator);
5549 
5550  /* Copy data into output area. */
5551  result->nParallelCurrentXids = nxids;
5552  memcpy(&result->parallelCurrentXids[0], workspace,
5553  nxids * sizeof(TransactionId));
5554 }
int i
Definition: isn.c:73
void * palloc(Size size)
Definition: mcxt.c:1316
#define qsort(a, b, c, d)
Definition: port.h:449
FullTransactionId currentFullTransactionId
Definition: xact.c:229
FullTransactionId topFullTransactionId
Definition: xact.c:228
CommandId currentCommandId
Definition: xact.c:230
TransactionId parallelCurrentXids[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.c:232
TransactionId * childXids
Definition: xact.c:203
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 856 of file xact.c.

857 {
859  xactStartTimestamp = xact_ts;
860  stmtStartTimestamp = stmt_ts;
861 }

References Assert, IsParallelWorker, stmtStartTimestamp, and xactStartTimestamp.

Referenced by ParallelWorkerMain().

◆ StartParallelWorkerTransaction()

void StartParallelWorkerTransaction ( char *  tstatespace)

Definition at line 5562 of file xact.c.

5563 {
5565 
5567  StartTransaction();
5568 
5569  tstate = (SerializedTransactionState *) tstatespace;
5570  XactIsoLevel = tstate->xactIsoLevel;
5571  XactDeferrable = tstate->xactDeferrable;
5574  tstate->currentFullTransactionId;
5578 
5580 }
static void StartTransaction(void)
Definition: xact.c:2014

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

2996 {
2998 
2999  switch (s->blockState)
3000  {
3001  /*
3002  * if we aren't in a transaction block, we just do our usual start
3003  * transaction.
3004  */
3005  case TBLOCK_DEFAULT:
3006  StartTransaction();
3008  break;
3009 
3010  /*
3011  * We are somewhere in a transaction block or subtransaction and
3012  * about to start a new command. For now we do nothing, but
3013  * someday we may do command-local resource initialization. (Note
3014  * that any needed CommandCounterIncrement was done by the
3015  * previous CommitTransactionCommand.)
3016  */
3017  case TBLOCK_INPROGRESS:
3019  case TBLOCK_SUBINPROGRESS:
3020  break;
3021 
3022  /*
3023  * Here we are in a failed transaction block (one of the commands
3024  * caused an abort) so we do nothing but remain in the abort
3025  * state. Eventually we will get a ROLLBACK command which will
3026  * get us out of this state. (It is up to other code to ensure
3027  * that no commands other than ROLLBACK will be processed in these
3028  * states.)
3029  */
3030  case TBLOCK_ABORT:
3031  case TBLOCK_SUBABORT:
3032  break;
3033 
3034  /* These cases are invalid. */
3035  case TBLOCK_STARTED:
3036  case TBLOCK_BEGIN:
3038  case TBLOCK_SUBBEGIN:
3039  case TBLOCK_END:
3040  case TBLOCK_SUBRELEASE:
3041  case TBLOCK_SUBCOMMIT:
3042  case TBLOCK_ABORT_END:
3043  case TBLOCK_SUBABORT_END:
3044  case TBLOCK_ABORT_PENDING:
3046  case TBLOCK_SUBRESTART:
3048  case TBLOCK_PREPARE:
3049  elog(ERROR, "StartTransactionCommand: unexpected state %s",
3051  break;
3052  }
3053 
3054  /*
3055  * We must switch to CurTransactionContext before returning. This is
3056  * already done if we called StartTransaction, otherwise not.
3057  */
3058  Assert(CurTransactionContext != NULL);
3060 }

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

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

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

Referenced by fmgr_sql().

◆ TransactionBlockStatusCode()

char TransactionBlockStatusCode ( void  )

Definition at line 4947 of file xact.c.

4948 {
4950 
4951  switch (s->blockState)
4952  {
4953  case TBLOCK_DEFAULT:
4954  case TBLOCK_STARTED:
4955  return 'I'; /* idle --- not in transaction */
4956  case TBLOCK_BEGIN:
4957  case TBLOCK_SUBBEGIN:
4958  case TBLOCK_INPROGRESS:
4961  case TBLOCK_SUBINPROGRESS:
4962  case TBLOCK_END:
4963  case TBLOCK_SUBRELEASE:
4964  case TBLOCK_SUBCOMMIT:
4965  case TBLOCK_PREPARE:
4966  return 'T'; /* in transaction */
4967  case TBLOCK_ABORT:
4968  case TBLOCK_SUBABORT:
4969  case TBLOCK_ABORT_END:
4970  case TBLOCK_SUBABORT_END:
4971  case TBLOCK_ABORT_PENDING:
4973  case TBLOCK_SUBRESTART:
4975  return 'E'; /* in failed transaction */
4976  }
4977 
4978  /* should never get here */
4979  elog(FATAL, "invalid transaction block state: %s",
4981  return 0; /* keep compiler quiet */
4982 }

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

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

3827 {
3828  SubXactCallbackItem *item;
3829  SubXactCallbackItem *prev;
3830 
3831  prev = NULL;
3832  for (item = SubXact_callbacks; item; prev = item, item = item->next)
3833  {
3834  if (item->callback == callback && item->arg == arg)
3835  {
3836  if (prev)
3837  prev->next = item->next;
3838  else
3839  SubXact_callbacks = item->next;
3840  pfree(item);
3841  break;
3842  }
3843  }
3844 }
void pfree(void *pointer)
Definition: mcxt.c:1520

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

◆ UnregisterXactCallback()

void UnregisterXactCallback ( XactCallback  callback,
void *  arg 
)

Definition at line 3766 of file xact.c.

3767 {
3768  XactCallbackItem *item;
3769  XactCallbackItem *prev;
3770 
3771  prev = NULL;
3772  for (item = Xact_callbacks; item; prev = item, item = item->next)
3773  {
3774  if (item->callback == callback && item->arg == arg)
3775  {
3776  if (prev)
3777  prev->next = item->next;
3778  else
3779  Xact_callbacks = item->next;
3780  pfree(item);
3781  break;
3782  }
3783  }
3784 }

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

◆ UserAbortTransactionBlock()

void UserAbortTransactionBlock ( bool  chain)

Definition at line 4153 of file xact.c.

4154 {
4156 
4157  switch (s->blockState)
4158  {
4159  /*
4160  * We are inside a transaction block and we got a ROLLBACK command
4161  * from the user, so tell CommitTransactionCommand to abort and
4162  * exit the transaction block.
4163  */
4164  case TBLOCK_INPROGRESS:
4166  break;
4167 
4168  /*
4169  * We are inside a failed transaction block and we got a ROLLBACK
4170  * command from the user. Abort processing is already done, so
4171  * CommitTransactionCommand just has to cleanup and go back to
4172  * idle state.
4173  */
4174  case TBLOCK_ABORT:
4176  break;
4177 
4178  /*
4179  * We are inside a subtransaction. Mark everything up to top
4180  * level as exitable.
4181  */
4182  case TBLOCK_SUBINPROGRESS:
4183  case TBLOCK_SUBABORT:
4184  while (s->parent != NULL)
4185  {
4186  if (s->blockState == TBLOCK_SUBINPROGRESS)
4188  else if (s->blockState == TBLOCK_SUBABORT)
4190  else
4191  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4193  s = s->parent;
4194  }
4195  if (s->blockState == TBLOCK_INPROGRESS)
4197  else if (s->blockState == TBLOCK_ABORT)
4199  else
4200  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4202  break;
4203 
4204  /*
4205  * The user issued ABORT when not inside a transaction. For
4206  * ROLLBACK without CHAIN, issue a WARNING and go to abort state.
4207  * The upcoming call to CommitTransactionCommand() will then put
4208  * us back into the default state. For ROLLBACK AND CHAIN, error.
4209  *
4210  * We do the same thing with ABORT inside an implicit transaction,
4211  * although in this case we might be rolling back actual database
4212  * state changes. (It's debatable whether we should issue a
4213  * WARNING in this case, but we have done so historically.)
4214  */
4215  case TBLOCK_STARTED:
4217  if (chain)
4218  ereport(ERROR,
4219  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4220  /* translator: %s represents an SQL statement name */
4221  errmsg("%s can only be used in transaction blocks",
4222  "ROLLBACK AND CHAIN")));
4223  else
4224  ereport(WARNING,
4225  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4226  errmsg("there is no transaction in progress")));
4228  break;
4229 
4230  /*
4231  * The user issued an ABORT that somehow ran inside a parallel
4232  * worker. We can't cope with that.
4233  */
4235  ereport(FATAL,
4236  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4237  errmsg("cannot abort during a parallel operation")));
4238  break;
4239 
4240  /* These cases are invalid. */
4241  case TBLOCK_DEFAULT:
4242  case TBLOCK_BEGIN:
4243  case TBLOCK_SUBBEGIN:
4244  case TBLOCK_END:
4245  case TBLOCK_SUBRELEASE:
4246  case TBLOCK_SUBCOMMIT:
4247  case TBLOCK_ABORT_END:
4248  case TBLOCK_SUBABORT_END:
4249  case TBLOCK_ABORT_PENDING:
4251  case TBLOCK_SUBRESTART:
4253  case TBLOCK_PREPARE:
4254  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4256  break;
4257  }
4258 
4261 
4262  s->chain = chain;
4263 }

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

3657 {
3658  CheckTransactionBlock(isTopLevel, false, stmtType);
3659 }

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

6315 {
6316  uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
6317 
6318  /* Backup blocks are not used in xact records */
6319  Assert(!XLogRecHasAnyBlockRefs(record));
6320 
6321  if (info == XLOG_XACT_COMMIT)
6322  {
6323  xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6324  xl_xact_parsed_commit parsed;
6325 
6326  ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6327  xact_redo_commit(&parsed, XLogRecGetXid(record),
6328  record->EndRecPtr, XLogRecGetOrigin(record));
6329  }
6330  else if (info == XLOG_XACT_COMMIT_PREPARED)
6331  {
6332  xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6333  xl_xact_parsed_commit parsed;
6334 
6335  ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6336  xact_redo_commit(&parsed, parsed.twophase_xid,
6337  record->EndRecPtr, XLogRecGetOrigin(record));
6338 
6339  /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6340  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6341  PrepareRedoRemove(parsed.twophase_xid, false);
6342  LWLockRelease(TwoPhaseStateLock);
6343  }
6344  else if (info == XLOG_XACT_ABORT)
6345  {
6346  xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6347  xl_xact_parsed_abort parsed;
6348 
6349  ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6350  xact_redo_abort(&parsed, XLogRecGetXid(record),
6351  record->EndRecPtr, XLogRecGetOrigin(record));
6352  }
6353  else if (info == XLOG_XACT_ABORT_PREPARED)
6354  {
6355  xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6356  xl_xact_parsed_abort parsed;
6357 
6358  ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6359  xact_redo_abort(&parsed, parsed.twophase_xid,
6360  record->EndRecPtr, XLogRecGetOrigin(record));
6361 
6362  /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6363  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6364  PrepareRedoRemove(parsed.twophase_xid, false);
6365  LWLockRelease(TwoPhaseStateLock);
6366  }
6367  else if (info == XLOG_XACT_PREPARE)
6368  {
6369  /*
6370  * Store xid and start/end pointers of the WAL record in TwoPhaseState
6371  * gxact entry.
6372  */
6373  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6375  record->ReadRecPtr,
6376  record->EndRecPtr,
6377  XLogRecGetOrigin(record));
6378  LWLockRelease(TwoPhaseStateLock);
6379  }
6380  else if (info == XLOG_XACT_ASSIGNMENT)
6381  {
6383 
6386  xlrec->nsubxacts, xlrec->xsub);
6387  }
6388  else if (info == XLOG_XACT_INVALIDATIONS)
6389  {
6390  /*
6391  * XXX we do ignore this for now, what matters are invalidations
6392  * written into the commit record.
6393  */
6394  }
6395  else
6396  elog(PANIC, "xact_redo: unknown op code %u", info);
6397 }
#define PANIC
Definition: elog.h:42
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1170
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1783
@ LW_EXCLUSIVE
Definition: lwlock.h:114
void ProcArrayApplyXidAssignment(TransactionId topxid, int nsubxids, TransactionId *subxids)
Definition: procarray.c:1306
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:2582
void PrepareRedoAdd(char *buf, XLogRecPtr start_lsn, XLogRecPtr end_lsn, RepOriginId origin_id)
Definition: twophase.c:2480
static void xact_redo_commit(xl_xact_parsed_commit *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:6081
static void xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:6235
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:50

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

◆ xactGetCommittedChildren()

int xactGetCommittedChildren ( TransactionId **  ptr)

Definition at line 5741 of file xact.c.

5742 {
5744 
5745  if (s->nChildXids == 0)
5746  *ptr = NULL;
5747  else
5748  *ptr = s->childXids;
5749 
5750  return s->nChildXids;
5751 }

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

5943 {
5944  xl_xact_abort xlrec;
5945  xl_xact_xinfo xl_xinfo;
5946  xl_xact_subxacts xl_subxacts;
5947  xl_xact_relfilelocators xl_relfilelocators;
5948  xl_xact_stats_items xl_dropped_stats;
5949  xl_xact_twophase xl_twophase;
5950  xl_xact_dbinfo xl_dbinfo;
5951  xl_xact_origin xl_origin;
5952 
5953  uint8 info;
5954 
5955  Assert(CritSectionCount > 0);
5956 
5957  xl_xinfo.xinfo = 0;
5958 
5959  /* decide between a plain and 2pc abort */
5960  if (!TransactionIdIsValid(twophase_xid))
5961  info = XLOG_XACT_ABORT;
5962  else
5963  info = XLOG_XACT_ABORT_PREPARED;
5964 
5965 
5966  /* First figure out and collect all the information needed */
5967 
5968  xlrec.xact_time = abort_time;
5969 
5970  if ((xactflags & XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK))
5971  xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5972 
5973  if (nsubxacts > 0)
5974  {
5975  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5976  xl_subxacts.nsubxacts = nsubxacts;
5977  }
5978 
5979  if (nrels > 0)
5980  {
5982  xl_relfilelocators.nrels = nrels;
5983  info |= XLR_SPECIAL_REL_UPDATE;
5984  }
5985 
5986  if (ndroppedstats > 0)
5987  {
5988  xl_xinfo.xinfo |= XACT_XINFO_HAS_DROPPED_STATS;
5989  xl_dropped_stats.nitems = ndroppedstats;
5990  }
5991 
5992  if (TransactionIdIsValid(twophase_xid))
5993  {
5994  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5995  xl_twophase.xid = twophase_xid;
5996  Assert(twophase_gid != NULL);
5997 
5998  if (XLogLogicalInfoActive())
5999  xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
6000  }
6001 
6002  if (TransactionIdIsValid(twophase_xid) && XLogLogicalInfoActive())
6003  {
6004  xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
6005  xl_dbinfo.dbId = MyDatabaseId;
6006  xl_dbinfo.tsId = MyDatabaseTableSpace;
6007  }
6008 
6009  /*
6010  * Dump transaction origin information. We need this during recovery to
6011  * update the replication origin progress.
6012  */
6014  {
6015  xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
6016 
6019  }
6020 
6021  if (xl_xinfo.xinfo != 0)
6022  info |= XLOG_XACT_HAS_INFO;
6023 
6024  /* Then include all the collected data into the abort record. */
6025 
6026  XLogBeginInsert();
6027 
6028  XLogRegisterData((char *) (&xlrec), MinSizeOfXactAbort);
6029 
6030  if (xl_xinfo.xinfo != 0)
6031  XLogRegisterData((char *) (&xl_xinfo), sizeof(xl_xinfo));
6032 
6033  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
6034  XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
6035 
6036  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
6037  {
6038  XLogRegisterData((char *) (&xl_subxacts),
6040  XLogRegisterData((char *) subxacts,
6041  nsubxacts * sizeof(TransactionId));
6042  }
6043 
6044  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILELOCATORS)
6045  {
6046  XLogRegisterData((char *) (&xl_relfilelocators),
6048  XLogRegisterData((char *) rels,
6049  nrels * sizeof(RelFileLocator));
6050  }
6051 
6052  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
6053  {
6054  XLogRegisterData((char *) (&xl_dropped_stats),
6056  XLogRegisterData((char *) droppedstats,
6057  ndroppedstats * sizeof(xl_xact_stats_item));
6058  }
6059 
6060  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
6061  {
6062  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
6063  if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
6064  XLogRegisterData(unconstify(char *, twophase_gid), strlen(twophase_gid) + 1);
6065  }
6066 
6067  if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
6068  XLogRegisterData((char *) (&xl_origin), sizeof(xl_xact_origin));
6069 
6070  /* Include the replication origin */
6072 
6073  return XLogInsert(RM_XACT_ID, info);
6074 }
#define unconstify(underlying_type, expr)
Definition: c.h:1245
Oid MyDatabaseTableSpace
Definition: globals.c:93
volatile uint32 CritSectionCount
Definition: globals.c:43
Oid MyDatabaseId
Definition: globals.c:91
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:152
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 5765 of file xact.c.

5773 {
5774  xl_xact_commit xlrec;
5775  xl_xact_xinfo xl_xinfo;
5776  xl_xact_dbinfo xl_dbinfo;
5777  xl_xact_subxacts xl_subxacts;
5778  xl_xact_relfilelocators xl_relfilelocators;
5779  xl_xact_stats_items xl_dropped_stats;
5780  xl_xact_invals xl_invals;
5781  xl_xact_twophase xl_twophase;
5782  xl_xact_origin xl_origin;
5783  uint8 info;
5784 
5785  Assert(CritSectionCount > 0);
5786 
5787  xl_xinfo.xinfo = 0;
5788 
5789  /* decide between a plain and 2pc commit */
5790  if (!TransactionIdIsValid(twophase_xid))
5791  info = XLOG_XACT_COMMIT;
5792  else
5794 
5795  /* First figure out and collect all the information needed */
5796 
5797  xlrec.xact_time = commit_time;
5798 
5799  if (relcacheInval)
5801  if (forceSyncCommit)
5803  if ((xactflags & XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK))
5804  xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5805 
5806  /*
5807  * Check if the caller would like to ask standbys for immediate feedback
5808  * once this commit is applied.
5809  */
5812 
5813  /*
5814  * Relcache invalidations requires information about the current database
5815  * and so does logical decoding.
5816  */
5817  if (nmsgs > 0 || XLogLogicalInfoActive())
5818  {
5819  xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5820  xl_dbinfo.dbId = MyDatabaseId;
5821  xl_dbinfo.tsId = MyDatabaseTableSpace;
5822  }
5823 
5824  if (nsubxacts > 0)
5825  {
5826  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5827  xl_subxacts.nsubxacts = nsubxacts;
5828  }
5829 
5830  if (nrels > 0)
5831  {
5833  xl_relfilelocators.nrels = nrels;
5834  info |= XLR_SPECIAL_REL_UPDATE;
5835  }
5836 
5837  if (ndroppedstats > 0)
5838  {
5839  xl_xinfo.xinfo |= XACT_XINFO_HAS_DROPPED_STATS;
5840  xl_dropped_stats.nitems = ndroppedstats;
5841  }
5842 
5843  if (nmsgs > 0)
5844  {
5845  xl_xinfo.xinfo |= XACT_XINFO_HAS_INVALS;
5846  xl_invals.nmsgs = nmsgs;
5847  }
5848 
5849  if (TransactionIdIsValid(twophase_xid))
5850  {
5851  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5852  xl_twophase.xid = twophase_xid;
5853  Assert(twophase_gid != NULL);
5854 
5855  if (XLogLogicalInfoActive())
5856  xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
5857  }
5858 
5859  /* dump transaction origin information */
5861  {
5862  xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
5863 
5866  }
5867 
5868  if (xl_xinfo.xinfo != 0)
5869  info |= XLOG_XACT_HAS_INFO;
5870 
5871  /* Then include all the collected data into the commit record. */
5872 
5873  XLogBeginInsert();
5874 
5875  XLogRegisterData((char *) (&xlrec), sizeof(xl_xact_commit));
5876 
5877  if (xl_xinfo.xinfo != 0)
5878  XLogRegisterData((char *) (&xl_xinfo.xinfo), sizeof(xl_xinfo.xinfo));
5879 
5880  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5881  XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
5882 
5883  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5884  {
5885  XLogRegisterData((char *) (&xl_subxacts),
5887  XLogRegisterData((char *) subxacts,
5888  nsubxacts * sizeof(TransactionId));
5889  }
5890 
5891  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILELOCATORS)
5892  {
5893  XLogRegisterData((char *) (&xl_relfilelocators),
5895  XLogRegisterData((char *) rels,
5896  nrels * sizeof(RelFileLocator));
5897  }
5898 
5899  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
5900  {
5901  XLogRegisterData((char *) (&xl_dropped_stats),
5903  XLogRegisterData((char *) droppedstats,
5904  ndroppedstats * sizeof(xl_xact_stats_item));
5905  }
5906 
5907  if (xl_xinfo.xinfo & XACT_XINFO_HAS_INVALS)
5908  {
5909  XLogRegisterData((char *) (&xl_invals), MinSizeOfXactInvals);
5910  XLogRegisterData((char *) msgs,
5911  nmsgs * sizeof(SharedInvalidationMessage));
5912  }
5913 
5914  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5915  {
5916  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5917  if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
5918  XLogRegisterData(unconstify(char *, twophase_gid), strlen(twophase_gid) + 1);
5919  }
5920 
5921  if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5922  XLogRegisterData((char *) (&xl_origin), sizeof(xl_xact_origin));
5923 
5924  /* we allow filtering by xacts */
5926 
5927  return XLogInsert(RM_XACT_ID, info);
5928 }
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 293 of file xact.c.

Referenced by check_log_duration(), and StartTransaction().

◆ XactDeferrable

◆ XactIsoLevel

◆ XactReadOnly