PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 3451 of file xact.c.

3452{
3453 /*
3454 * Repeatedly call AbortCurrentTransactionInternal() until all the work is
3455 * done.
3456 */
3458 {
3459 }
3460}
static bool AbortCurrentTransactionInternal(void)
Definition: xact.c:3469

References AbortCurrentTransactionInternal().

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

◆ AbortOutOfAnyTransaction()

void AbortOutOfAnyTransaction ( void  )

Definition at line 4862 of file xact.c.

4863{
4865
4866 /* Ensure we're not running in a doomed memory context */
4868
4869 /*
4870 * Get out of any transaction or nested transaction
4871 */
4872 do
4873 {
4874 switch (s->blockState)
4875 {
4876 case TBLOCK_DEFAULT:
4877 if (s->state == TRANS_DEFAULT)
4878 {
4879 /* Not in a transaction, do nothing */
4880 }
4881 else
4882 {
4883 /*
4884 * We can get here after an error during transaction start
4885 * (state will be TRANS_START). Need to clean up the
4886 * incompletely started transaction. First, adjust the
4887 * low-level state to suppress warning message from
4888 * AbortTransaction.
4889 */
4890 if (s->state == TRANS_START)
4894 }
4895 break;
4896 case TBLOCK_STARTED:
4897 case TBLOCK_BEGIN:
4898 case TBLOCK_INPROGRESS:
4901 case TBLOCK_END:
4903 case TBLOCK_PREPARE:
4904 /* In a transaction, so clean up */
4908 break;
4909 case TBLOCK_ABORT:
4910 case TBLOCK_ABORT_END:
4911
4912 /*
4913 * AbortTransaction is already done, still need Cleanup.
4914 * However, if we failed partway through running ROLLBACK,
4915 * there will be an active portal running that command, which
4916 * we need to shut down before doing CleanupTransaction.
4917 */
4921 break;
4922
4923 /*
4924 * In a subtransaction, so clean it up and abort parent too
4925 */
4926 case TBLOCK_SUBBEGIN:
4928 case TBLOCK_SUBRELEASE:
4929 case TBLOCK_SUBCOMMIT:
4931 case TBLOCK_SUBRESTART:
4934 s = CurrentTransactionState; /* changed by pop */
4935 break;
4936
4937 case TBLOCK_SUBABORT:
4940 /* As above, but AbortSubTransaction already done */
4941 if (s->curTransactionOwner)
4942 {
4943 /* As in TBLOCK_ABORT, might have a live portal to zap */
4948 }
4950 s = CurrentTransactionState; /* changed by pop */
4951 break;
4952 }
4953 } while (s->blockState != TBLOCK_DEFAULT);
4954
4955 /* Should be out of all subxacts now */
4956 Assert(s->parent == NULL);
4957
4958 /*
4959 * Revert to TopMemoryContext, to ensure we exit in a well-defined state
4960 * whether there were any transactions to close or not. (Callers that
4961 * don't intend to exit soon should switch to some other context to avoid
4962 * long-term memory leaks.)
4963 */
4965}
Assert(PointerIsAligned(start, uint64))
MemoryContext TopMemoryContext
Definition: mcxt.c:165
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
void AtAbort_Portals(void)
Definition: portalmem.c:783
void AtSubAbort_Portals(SubTransactionId mySubid, SubTransactionId parentSubid, ResourceOwner myXactOwner, ResourceOwner parentXactOwner)
Definition: portalmem.c:981
TransState state
Definition: xact.c:199
SubTransactionId subTransactionId
Definition: xact.c:196
struct TransactionStateData * parent
Definition: xact.c:218
TBlockState blockState
Definition: xact.c:200
ResourceOwner curTransactionOwner
Definition: xact.c:204
static void CleanupSubTransaction(void)
Definition: xact.c:5383
static void CleanupTransaction(void)
Definition: xact.c:3009
@ TRANS_INPROGRESS
Definition: xact.c:145
@ TRANS_START
Definition: xact.c:144
@ TRANS_DEFAULT
Definition: xact.c:143
static void AbortSubTransaction(void)
Definition: xact.c:5219
static void AtAbort_Memory(void)
Definition: xact.c:1884
@ TBLOCK_DEFAULT
Definition: xact.c:160
@ TBLOCK_SUBABORT_END
Definition: xact.c:180
@ TBLOCK_STARTED
Definition: xact.c:161
@ TBLOCK_SUBCOMMIT
Definition: xact.c:178
@ TBLOCK_IMPLICIT_INPROGRESS
Definition: xact.c:166
@ TBLOCK_ABORT_END
Definition: xact.c:170
@ TBLOCK_PREPARE
Definition: xact.c:172
@ TBLOCK_ABORT_PENDING
Definition: xact.c:171
@ TBLOCK_ABORT
Definition: xact.c:169
@ TBLOCK_SUBRELEASE
Definition: xact.c:177
@ TBLOCK_SUBBEGIN
Definition: xact.c:175
@ TBLOCK_SUBABORT
Definition: xact.c:179
@ TBLOCK_SUBRESTART
Definition: xact.c:182
@ TBLOCK_INPROGRESS
Definition: xact.c:165
@ TBLOCK_END
Definition: xact.c:168
@ TBLOCK_PARALLEL_INPROGRESS
Definition: xact.c:167
@ TBLOCK_SUBABORT_RESTART
Definition: xact.c:183
@ TBLOCK_SUBABORT_PENDING
Definition: xact.c:181
@ TBLOCK_BEGIN
Definition: xact.c:164
@ TBLOCK_SUBINPROGRESS
Definition: xact.c:176
static void AbortTransaction(void)
Definition: xact.c:2809
static TransactionState CurrentTransactionState
Definition: xact.c:260

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

4327{
4329
4330 /*
4331 * If we are in STARTED state (that is, no transaction block is open),
4332 * switch to IMPLICIT_INPROGRESS state, creating an implicit transaction
4333 * block.
4334 *
4335 * For caller convenience, we consider all other transaction states as
4336 * legal here; otherwise the caller would need its own state check, which
4337 * seems rather pointless.
4338 */
4339 if (s->blockState == TBLOCK_STARTED)
4341}

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

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

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

3925{
3927
3928 switch (s->blockState)
3929 {
3930 /*
3931 * We are not inside a transaction block, so allow one to begin.
3932 */
3933 case TBLOCK_STARTED:
3935 break;
3936
3937 /*
3938 * BEGIN converts an implicit transaction block to a regular one.
3939 * (Note that we allow this even if we've already done some
3940 * commands, which is a bit odd but matches historical practice.)
3941 */
3944 break;
3945
3946 /*
3947 * Already a transaction block in progress.
3948 */
3949 case TBLOCK_INPROGRESS:
3952 case TBLOCK_ABORT:
3953 case TBLOCK_SUBABORT:
3955 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3956 errmsg("there is already a transaction in progress")));
3957 break;
3958
3959 /* These cases are invalid. */
3960 case TBLOCK_DEFAULT:
3961 case TBLOCK_BEGIN:
3962 case TBLOCK_SUBBEGIN:
3963 case TBLOCK_END:
3964 case TBLOCK_SUBRELEASE:
3965 case TBLOCK_SUBCOMMIT:
3966 case TBLOCK_ABORT_END:
3970 case TBLOCK_SUBRESTART:
3972 case TBLOCK_PREPARE:
3973 elog(FATAL, "BeginTransactionBlock: unexpected state %s",
3975 break;
3976 }
3977}
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#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 1100 of file xact.c.

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

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(), ATExecAlterConstrInheritability(), ATExecCmd(), ATExecDropColumn(), ATExecDropExpression(), ATExecDropIdentity(), ATExecSetAccessMethodNoStorage(), ATExecSetCompression(), ATExecSetExpression(), ATExecSetNotNull(), ATExecSetTableSpace(), ATExecSetTableSpaceNoStorage(), ATParseTransformCmd(), ATRewriteTables(), AttachPartitionEnsureIndexes(), AttachPartitionForeignKey(), 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(), DropForeignKeyConstraintTriggers(), 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(), RemoveInheritedConstraint(), 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(), upsert_pg_statistic(), vacuum(), and validatePartitionedIndex().

◆ CommitTransactionCommand()

void CommitTransactionCommand ( void  )

Definition at line 3157 of file xact.c.

3158{
3159 /*
3160 * Repeatedly call CommitTransactionCommandInternal() until all the work
3161 * is done.
3162 */
3164 {
3165 }
3166}
static bool CommitTransactionCommandInternal(void)
Definition: xact.c:3175

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

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

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

4352{
4354
4355 /*
4356 * If we are in IMPLICIT_INPROGRESS state, switch back to STARTED state,
4357 * allowing CommitTransactionCommand to commit whatever happened during
4358 * the implicit transaction block as though it were a single statement.
4359 *
4360 * For caller convenience, we consider all other transaction states as
4361 * legal here; otherwise the caller would need its own state check, which
4362 * seems rather pointless.
4363 */
4366}

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

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

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

5513{
5515 Size nxids = 0;
5517
5518 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5519 {
5521 nxids = add_size(nxids, 1);
5522 nxids = add_size(nxids, s->nChildXids);
5523 }
5524
5525 return add_size(size, mul_size(sizeof(TransactionId), nxids));
5526}
uint32 TransactionId
Definition: c.h:623
size_t Size
Definition: c.h:576
Size add_size(Size s1, Size s2)
Definition: shmem.c:493
Size mul_size(Size s1, Size s2)
Definition: shmem.c:510
FullTransactionId fullTransactionId
Definition: xact.c:195
#define FullTransactionIdIsValid(x)
Definition: transam.h:55
#define SerializedTransactionStateHeaderSize
Definition: xact.c:239

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

Referenced by InitializeParallelDSM().

◆ ExitParallelMode()

◆ ForceSyncCommit()

void ForceSyncCommit ( void  )

Definition at line 1152 of file xact.c.

1153{
1154 forceSyncCommit = true;
1155}
static bool forceSyncCommit
Definition: xact.c:293

References forceSyncCommit.

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

◆ GetCurrentCommandId()

CommandId GetCurrentCommandId ( bool  used)

Definition at line 829 of file xact.c.

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

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

513{
515
518 return s->fullTransactionId;
519}
static void AssignTransactionId(TransactionState s)
Definition: xact.c:635

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

◆ GetCurrentFullTransactionIdIfAny()

FullTransactionId GetCurrentFullTransactionIdIfAny ( void  )

Definition at line 530 of file xact.c.

References CurrentTransactionState, and TransactionStateData::fullTransactionId.

◆ GetCurrentStatementStartTimestamp()

TimestampTz GetCurrentStatementStartTimestamp ( void  )

Definition at line 879 of file xact.c.

880{
881 return stmtStartTimestamp;
882}
static TimestampTz stmtStartTimestamp
Definition: xact.c:281

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

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

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

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

◆ GetStableLatestTransactionId()

TransactionId GetStableLatestTransactionId ( void  )

Definition at line 607 of file xact.c.

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

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

Referenced by xid_age().

◆ GetTopFullTransactionId()

FullTransactionId GetTopFullTransactionId ( void  )

Definition at line 483 of file xact.c.

484{
488}
static TransactionStateData TopTransactionStateData
Definition: xact.c:247
static FullTransactionId XactTopFullTransactionId
Definition: xact.c:125

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

Referenced by pg_current_xact_id().

◆ GetTopFullTransactionIdIfAny()

FullTransactionId GetTopFullTransactionIdIfAny ( void  )

Definition at line 499 of file xact.c.

500{
502}

References XactTopFullTransactionId.

Referenced by pg_current_xact_id_if_assigned().

◆ GetTopTransactionId()

◆ GetTopTransactionIdIfAny()

◆ IsAbortedTransactionBlockState()

◆ IsInParallelMode()

◆ IsInTransactionBlock()

bool IsInTransactionBlock ( bool  isTopLevel)

Definition at line 3769 of file xact.c.

3770{
3771 /*
3772 * Return true on same conditions that would make
3773 * PreventInTransactionBlock error out
3774 */
3775 if (IsTransactionBlock())
3776 return true;
3777
3778 if (IsSubTransaction())
3779 return true;
3780
3781 if (!isTopLevel)
3782 return true;
3783
3786 return true;
3787
3788 return false;
3789}
bool IsSubTransaction(void)
Definition: xact.c:5044
bool IsTransactionBlock(void)
Definition: xact.c:4971

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

Referenced by vacuum().

◆ IsSubTransaction()

◆ IsSubxactTopXidLogPending()

bool IsSubxactTopXidLogPending ( void  )

Definition at line 559 of file xact.c.

560{
561 /* check whether it is already logged */
563 return false;
564
565 /* wal_level has to be logical */
567 return false;
568
569 /* we need to be in a transaction state */
570 if (!IsTransactionState())
571 return false;
572
573 /* it has to be a subtransaction */
574 if (!IsSubTransaction())
575 return false;
576
577 /* the subtransaction has to have a XID assigned */
579 return false;
580
581 return true;
582}
bool IsTransactionState(void)
Definition: xact.c:387
TransactionId GetCurrentTransactionIdIfAny(void)
Definition: xact.c:471
#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 387 of file xact.c.

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

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(), finish_sync_worker(), InitializeClientEncoding(), IsSubxactTopXidLogPending(), LogicalRepApplyLoop(), LogLogicalMessage(), maybe_reread_subscription(), pa_send_data(), pa_start_subtrans(), 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 591 of file xact.c.

592{
594
596}
bool IsSubxactTopXidLogPending(void)
Definition: xact.c:559

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:782
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 3992 of file xact.c.

3993{
3995 bool result;
3996
3997 /* Set up to commit the current transaction */
3998 result = EndTransactionBlock(false);
3999
4000 /* If successful, change outer tblock state to PREPARE */
4001 if (result)
4002 {
4004
4005 while (s->parent != NULL)
4006 s = s->parent;
4007
4008 if (s->blockState == TBLOCK_END)
4009 {
4010 /* Save GID where PrepareTransaction can find it again */
4012
4014 }
4015 else
4016 {
4017 /*
4018 * ignore case where we are not in a transaction;
4019 * EndTransactionBlock already issued a warning.
4020 */
4023 /* Don't send back a PREPARE result tag... */
4024 result = false;
4025 }
4026 }
4027
4028 return result;
4029}
static char * prepareGID
Definition: xact.c:288
bool EndTransactionBlock(bool chain)
Definition: xact.c:4044

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

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

3865{
3866 SubXactCallbackItem *item;
3867
3868 item = (SubXactCallbackItem *)
3870 item->callback = callback;
3871 item->arg = arg;
3872 item->next = SubXact_callbacks;
3873 SubXact_callbacks = item;
3874}
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1256
void * arg
struct SubXactCallbackItem * next
Definition: xact.c:322
SubXactCallback callback
Definition: xact.c:323
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46
static SubXactCallbackItem * SubXact_callbacks
Definition: xact.c:327

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

3805{
3806 XactCallbackItem *item;
3807
3808 item = (XactCallbackItem *)
3810 item->callback = callback;
3811 item->arg = arg;
3812 item->next = Xact_callbacks;
3813 Xact_callbacks = item;
3814}
struct XactCallbackItem * next
Definition: xact.c:310
void * arg
Definition: xact.c:312
XactCallback callback
Definition: xact.c:311
static XactCallbackItem * Xact_callbacks
Definition: xact.c:315

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

4769{
4771
4772 /*
4773 * We do not check for parallel mode here. It's permissible to start and
4774 * end "internal" subtransactions while in parallel mode, so long as no
4775 * new XIDs or command IDs are assigned.
4776 */
4777
4779 elog(ERROR, "ReleaseCurrentSubTransaction: unexpected state %s",
4784 s = CurrentTransactionState; /* changed by pop */
4786}
MemoryContext CurTransactionContext
Definition: mcxt.c:171
static void CommitSubTransaction(void)
Definition: xact.c:5104

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

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

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

3717{
3718 CheckTransactionBlock(isTopLevel, true, stmtType);
3719}
static void CheckTransactionBlock(bool isTopLevel, bool throwError, const char *stmtType)
Definition: xact.c:3725

References CheckTransactionBlock().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

◆ RestoreTransactionCharacteristics()

◆ RollbackAndReleaseCurrentSubTransaction()

void RollbackAndReleaseCurrentSubTransaction ( void  )

Definition at line 4796 of file xact.c.

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

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

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

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

5541{
5543 Size nxids = 0;
5544 Size i = 0;
5545 TransactionId *workspace;
5547
5548 result = (SerializedTransactionState *) start_address;
5549
5550 result->xactIsoLevel = XactIsoLevel;
5553 result->currentFullTransactionId =
5556
5557 /*
5558 * If we're running in a parallel worker and launching a parallel worker
5559 * of our own, we can just pass along the information that was passed to
5560 * us.
5561 */
5562 if (nParallelCurrentXids > 0)
5563 {
5565 memcpy(&result->parallelCurrentXids[0], ParallelCurrentXids,
5567 return;
5568 }
5569
5570 /*
5571 * OK, we need to generate a sorted list of XIDs that our workers should
5572 * view as current. First, figure out how many there are.
5573 */
5574 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5575 {
5577 nxids = add_size(nxids, 1);
5578 nxids = add_size(nxids, s->nChildXids);
5579 }
5581 <= maxsize);
5582
5583 /* Copy them to our scratch space. */
5584 workspace = palloc(nxids * sizeof(TransactionId));
5585 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5586 {
5588 workspace[i++] = XidFromFullTransactionId(s->fullTransactionId);
5589 if (s->nChildXids > 0)
5590 memcpy(&workspace[i], s->childXids,
5591 s->nChildXids * sizeof(TransactionId));
5592 i += s->nChildXids;
5593 }
5594 Assert(i == nxids);
5595
5596 /* Sort them. */
5597 qsort(workspace, nxids, sizeof(TransactionId), xidComparator);
5598
5599 /* Copy data into output area. */
5600 result->nParallelCurrentXids = nxids;
5601 memcpy(&result->parallelCurrentXids[0], workspace,
5602 nxids * sizeof(TransactionId));
5603}
int i
Definition: isn.c:77
void * palloc(Size size)
Definition: mcxt.c:1940
#define qsort(a, b, c, d)
Definition: port.h:479
FullTransactionId currentFullTransactionId
Definition: xact.c:232
FullTransactionId topFullTransactionId
Definition: xact.c:231
CommandId currentCommandId
Definition: xact.c:233
TransactionId parallelCurrentXids[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.c:235
TransactionId * childXids
Definition: xact.c:206
static int nParallelCurrentXids
Definition: xact.c:126
static TransactionId * ParallelCurrentXids
Definition: xact.c:127
int xidComparator(const void *arg1, const void *arg2)
Definition: xid.c: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 859 of file xact.c.

860{
862 xactStartTimestamp = xact_ts;
863 stmtStartTimestamp = stmt_ts;
864}

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

Referenced by ParallelWorkerMain().

◆ StartParallelWorkerTransaction()

void StartParallelWorkerTransaction ( char *  tstatespace)

◆ StartTransactionCommand()

void StartTransactionCommand ( void  )

Definition at line 3059 of file xact.c.

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

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

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

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

◆ TransactionBlockStatusCode()

char TransactionBlockStatusCode ( void  )

Definition at line 5003 of file xact.c.

5004{
5006
5007 switch (s->blockState)
5008 {
5009 case TBLOCK_DEFAULT:
5010 case TBLOCK_STARTED:
5011 return 'I'; /* idle --- not in transaction */
5012 case TBLOCK_BEGIN:
5013 case TBLOCK_SUBBEGIN:
5014 case TBLOCK_INPROGRESS:
5018 case TBLOCK_END:
5019 case TBLOCK_SUBRELEASE:
5020 case TBLOCK_SUBCOMMIT:
5021 case TBLOCK_PREPARE:
5022 return 'T'; /* in transaction */
5023 case TBLOCK_ABORT:
5024 case TBLOCK_SUBABORT:
5025 case TBLOCK_ABORT_END:
5029 case TBLOCK_SUBRESTART:
5031 return 'E'; /* in failed transaction */
5032 }
5033
5034 /* should never get here */
5035 elog(FATAL, "invalid transaction block state: %s",
5037 return 0; /* keep compiler quiet */
5038}

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

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

3878{
3879 SubXactCallbackItem *item;
3880 SubXactCallbackItem *prev;
3881
3882 prev = NULL;
3883 for (item = SubXact_callbacks; item; prev = item, item = item->next)
3884 {
3885 if (item->callback == callback && item->arg == arg)
3886 {
3887 if (prev)
3888 prev->next = item->next;
3889 else
3890 SubXact_callbacks = item->next;
3891 pfree(item);
3892 break;
3893 }
3894 }
3895}
void pfree(void *pointer)
Definition: mcxt.c:2147

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

◆ UnregisterXactCallback()

void UnregisterXactCallback ( XactCallback  callback,
void *  arg 
)

Definition at line 3817 of file xact.c.

3818{
3819 XactCallbackItem *item;
3820 XactCallbackItem *prev;
3821
3822 prev = NULL;
3823 for (item = Xact_callbacks; item; prev = item, item = item->next)
3824 {
3825 if (item->callback == callback && item->arg == arg)
3826 {
3827 if (prev)
3828 prev->next = item->next;
3829 else
3830 Xact_callbacks = item->next;
3831 pfree(item);
3832 break;
3833 }
3834 }
3835}

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

◆ UserAbortTransactionBlock()

void UserAbortTransactionBlock ( bool  chain)

Definition at line 4204 of file xact.c.

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

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

3711{
3712 CheckTransactionBlock(isTopLevel, false, stmtType);
3713}

References CheckTransactionBlock().

Referenced by ExecSetVariableStmt(), and standard_ProcessUtility().

◆ xact_desc()

void xact_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 437 of file xactdesc.c.

438{
439 char *rec = XLogRecGetData(record);
440 uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
441
442 if (info == XLOG_XACT_COMMIT || info == XLOG_XACT_COMMIT_PREPARED)
443 {
444 xl_xact_commit *xlrec = (xl_xact_commit *) rec;
445
446 xact_desc_commit(buf, XLogRecGetInfo(record), xlrec,
447 XLogRecGetOrigin(record));
448 }
449 else if (info == XLOG_XACT_ABORT || info == XLOG_XACT_ABORT_PREPARED)
450 {
451 xl_xact_abort *xlrec = (xl_xact_abort *) rec;
452
453 xact_desc_abort(buf, XLogRecGetInfo(record), xlrec,
454 XLogRecGetOrigin(record));
455 }
456 else if (info == XLOG_XACT_PREPARE)
457 {
458 xl_xact_prepare *xlrec = (xl_xact_prepare *) rec;
459
460 xact_desc_prepare(buf, XLogRecGetInfo(record), xlrec,
461 XLogRecGetOrigin(record));
462 }
463 else if (info == XLOG_XACT_ASSIGNMENT)
464 {
465 xl_xact_assignment *xlrec = (xl_xact_assignment *) rec;
466
467 /*
468 * Note that we ignore the WAL record's xid, since we're more
469 * interested in the top-level xid that issued the record and which
470 * xids are being reported here.
471 */
472 appendStringInfo(buf, "xtop %u: ", xlrec->xtop);
474 }
475 else if (info == XLOG_XACT_INVALIDATIONS)
476 {
477 xl_xact_invals *xlrec = (xl_xact_invals *) rec;
478
480 InvalidOid, false);
481 }
482}
uint8_t uint8
Definition: c.h:500
static char * buf
Definition: pg_test_fsync.c:72
#define InvalidOid
Definition: postgres_ext.h:35
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:332
static void xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec, RepOriginId origin_id)
Definition: xactdesc.c:368
static void xact_desc_assignment(StringInfo buf, xl_xact_assignment *xlrec)
Definition: xactdesc.c:426
static void xact_desc_prepare(StringInfo buf, uint8 info, xl_xact_prepare *xlrec, RepOriginId origin_id)
Definition: xactdesc.c:395
#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 485 of file xactdesc.c.

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

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

6364{
6365 uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
6366
6367 /* Backup blocks are not used in xact records */
6369
6370 if (info == XLOG_XACT_COMMIT)
6371 {
6372 xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6373 xl_xact_parsed_commit parsed;
6374
6375 ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6376 xact_redo_commit(&parsed, XLogRecGetXid(record),
6377 record->EndRecPtr, XLogRecGetOrigin(record));
6378 }
6379 else if (info == XLOG_XACT_COMMIT_PREPARED)
6380 {
6381 xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6382 xl_xact_parsed_commit parsed;
6383
6384 ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6385 xact_redo_commit(&parsed, parsed.twophase_xid,
6386 record->EndRecPtr, XLogRecGetOrigin(record));
6387
6388 /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6389 LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6390 PrepareRedoRemove(parsed.twophase_xid, false);
6391 LWLockRelease(TwoPhaseStateLock);
6392 }
6393 else if (info == XLOG_XACT_ABORT)
6394 {
6395 xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6396 xl_xact_parsed_abort parsed;
6397
6398 ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6399 xact_redo_abort(&parsed, XLogRecGetXid(record),
6400 record->EndRecPtr, XLogRecGetOrigin(record));
6401 }
6402 else if (info == XLOG_XACT_ABORT_PREPARED)
6403 {
6404 xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6405 xl_xact_parsed_abort parsed;
6406
6407 ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6408 xact_redo_abort(&parsed, parsed.twophase_xid,
6409 record->EndRecPtr, XLogRecGetOrigin(record));
6410
6411 /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6412 LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6413 PrepareRedoRemove(parsed.twophase_xid, false);
6414 LWLockRelease(TwoPhaseStateLock);
6415 }
6416 else if (info == XLOG_XACT_PREPARE)
6417 {
6418 /*
6419 * Store xid and start/end pointers of the WAL record in TwoPhaseState
6420 * gxact entry.
6421 */
6422 LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6424 record->ReadRecPtr,
6425 record->EndRecPtr,
6426 XLogRecGetOrigin(record));
6427 LWLockRelease(TwoPhaseStateLock);
6428 }
6429 else if (info == XLOG_XACT_ASSIGNMENT)
6430 {
6432
6435 xlrec->nsubxacts, xlrec->xsub);
6436 }
6437 else if (info == XLOG_XACT_INVALIDATIONS)
6438 {
6439 /*
6440 * XXX we do ignore this for now, what matters are invalidations
6441 * written into the commit record.
6442 */
6443 }
6444 else
6445 elog(PANIC, "xact_redo: unknown op code %u", info);
6446}
#define PANIC
Definition: elog.h:42
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1182
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1902
@ 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:2571
void PrepareRedoAdd(char *buf, XLogRecPtr start_lsn, XLogRecPtr end_lsn, RepOriginId origin_id)
Definition: twophase.c:2469
static void xact_redo_commit(xl_xact_parsed_commit *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:6130
static void xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:6284
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 5790 of file xact.c.

5791{
5793
5794 if (s->nChildXids == 0)
5795 *ptr = NULL;
5796 else
5797 *ptr = s->childXids;
5798
5799 return s->nChildXids;
5800}

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

5992{
5993 xl_xact_abort xlrec;
5994 xl_xact_xinfo xl_xinfo;
5995 xl_xact_subxacts xl_subxacts;
5996 xl_xact_relfilelocators xl_relfilelocators;
5997 xl_xact_stats_items xl_dropped_stats;
5998 xl_xact_twophase xl_twophase;
5999 xl_xact_dbinfo xl_dbinfo;
6000 xl_xact_origin xl_origin;
6001
6002 uint8 info;
6003
6005
6006 xl_xinfo.xinfo = 0;
6007
6008 /* decide between a plain and 2pc abort */
6009 if (!TransactionIdIsValid(twophase_xid))
6010 info = XLOG_XACT_ABORT;
6011 else
6013
6014
6015 /* First figure out and collect all the information needed */
6016
6017 xlrec.xact_time = abort_time;
6018
6020 xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
6021
6022 if (nsubxacts > 0)
6023 {
6024 xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
6025 xl_subxacts.nsubxacts = nsubxacts;
6026 }
6027
6028 if (nrels > 0)
6029 {
6031 xl_relfilelocators.nrels = nrels;
6032 info |= XLR_SPECIAL_REL_UPDATE;
6033 }
6034
6035 if (ndroppedstats > 0)
6036 {
6038 xl_dropped_stats.nitems = ndroppedstats;
6039 }
6040
6041 if (TransactionIdIsValid(twophase_xid))
6042 {
6043 xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
6044 xl_twophase.xid = twophase_xid;
6045 Assert(twophase_gid != NULL);
6046
6048 xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
6049 }
6050
6051 if (TransactionIdIsValid(twophase_xid) && XLogLogicalInfoActive())
6052 {
6053 xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
6054 xl_dbinfo.dbId = MyDatabaseId;
6055 xl_dbinfo.tsId = MyDatabaseTableSpace;
6056 }
6057
6058 /*
6059 * Dump transaction origin information. We need this during recovery to
6060 * update the replication origin progress.
6061 */
6063 {
6064 xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
6065
6068 }
6069
6070 if (xl_xinfo.xinfo != 0)
6071 info |= XLOG_XACT_HAS_INFO;
6072
6073 /* Then include all the collected data into the abort record. */
6074
6076
6078
6079 if (xl_xinfo.xinfo != 0)
6080 XLogRegisterData(&xl_xinfo, sizeof(xl_xinfo));
6081
6082 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
6083 XLogRegisterData(&xl_dbinfo, sizeof(xl_dbinfo));
6084
6085 if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
6086 {
6087 XLogRegisterData(&xl_subxacts,
6089 XLogRegisterData(subxacts,
6090 nsubxacts * sizeof(TransactionId));
6091 }
6092
6094 {
6095 XLogRegisterData(&xl_relfilelocators,
6097 XLogRegisterData(rels,
6098 nrels * sizeof(RelFileLocator));
6099 }
6100
6101 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
6102 {
6103 XLogRegisterData(&xl_dropped_stats,
6105 XLogRegisterData(droppedstats,
6106 ndroppedstats * sizeof(xl_xact_stats_item));
6107 }
6108
6109 if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
6110 {
6111 XLogRegisterData(&xl_twophase, sizeof(xl_xact_twophase));
6112 if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
6113 XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
6114 }
6115
6116 if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
6117 XLogRegisterData(&xl_origin, sizeof(xl_xact_origin));
6118
6119 /* Include the replication origin */
6121
6122 return XLogInsert(RM_XACT_ID, info);
6123}
Oid MyDatabaseTableSpace
Definition: globals.c:97
volatile uint32 CritSectionCount
Definition: globals.c:46
Oid MyDatabaseId
Definition: globals.c:95
TimestampTz replorigin_session_origin_timestamp
Definition: origin.c:165
RepOriginId replorigin_session_origin
Definition: origin.c:163
XLogRecPtr replorigin_session_origin_lsn
Definition: origin.c:164
#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 XLogRegisterData(const void *data, uint32 len)
Definition: xloginsert.c:364
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:456
void XLogBeginInsert(void)
Definition: xloginsert.c:149
#define XLR_SPECIAL_REL_UPDATE
Definition: xlogrecord.h:82

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

5822{
5823 xl_xact_commit xlrec;
5824 xl_xact_xinfo xl_xinfo;
5825 xl_xact_dbinfo xl_dbinfo;
5826 xl_xact_subxacts xl_subxacts;
5827 xl_xact_relfilelocators xl_relfilelocators;
5828 xl_xact_stats_items xl_dropped_stats;
5829 xl_xact_invals xl_invals;
5830 xl_xact_twophase xl_twophase;
5831 xl_xact_origin xl_origin;
5832 uint8 info;
5833
5835
5836 xl_xinfo.xinfo = 0;
5837
5838 /* decide between a plain and 2pc commit */
5839 if (!TransactionIdIsValid(twophase_xid))
5840 info = XLOG_XACT_COMMIT;
5841 else
5843
5844 /* First figure out and collect all the information needed */
5845
5846 xlrec.xact_time = commit_time;
5847
5848 if (relcacheInval)
5850 if (forceSyncCommit)
5853 xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5854
5855 /*
5856 * Check if the caller would like to ask standbys for immediate feedback
5857 * once this commit is applied.
5858 */
5861
5862 /*
5863 * Relcache invalidations requires information about the current database
5864 * and so does logical decoding.
5865 */
5866 if (nmsgs > 0 || XLogLogicalInfoActive())
5867 {
5868 xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5869 xl_dbinfo.dbId = MyDatabaseId;
5870 xl_dbinfo.tsId = MyDatabaseTableSpace;
5871 }
5872
5873 if (nsubxacts > 0)
5874 {
5875 xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5876 xl_subxacts.nsubxacts = nsubxacts;
5877 }
5878
5879 if (nrels > 0)
5880 {
5882 xl_relfilelocators.nrels = nrels;
5883 info |= XLR_SPECIAL_REL_UPDATE;
5884 }
5885
5886 if (ndroppedstats > 0)
5887 {
5889 xl_dropped_stats.nitems = ndroppedstats;
5890 }
5891
5892 if (nmsgs > 0)
5893 {
5894 xl_xinfo.xinfo |= XACT_XINFO_HAS_INVALS;
5895 xl_invals.nmsgs = nmsgs;
5896 }
5897
5898 if (TransactionIdIsValid(twophase_xid))
5899 {
5900 xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5901 xl_twophase.xid = twophase_xid;
5902 Assert(twophase_gid != NULL);
5903
5905 xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
5906 }
5907
5908 /* dump transaction origin information */
5910 {
5911 xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
5912
5915 }
5916
5917 if (xl_xinfo.xinfo != 0)
5918 info |= XLOG_XACT_HAS_INFO;
5919
5920 /* Then include all the collected data into the commit record. */
5921
5923
5924 XLogRegisterData(&xlrec, sizeof(xl_xact_commit));
5925
5926 if (xl_xinfo.xinfo != 0)
5927 XLogRegisterData(&xl_xinfo.xinfo, sizeof(xl_xinfo.xinfo));
5928
5929 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5930 XLogRegisterData(&xl_dbinfo, sizeof(xl_dbinfo));
5931
5932 if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5933 {
5934 XLogRegisterData(&xl_subxacts,
5936 XLogRegisterData(subxacts,
5937 nsubxacts * sizeof(TransactionId));
5938 }
5939
5941 {
5942 XLogRegisterData(&xl_relfilelocators,
5944 XLogRegisterData(rels,
5945 nrels * sizeof(RelFileLocator));
5946 }
5947
5948 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
5949 {
5950 XLogRegisterData(&xl_dropped_stats,
5952 XLogRegisterData(droppedstats,
5953 ndroppedstats * sizeof(xl_xact_stats_item));
5954 }
5955
5956 if (xl_xinfo.xinfo & XACT_XINFO_HAS_INVALS)
5957 {
5959 XLogRegisterData(msgs,
5960 nmsgs * sizeof(SharedInvalidationMessage));
5961 }
5962
5963 if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5964 {
5965 XLogRegisterData(&xl_twophase, sizeof(xl_xact_twophase));
5966 if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
5967 XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
5968 }
5969
5970 if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5971 XLogRegisterData(&xl_origin, sizeof(xl_xact_origin));
5972
5973 /* we allow filtering by xacts */
5975
5976 return XLogInsert(RM_XACT_ID, info);
5977}
int synchronous_commit
Definition: xact.c:87
#define XACT_COMPLETION_UPDATE_RELCACHE_FILE
Definition: xact.h:207
#define XACT_COMPLETION_FORCE_SYNC_COMMIT
Definition: xact.h:208
#define XACT_COMPLETION_APPLY_FEEDBACK
Definition: xact.h:206

References Assert(), CritSectionCount, xl_xact_dbinfo::dbId, forceSyncCommit, InvalidRepOriginId, MinSizeOfXactInvals, MinSizeOfXactRelfileLocators, MinSizeOfXactStatsItems, MinSizeOfXactSubxacts, MyDatabaseId, MyDatabaseTableSpace, xl_xact_stats_items::nitems, xl_xact_invals::nmsgs, xl_xact_relfilelocators::nrels, xl_xact_subxacts::nsubxacts, xl_xact_origin::origin_lsn, xl_xact_origin::origin_timestamp, replorigin_session_origin, replorigin_session_origin_lsn, replorigin_session_origin_timestamp, synchronous_commit, SYNCHRONOUS_COMMIT_REMOTE_APPLY, TransactionIdIsValid, xl_xact_dbinfo::tsId, XACT_COMPLETION_APPLY_FEEDBACK, XACT_COMPLETION_FORCE_SYNC_COMMIT, XACT_COMPLETION_UPDATE_RELCACHE_FILE, XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK, xl_xact_commit::xact_time, XACT_XINFO_HAS_AE_LOCKS, XACT_XINFO_HAS_DBINFO, XACT_XINFO_HAS_DROPPED_STATS, XACT_XINFO_HAS_GID, XACT_XINFO_HAS_INVALS, XACT_XINFO_HAS_ORIGIN, XACT_XINFO_HAS_RELFILELOCATORS, XACT_XINFO_HAS_SUBXACTS, XACT_XINFO_HAS_TWOPHASE, xl_xact_twophase::xid, xl_xact_xinfo::xinfo, XLOG_INCLUDE_ORIGIN, XLOG_XACT_COMMIT, XLOG_XACT_COMMIT_PREPARED, XLOG_XACT_HAS_INFO, XLogBeginInsert(), XLogInsert(), XLogLogicalInfoActive, XLogRegisterData(), XLogSetRecordFlags(), and XLR_SPECIAL_REL_UPDATE.

Referenced by RecordTransactionCommit(), and RecordTransactionCommitPrepared().

Variable Documentation

◆ bsysscan

◆ CheckXidAlive

◆ DefaultXactDeferrable

PGDLLIMPORT bool DefaultXactDeferrable
extern

Definition at line 84 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactIsoLevel

PGDLLIMPORT int DefaultXactIsoLevel
extern

Definition at line 78 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactReadOnly

PGDLLIMPORT bool DefaultXactReadOnly
extern

Definition at line 81 of file xact.c.

Referenced by StartTransaction().

◆ MyXactFlags

◆ synchronous_commit

PGDLLIMPORT int synchronous_commit
extern

Definition at line 87 of file xact.c.

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

◆ xact_is_sampled

PGDLLIMPORT bool xact_is_sampled
extern

Definition at line 296 of file xact.c.

Referenced by check_log_duration(), and StartTransaction().

◆ XactDeferrable

◆ XactIsoLevel

◆ XactReadOnly