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

◆ MinSizeOfXactInvals

#define MinSizeOfXactInvals   offsetof(xl_xact_invals, msgs)

Definition at line 307 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 300 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 408 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{
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 3443 of file xact.c.

3444{
3445 /*
3446 * Repeatedly call AbortCurrentTransactionInternal() until all the work is
3447 * done.
3448 */
3450 {
3451 }
3452}
static bool AbortCurrentTransactionInternal(void)
Definition: xact.c:3461

References AbortCurrentTransactionInternal().

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

◆ AbortOutOfAnyTransaction()

void AbortOutOfAnyTransaction ( void  )

Definition at line 4854 of file xact.c.

4855{
4857
4858 /* Ensure we're not running in a doomed memory context */
4860
4861 /*
4862 * Get out of any transaction or nested transaction
4863 */
4864 do
4865 {
4866 switch (s->blockState)
4867 {
4868 case TBLOCK_DEFAULT:
4869 if (s->state == TRANS_DEFAULT)
4870 {
4871 /* Not in a transaction, do nothing */
4872 }
4873 else
4874 {
4875 /*
4876 * We can get here after an error during transaction start
4877 * (state will be TRANS_START). Need to clean up the
4878 * incompletely started transaction. First, adjust the
4879 * low-level state to suppress warning message from
4880 * AbortTransaction.
4881 */
4882 if (s->state == TRANS_START)
4886 }
4887 break;
4888 case TBLOCK_STARTED:
4889 case TBLOCK_BEGIN:
4890 case TBLOCK_INPROGRESS:
4893 case TBLOCK_END:
4895 case TBLOCK_PREPARE:
4896 /* In a transaction, so clean up */
4900 break;
4901 case TBLOCK_ABORT:
4902 case TBLOCK_ABORT_END:
4903
4904 /*
4905 * AbortTransaction is already done, still need Cleanup.
4906 * However, if we failed partway through running ROLLBACK,
4907 * there will be an active portal running that command, which
4908 * we need to shut down before doing CleanupTransaction.
4909 */
4913 break;
4914
4915 /*
4916 * In a subtransaction, so clean it up and abort parent too
4917 */
4918 case TBLOCK_SUBBEGIN:
4920 case TBLOCK_SUBRELEASE:
4921 case TBLOCK_SUBCOMMIT:
4923 case TBLOCK_SUBRESTART:
4926 s = CurrentTransactionState; /* changed by pop */
4927 break;
4928
4929 case TBLOCK_SUBABORT:
4932 /* As above, but AbortSubTransaction already done */
4933 if (s->curTransactionOwner)
4934 {
4935 /* As in TBLOCK_ABORT, might have a live portal to zap */
4940 }
4942 s = CurrentTransactionState; /* changed by pop */
4943 break;
4944 }
4945 } while (s->blockState != TBLOCK_DEFAULT);
4946
4947 /* Should be out of all subxacts now */
4948 Assert(s->parent == NULL);
4949
4950 /*
4951 * Revert to TopMemoryContext, to ensure we exit in a well-defined state
4952 * whether there were any transactions to close or not. (Callers that
4953 * don't intend to exit soon should switch to some other context to avoid
4954 * long-term memory leaks.)
4955 */
4957}
#define Assert(condition)
Definition: c.h:815
MemoryContext TopMemoryContext
Definition: mcxt.c:149
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
void AtAbort_Portals(void)
Definition: portalmem.c:781
void AtSubAbort_Portals(SubTransactionId mySubid, SubTransactionId parentSubid, ResourceOwner myXactOwner, ResourceOwner parentXactOwner)
Definition: portalmem.c:979
TransState state
Definition: xact.c:198
SubTransactionId subTransactionId
Definition: xact.c:195
struct TransactionStateData * parent
Definition: xact.c:217
TBlockState blockState
Definition: xact.c:199
ResourceOwner curTransactionOwner
Definition: xact.c:203
static void CleanupSubTransaction(void)
Definition: xact.c:5371
static void CleanupTransaction(void)
Definition: xact.c:3001
@ TRANS_INPROGRESS
Definition: xact.c:144
@ TRANS_START
Definition: xact.c:143
@ TRANS_DEFAULT
Definition: xact.c:142
static void AbortSubTransaction(void)
Definition: xact.c:5211
static void AtAbort_Memory(void)
Definition: xact.c:1883
@ TBLOCK_DEFAULT
Definition: xact.c:159
@ TBLOCK_SUBABORT_END
Definition: xact.c:179
@ TBLOCK_STARTED
Definition: xact.c:160
@ TBLOCK_SUBCOMMIT
Definition: xact.c:177
@ TBLOCK_IMPLICIT_INPROGRESS
Definition: xact.c:165
@ TBLOCK_ABORT_END
Definition: xact.c:169
@ TBLOCK_PREPARE
Definition: xact.c:171
@ TBLOCK_ABORT_PENDING
Definition: xact.c:170
@ TBLOCK_ABORT
Definition: xact.c:168
@ TBLOCK_SUBRELEASE
Definition: xact.c:176
@ TBLOCK_SUBBEGIN
Definition: xact.c:174
@ TBLOCK_SUBABORT
Definition: xact.c:178
@ TBLOCK_SUBRESTART
Definition: xact.c:181
@ TBLOCK_INPROGRESS
Definition: xact.c:164
@ TBLOCK_END
Definition: xact.c:167
@ TBLOCK_PARALLEL_INPROGRESS
Definition: xact.c:166
@ TBLOCK_SUBABORT_RESTART
Definition: xact.c:182
@ TBLOCK_SUBABORT_PENDING
Definition: xact.c:180
@ TBLOCK_BEGIN
Definition: xact.c:163
@ TBLOCK_SUBINPROGRESS
Definition: xact.c:175
static void AbortTransaction(void)
Definition: xact.c:2804
static TransactionState CurrentTransactionState
Definition: xact.c:259

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

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

◆ BeginImplicitTransactionBlock()

void BeginImplicitTransactionBlock ( void  )

Definition at line 4318 of file xact.c.

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

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

Referenced by exec_simple_query(), and start_xact_command().

◆ BeginInternalSubTransaction()

void BeginInternalSubTransaction ( const char *  name)

Definition at line 4686 of file xact.c.

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

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

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

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

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

◆ CommandCounterIncrement()

void CommandCounterIncrement ( void  )

Definition at line 1099 of file xact.c.

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

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

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

◆ CommitTransactionCommand()

void CommitTransactionCommand ( void  )

Definition at line 3149 of file xact.c.

3150{
3151 /*
3152 * Repeatedly call CommitTransactionCommandInternal() until all the work
3153 * is done.
3154 */
3156 {
3157 }
3158}
static bool CommitTransactionCommandInternal(void)
Definition: xact.c:3167

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

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

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

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

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

Referenced by exec_simple_query(), and PostgresMain().

◆ EndParallelWorkerTransaction()

void EndParallelWorkerTransaction ( void  )

◆ EndTransactionBlock()

bool EndTransactionBlock ( bool  chain)

Definition at line 4036 of file xact.c.

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

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

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

◆ EnterParallelMode()

◆ EstimateTransactionStateSpace()

Size EstimateTransactionStateSpace ( void  )

Definition at line 5500 of file xact.c.

5501{
5503 Size nxids = 0;
5505
5506 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5507 {
5509 nxids = add_size(nxids, 1);
5510 nxids = add_size(nxids, s->nChildXids);
5511 }
5512
5513 return add_size(size, mul_size(sizeof(TransactionId), nxids));
5514}
uint32 TransactionId
Definition: c.h:609
size_t Size
Definition: c.h:562
Size add_size(Size s1, Size s2)
Definition: shmem.c:488
Size mul_size(Size s1, Size s2)
Definition: shmem.c:505
static pg_noinline void Size size
Definition: slab.c:607
FullTransactionId fullTransactionId
Definition: xact.c:194
#define FullTransactionIdIsValid(x)
Definition: transam.h:55
#define SerializedTransactionStateHeaderSize
Definition: xact.c:238

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

1152{
1153 forceSyncCommit = true;
1154}
static bool forceSyncCommit
Definition: xact.c:292

References forceSyncCommit.

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

◆ GetCurrentCommandId()

CommandId GetCurrentCommandId ( bool  used)

Definition at line 828 of file xact.c.

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

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

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

◆ GetCurrentFullTransactionId()

FullTransactionId GetCurrentFullTransactionId ( void  )

Definition at line 511 of file xact.c.

512{
514
517 return s->fullTransactionId;
518}
static void AssignTransactionId(TransactionState s)
Definition: xact.c:634

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

◆ GetCurrentFullTransactionIdIfAny()

FullTransactionId GetCurrentFullTransactionIdIfAny ( void  )

Definition at line 529 of file xact.c.

References CurrentTransactionState, and TransactionStateData::fullTransactionId.

◆ GetCurrentStatementStartTimestamp()

TimestampTz GetCurrentStatementStartTimestamp ( void  )

Definition at line 878 of file xact.c.

879{
880 return stmtStartTimestamp;
881}
static TimestampTz stmtStartTimestamp
Definition: xact.c:280

References stmtStartTimestamp.

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

◆ GetCurrentSubTransactionId()

◆ GetCurrentTransactionId()

◆ GetCurrentTransactionIdIfAny()

◆ GetCurrentTransactionNestLevel()

◆ GetCurrentTransactionStartTimestamp()

TimestampTz GetCurrentTransactionStartTimestamp ( void  )

◆ GetCurrentTransactionStopTimestamp()

TimestampTz GetCurrentTransactionStopTimestamp ( void  )

Definition at line 890 of file xact.c.

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

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

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

◆ GetStableLatestTransactionId()

TransactionId GetStableLatestTransactionId ( void  )

Definition at line 606 of file xact.c.

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

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

Referenced by xid_age().

◆ GetTopFullTransactionId()

FullTransactionId GetTopFullTransactionId ( void  )

Definition at line 482 of file xact.c.

483{
487}
static TransactionStateData TopTransactionStateData
Definition: xact.c:246
static FullTransactionId XactTopFullTransactionId
Definition: xact.c:124

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

Referenced by pg_current_xact_id().

◆ GetTopFullTransactionIdIfAny()

FullTransactionId GetTopFullTransactionIdIfAny ( void  )

Definition at line 498 of file xact.c.

499{
501}

References XactTopFullTransactionId.

Referenced by pg_current_xact_id_if_assigned().

◆ GetTopTransactionId()

◆ GetTopTransactionIdIfAny()

◆ IsAbortedTransactionBlockState()

◆ IsInParallelMode()

◆ IsInTransactionBlock()

bool IsInTransactionBlock ( bool  isTopLevel)

Definition at line 3761 of file xact.c.

3762{
3763 /*
3764 * Return true on same conditions that would make
3765 * PreventInTransactionBlock error out
3766 */
3767 if (IsTransactionBlock())
3768 return true;
3769
3770 if (IsSubTransaction())
3771 return true;
3772
3773 if (!isTopLevel)
3774 return true;
3775
3778 return true;
3779
3780 return false;
3781}
bool IsSubTransaction(void)
Definition: xact.c:5036
bool IsTransactionBlock(void)
Definition: xact.c:4963

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

Referenced by vacuum().

◆ IsSubTransaction()

◆ IsSubxactTopXidLogPending()

bool IsSubxactTopXidLogPending ( void  )

Definition at line 558 of file xact.c.

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

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

Referenced by MarkSubxactTopXidLogged(), and XLogRecordAssemble().

◆ IsTransactionBlock()

◆ IsTransactionOrTransactionBlock()

◆ IsTransactionState()

bool IsTransactionState ( void  )

Definition at line 386 of file xact.c.

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

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(), PrepareInplaceInvalidationState(), PrepareInvalidationState(), PrepareTempTablespaces(), process_syncing_tables_for_apply(), process_syncing_tables_for_sync(), RelationCacheInvalidate(), RelationFlushRelation(), RelationIdGetRelation(), RelationInitPhysicalAddr(), RelationRebuildRelation(), 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 590 of file xact.c.

591{
593
595}
bool IsSubxactTopXidLogPending(void)
Definition: xact.c:558

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

Referenced by XLogInsertRecord().

◆ ParseAbortRecord()

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

Definition at line 141 of file xactdesc.c.

142{
143 char *data = ((char *) xlrec) + MinSizeOfXactAbort;
144
145 memset(parsed, 0, sizeof(*parsed));
146
147 parsed->xinfo = 0; /* default, if no XLOG_XACT_HAS_INFO is
148 * present */
149
150 parsed->xact_time = xlrec->xact_time;
151
152 if (info & XLOG_XACT_HAS_INFO)
153 {
154 xl_xact_xinfo *xl_xinfo = (xl_xact_xinfo *) data;
155
156 parsed->xinfo = xl_xinfo->xinfo;
157
158 data += sizeof(xl_xact_xinfo);
159 }
160
161 if (parsed->xinfo & XACT_XINFO_HAS_DBINFO)
162 {
163 xl_xact_dbinfo *xl_dbinfo = (xl_xact_dbinfo *) data;
164
165 parsed->dbId = xl_dbinfo->dbId;
166 parsed->tsId = xl_dbinfo->tsId;
167
168 data += sizeof(xl_xact_dbinfo);
169 }
170
171 if (parsed->xinfo & XACT_XINFO_HAS_SUBXACTS)
172 {
173 xl_xact_subxacts *xl_subxacts = (xl_xact_subxacts *) data;
174
175 parsed->nsubxacts = xl_subxacts->nsubxacts;
176 parsed->subxacts = xl_subxacts->subxacts;
177
179 data += parsed->nsubxacts * sizeof(TransactionId);
180 }
181
183 {
185
186 parsed->nrels = xl_rellocator->nrels;
187 parsed->xlocators = xl_rellocator->xlocators;
188
190 data += xl_rellocator->nrels * sizeof(RelFileLocator);
191 }
192
194 {
196
197 parsed->nstats = xl_drops->nitems;
198 parsed->stats = xl_drops->items;
199
201 data += xl_drops->nitems * sizeof(xl_xact_stats_item);
202 }
203
204 if (parsed->xinfo & XACT_XINFO_HAS_TWOPHASE)
205 {
206 xl_xact_twophase *xl_twophase = (xl_xact_twophase *) data;
207
208 parsed->twophase_xid = xl_twophase->xid;
209
210 data += sizeof(xl_xact_twophase);
211
212 if (parsed->xinfo & XACT_XINFO_HAS_GID)
213 {
214 strlcpy(parsed->twophase_gid, data, sizeof(parsed->twophase_gid));
215 data += strlen(data) + 1;
216 }
217 }
218
219 /* Note: no alignment is guaranteed after this point */
220
221 if (parsed->xinfo & XACT_XINFO_HAS_ORIGIN)
222 {
223 xl_xact_origin xl_origin;
224
225 /* no alignment is guaranteed, so copy onto stack */
226 memcpy(&xl_origin, data, sizeof(xl_origin));
227
228 parsed->origin_lsn = xl_origin.origin_lsn;
229 parsed->origin_timestamp = xl_origin.origin_timestamp;
230
231 data += sizeof(xl_xact_origin);
232 }
233}
const void * data
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
struct RelFileLocator RelFileLocator
TimestampTz xact_time
Definition: xact.h:338
Oid tsId
Definition: xact.h:258
Oid dbId
Definition: xact.h:257
TimestampTz origin_timestamp
Definition: xact.h:317
XLogRecPtr origin_lsn
Definition: xact.h:316
xl_xact_stats_item * stats
Definition: xact.h:425
RelFileLocator * xlocators
Definition: xact.h:422
TransactionId twophase_xid
Definition: xact.h:427
TimestampTz xact_time
Definition: xact.h:412
TransactionId * subxacts
Definition: xact.h:419
XLogRecPtr origin_lsn
Definition: xact.h:430
char twophase_gid[GIDSIZE]
Definition: xact.h:428
TimestampTz origin_timestamp
Definition: xact.h:431
RelFileLocator xlocators[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:271
xl_xact_stats_item items[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:298
TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:264
int nsubxacts
Definition: xact.h:263
TransactionId xid
Definition: xact.h:311
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:300
#define XACT_XINFO_HAS_RELFILELOCATORS
Definition: xact.h:190
#define MinSizeOfXactAbort
Definition: xact.h:350
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
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:322
SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:305
int nmsgs
Definition: xact.h:304
xl_xact_stats_item * stats
Definition: xact.h:392
TimestampTz xact_time
Definition: xact.h:379
TransactionId twophase_xid
Definition: xact.h:397
RelFileLocator * xlocators
Definition: xact.h:389
TimestampTz origin_timestamp
Definition: xact.h:405
TransactionId * subxacts
Definition: xact.h:386
char twophase_gid[GIDSIZE]
Definition: xact.h:398
XLogRecPtr origin_lsn
Definition: xact.h:404
SharedInvalidationMessage * msgs
Definition: xact.h:395
#define MinSizeOfXactInvals
Definition: xact.h:307
#define MinSizeOfXactCommit
Definition: xact.h:334
#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:768
RelFileLocator * abortlocators
Definition: xact.h:400
xl_xact_stats_item * abortstats
Definition: xact.h:402
TimestampTz prepared_at
Definition: xact.h:358
int32 nabortrels
Definition: xact.h:362
int32 ninvalmsgs
Definition: xact.h:365
int32 ncommitstats
Definition: xact.h:363
TimestampTz origin_timestamp
Definition: xact.h:369
uint16 gidlen
Definition: xact.h:367
int32 nabortstats
Definition: xact.h:364
Oid database
Definition: xact.h:357
XLogRecPtr origin_lsn
Definition: xact.h:368
int32 ncommitrels
Definition: xact.h:361
TransactionId xid
Definition: xact.h:356
int32 nsubxacts
Definition: xact.h:360

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

3985{
3987 bool result;
3988
3989 /* Set up to commit the current transaction */
3990 result = EndTransactionBlock(false);
3991
3992 /* If successful, change outer tblock state to PREPARE */
3993 if (result)
3994 {
3996
3997 while (s->parent != NULL)
3998 s = s->parent;
3999
4000 if (s->blockState == TBLOCK_END)
4001 {
4002 /* Save GID where PrepareTransaction can find it again */
4004
4006 }
4007 else
4008 {
4009 /*
4010 * ignore case where we are not in a transaction;
4011 * EndTransactionBlock already issued a warning.
4012 */
4015 /* Don't send back a PREPARE result tag... */
4016 result = false;
4017 }
4018 }
4019
4020 return result;
4021}
static char * prepareGID
Definition: xact.c:287
bool EndTransactionBlock(bool chain)
Definition: xact.c:4036

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

3641{
3642 /*
3643 * xact block already started?
3644 */
3645 if (IsTransactionBlock())
3646 ereport(ERROR,
3647 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3648 /* translator: %s represents an SQL statement name */
3649 errmsg("%s cannot run inside a transaction block",
3650 stmtType)));
3651
3652 /*
3653 * subtransaction?
3654 */
3655 if (IsSubTransaction())
3656 ereport(ERROR,
3657 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3658 /* translator: %s represents an SQL statement name */
3659 errmsg("%s cannot run inside a subtransaction",
3660 stmtType)));
3661
3662 /*
3663 * inside a function call?
3664 */
3665 if (!isTopLevel)
3666 ereport(ERROR,
3667 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3668 /* translator: %s represents an SQL statement name */
3669 errmsg("%s cannot be executed from a function", stmtType)));
3670
3671 /* If we got past IsTransactionBlock test, should be in default state */
3674 elog(FATAL, "cannot prevent transaction chain");
3675
3676 /* All okay. Set the flag to make sure the right thing happens later. */
3678}
int MyXactFlags
Definition: xact.c:135
#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, and XACT_FLAGS_NEEDIMMEDIATECOMMIT.

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

◆ RegisterSubXactCallback()

void RegisterSubXactCallback ( SubXactCallback  callback,
void *  arg 
)

Definition at line 3856 of file xact.c.

3857{
3858 SubXactCallbackItem *item;
3859
3860 item = (SubXactCallbackItem *)
3862 item->callback = callback;
3863 item->arg = arg;
3864 item->next = SubXact_callbacks;
3865 SubXact_callbacks = item;
3866}
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1181
void * arg
struct SubXactCallbackItem * next
Definition: xact.c:321
SubXactCallback callback
Definition: xact.c:322
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46
static SubXactCallbackItem * SubXact_callbacks
Definition: xact.c:326

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

3797{
3798 XactCallbackItem *item;
3799
3800 item = (XactCallbackItem *)
3802 item->callback = callback;
3803 item->arg = arg;
3804 item->next = Xact_callbacks;
3805 Xact_callbacks = item;
3806}
struct XactCallbackItem * next
Definition: xact.c:309
void * arg
Definition: xact.c:311
XactCallback callback
Definition: xact.c:310
static XactCallbackItem * Xact_callbacks
Definition: xact.c:314

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

4761{
4763
4764 /*
4765 * We do not check for parallel mode here. It's permissible to start and
4766 * end "internal" subtransactions while in parallel mode, so long as no
4767 * new XIDs or command IDs are assigned.
4768 */
4769
4771 elog(ERROR, "ReleaseCurrentSubTransaction: unexpected state %s",
4776 s = CurrentTransactionState; /* changed by pop */
4778}
MemoryContext CurTransactionContext
Definition: mcxt.c:155
static void CommitSubTransaction(void)
Definition: xact.c:5096

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

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

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

3709{
3710 CheckTransactionBlock(isTopLevel, true, stmtType);
3711}
static void CheckTransactionBlock(bool isTopLevel, bool throwError, const char *stmtType)
Definition: xact.c:3717

References CheckTransactionBlock().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

◆ RestoreTransactionCharacteristics()

◆ RollbackAndReleaseCurrentSubTransaction()

void RollbackAndReleaseCurrentSubTransaction ( void  )

Definition at line 4788 of file xact.c.

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

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

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

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

5529{
5531 Size nxids = 0;
5532 Size i = 0;
5533 TransactionId *workspace;
5535
5536 result = (SerializedTransactionState *) start_address;
5537
5538 result->xactIsoLevel = XactIsoLevel;
5541 result->currentFullTransactionId =
5544
5545 /*
5546 * If we're running in a parallel worker and launching a parallel worker
5547 * of our own, we can just pass along the information that was passed to
5548 * us.
5549 */
5550 if (nParallelCurrentXids > 0)
5551 {
5553 memcpy(&result->parallelCurrentXids[0], ParallelCurrentXids,
5555 return;
5556 }
5557
5558 /*
5559 * OK, we need to generate a sorted list of XIDs that our workers should
5560 * view as current. First, figure out how many there are.
5561 */
5562 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5563 {
5565 nxids = add_size(nxids, 1);
5566 nxids = add_size(nxids, s->nChildXids);
5567 }
5569 <= maxsize);
5570
5571 /* Copy them to our scratch space. */
5572 workspace = palloc(nxids * sizeof(TransactionId));
5573 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5574 {
5576 workspace[i++] = XidFromFullTransactionId(s->fullTransactionId);
5577 if (s->nChildXids > 0)
5578 memcpy(&workspace[i], s->childXids,
5579 s->nChildXids * sizeof(TransactionId));
5580 i += s->nChildXids;
5581 }
5582 Assert(i == nxids);
5583
5584 /* Sort them. */
5585 qsort(workspace, nxids, sizeof(TransactionId), xidComparator);
5586
5587 /* Copy data into output area. */
5588 result->nParallelCurrentXids = nxids;
5589 memcpy(&result->parallelCurrentXids[0], workspace,
5590 nxids * sizeof(TransactionId));
5591}
int i
Definition: isn.c:72
void * palloc(Size size)
Definition: mcxt.c:1317
#define qsort(a, b, c, d)
Definition: port.h:474
FullTransactionId currentFullTransactionId
Definition: xact.c:231
FullTransactionId topFullTransactionId
Definition: xact.c:230
CommandId currentCommandId
Definition: xact.c:232
TransactionId parallelCurrentXids[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.c:234
TransactionId * childXids
Definition: xact.c:205
static int nParallelCurrentXids
Definition: xact.c:125
static TransactionId * ParallelCurrentXids
Definition: xact.c:126
int xidComparator(const void *arg1, const void *arg2)
Definition: xid.c:152

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

Referenced by InitializeParallelDSM().

◆ SetCurrentStatementStartTimestamp()

◆ SetParallelStartTimestamps()

void SetParallelStartTimestamps ( TimestampTz  xact_ts,
TimestampTz  stmt_ts 
)

Definition at line 858 of file xact.c.

859{
861 xactStartTimestamp = xact_ts;
862 stmtStartTimestamp = stmt_ts;
863}

References Assert, IsParallelWorker, stmtStartTimestamp, and xactStartTimestamp.

Referenced by ParallelWorkerMain().

◆ StartParallelWorkerTransaction()

void StartParallelWorkerTransaction ( char *  tstatespace)

◆ StartTransactionCommand()

void StartTransactionCommand ( void  )

Definition at line 3051 of file xact.c.

3052{
3054
3055 switch (s->blockState)
3056 {
3057 /*
3058 * if we aren't in a transaction block, we just do our usual start
3059 * transaction.
3060 */
3061 case TBLOCK_DEFAULT:
3064 break;
3065
3066 /*
3067 * We are somewhere in a transaction block or subtransaction and
3068 * about to start a new command. For now we do nothing, but
3069 * someday we may do command-local resource initialization. (Note
3070 * that any needed CommandCounterIncrement was done by the
3071 * previous CommitTransactionCommand.)
3072 */
3073 case TBLOCK_INPROGRESS:
3076 break;
3077
3078 /*
3079 * Here we are in a failed transaction block (one of the commands
3080 * caused an abort) so we do nothing but remain in the abort
3081 * state. Eventually we will get a ROLLBACK command which will
3082 * get us out of this state. (It is up to other code to ensure
3083 * that no commands other than ROLLBACK will be processed in these
3084 * states.)
3085 */
3086 case TBLOCK_ABORT:
3087 case TBLOCK_SUBABORT:
3088 break;
3089
3090 /* These cases are invalid. */
3091 case TBLOCK_STARTED:
3092 case TBLOCK_BEGIN:
3094 case TBLOCK_SUBBEGIN:
3095 case TBLOCK_END:
3096 case TBLOCK_SUBRELEASE:
3097 case TBLOCK_SUBCOMMIT:
3098 case TBLOCK_ABORT_END:
3102 case TBLOCK_SUBRESTART:
3104 case TBLOCK_PREPARE:
3105 elog(ERROR, "StartTransactionCommand: unexpected state %s",
3107 break;
3108 }
3109
3110 /*
3111 * We must switch to CurTransactionContext before returning. This is
3112 * already done if we called StartTransaction, otherwise not.
3113 */
3116}

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

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

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

Referenced by fmgr_sql().

◆ TransactionBlockStatusCode()

char TransactionBlockStatusCode ( void  )

Definition at line 4995 of file xact.c.

4996{
4998
4999 switch (s->blockState)
5000 {
5001 case TBLOCK_DEFAULT:
5002 case TBLOCK_STARTED:
5003 return 'I'; /* idle --- not in transaction */
5004 case TBLOCK_BEGIN:
5005 case TBLOCK_SUBBEGIN:
5006 case TBLOCK_INPROGRESS:
5010 case TBLOCK_END:
5011 case TBLOCK_SUBRELEASE:
5012 case TBLOCK_SUBCOMMIT:
5013 case TBLOCK_PREPARE:
5014 return 'T'; /* in transaction */
5015 case TBLOCK_ABORT:
5016 case TBLOCK_SUBABORT:
5017 case TBLOCK_ABORT_END:
5021 case TBLOCK_SUBRESTART:
5023 return 'E'; /* in failed transaction */
5024 }
5025
5026 /* should never get here */
5027 elog(FATAL, "invalid transaction block state: %s",
5029 return 0; /* keep compiler quiet */
5030}

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

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

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

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

◆ UnregisterSubXactCallback()

void UnregisterSubXactCallback ( SubXactCallback  callback,
void *  arg 
)

Definition at line 3869 of file xact.c.

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

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

◆ UnregisterXactCallback()

void UnregisterXactCallback ( XactCallback  callback,
void *  arg 
)

Definition at line 3809 of file xact.c.

3810{
3811 XactCallbackItem *item;
3812 XactCallbackItem *prev;
3813
3814 prev = NULL;
3815 for (item = Xact_callbacks; item; prev = item, item = item->next)
3816 {
3817 if (item->callback == callback && item->arg == arg)
3818 {
3819 if (prev)
3820 prev->next = item->next;
3821 else
3822 Xact_callbacks = item->next;
3823 pfree(item);
3824 break;
3825 }
3826 }
3827}

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

◆ UserAbortTransactionBlock()

void UserAbortTransactionBlock ( bool  chain)

Definition at line 4196 of file xact.c.

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

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

3703{
3704 CheckTransactionBlock(isTopLevel, false, stmtType);
3705}

References CheckTransactionBlock().

Referenced by ExecSetVariableStmt(), and standard_ProcessUtility().

◆ xact_desc()

void xact_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 439 of file xactdesc.c.

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

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

◆ xact_identify()

const char * xact_identify ( uint8  info)

Definition at line 487 of file xactdesc.c.

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

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

◆ xact_redo()

void xact_redo ( XLogReaderState record)

Definition at line 6351 of file xact.c.

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

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

◆ xactGetCommittedChildren()

int xactGetCommittedChildren ( TransactionId **  ptr)

Definition at line 5778 of file xact.c.

5779{
5781
5782 if (s->nChildXids == 0)
5783 *ptr = NULL;
5784 else
5785 *ptr = s->childXids;
5786
5787 return s->nChildXids;
5788}

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

5980{
5981 xl_xact_abort xlrec;
5982 xl_xact_xinfo xl_xinfo;
5983 xl_xact_subxacts xl_subxacts;
5984 xl_xact_relfilelocators xl_relfilelocators;
5985 xl_xact_stats_items xl_dropped_stats;
5986 xl_xact_twophase xl_twophase;
5987 xl_xact_dbinfo xl_dbinfo;
5988 xl_xact_origin xl_origin;
5989
5990 uint8 info;
5991
5993
5994 xl_xinfo.xinfo = 0;
5995
5996 /* decide between a plain and 2pc abort */
5997 if (!TransactionIdIsValid(twophase_xid))
5998 info = XLOG_XACT_ABORT;
5999 else
6001
6002
6003 /* First figure out and collect all the information needed */
6004
6005 xlrec.xact_time = abort_time;
6006
6008 xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
6009
6010 if (nsubxacts > 0)
6011 {
6012 xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
6013 xl_subxacts.nsubxacts = nsubxacts;
6014 }
6015
6016 if (nrels > 0)
6017 {
6019 xl_relfilelocators.nrels = nrels;
6020 info |= XLR_SPECIAL_REL_UPDATE;
6021 }
6022
6023 if (ndroppedstats > 0)
6024 {
6026 xl_dropped_stats.nitems = ndroppedstats;
6027 }
6028
6029 if (TransactionIdIsValid(twophase_xid))
6030 {
6031 xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
6032 xl_twophase.xid = twophase_xid;
6033 Assert(twophase_gid != NULL);
6034
6036 xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
6037 }
6038
6039 if (TransactionIdIsValid(twophase_xid) && XLogLogicalInfoActive())
6040 {
6041 xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
6042 xl_dbinfo.dbId = MyDatabaseId;
6043 xl_dbinfo.tsId = MyDatabaseTableSpace;
6044 }
6045
6046 /*
6047 * Dump transaction origin information. We need this during recovery to
6048 * update the replication origin progress.
6049 */
6051 {
6052 xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
6053
6056 }
6057
6058 if (xl_xinfo.xinfo != 0)
6059 info |= XLOG_XACT_HAS_INFO;
6060
6061 /* Then include all the collected data into the abort record. */
6062
6064
6065 XLogRegisterData((char *) (&xlrec), MinSizeOfXactAbort);
6066
6067 if (xl_xinfo.xinfo != 0)
6068 XLogRegisterData((char *) (&xl_xinfo), sizeof(xl_xinfo));
6069
6070 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
6071 XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
6072
6073 if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
6074 {
6075 XLogRegisterData((char *) (&xl_subxacts),
6077 XLogRegisterData((char *) subxacts,
6078 nsubxacts * sizeof(TransactionId));
6079 }
6080
6082 {
6083 XLogRegisterData((char *) (&xl_relfilelocators),
6085 XLogRegisterData((char *) rels,
6086 nrels * sizeof(RelFileLocator));
6087 }
6088
6089 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
6090 {
6091 XLogRegisterData((char *) (&xl_dropped_stats),
6093 XLogRegisterData((char *) droppedstats,
6094 ndroppedstats * sizeof(xl_xact_stats_item));
6095 }
6096
6097 if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
6098 {
6099 XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
6100 if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
6101 XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
6102 }
6103
6104 if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
6105 XLogRegisterData((char *) (&xl_origin), sizeof(xl_xact_origin));
6106
6107 /* Include the replication origin */
6109
6110 return XLogInsert(RM_XACT_ID, info);
6111}
Oid MyDatabaseTableSpace
Definition: globals.c:95
volatile uint32 CritSectionCount
Definition: globals.c:44
Oid MyDatabaseId
Definition: globals.c:93
TimestampTz replorigin_session_origin_timestamp
Definition: origin.c:161
RepOriginId replorigin_session_origin
Definition: origin.c:159
XLogRecPtr replorigin_session_origin_lsn
Definition: origin.c:160
#define InvalidRepOriginId
Definition: origin.h:33
#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK
Definition: xact.h:108
#define XACT_XINFO_HAS_AE_LOCKS
Definition: xact.h:194
#define XLOG_INCLUDE_ORIGIN
Definition: xlog.h:154
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:474
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:456
void XLogRegisterData(const char *data, uint32 len)
Definition: xloginsert.c:364
void XLogBeginInsert(void)
Definition: xloginsert.c:149
#define XLR_SPECIAL_REL_UPDATE
Definition: xlogrecord.h:82

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

Referenced by RecordTransactionAbort(), and RecordTransactionAbortPrepared().

◆ XactLogCommitRecord()

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

Definition at line 5802 of file xact.c.

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

Referenced by RecordTransactionCommit(), and RecordTransactionCommitPrepared().

Variable Documentation

◆ bsysscan

◆ CheckXidAlive

◆ DefaultXactDeferrable

PGDLLIMPORT bool DefaultXactDeferrable
extern

Definition at line 83 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactIsoLevel

PGDLLIMPORT int DefaultXactIsoLevel
extern

Definition at line 77 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactReadOnly

PGDLLIMPORT bool DefaultXactReadOnly
extern

Definition at line 80 of file xact.c.

Referenced by StartTransaction().

◆ MyXactFlags

◆ synchronous_commit

PGDLLIMPORT int synchronous_commit
extern

Definition at line 86 of file xact.c.

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

◆ xact_is_sampled

PGDLLIMPORT bool xact_is_sampled
extern

Definition at line 295 of file xact.c.

Referenced by check_log_duration(), and StartTransaction().

◆ XactDeferrable

◆ XactIsoLevel

◆ XactReadOnly