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

Go to the source code of this file.

Data Structures

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

Macros

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

Typedefs

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

Enumerations

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

Functions

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

Variables

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

Macro Definition Documentation

◆ GIDSIZE

#define GIDSIZE   200

Definition at line 31 of file xact.h.

◆ IsolationIsSerializable

#define IsolationIsSerializable ( )    (XactIsoLevel == XACT_SERIALIZABLE)

Definition at line 53 of file xact.h.

◆ IsolationUsesXactSnapshot

#define IsolationUsesXactSnapshot ( )    (XactIsoLevel >= XACT_REPEATABLE_READ)

Definition at line 52 of file xact.h.

◆ MinSizeOfXactAbort

#define MinSizeOfXactAbort   sizeof(xl_xact_abort)

Definition at line 351 of file xact.h.

◆ MinSizeOfXactAssignment

#define MinSizeOfXactAssignment   offsetof(xl_xact_assignment, xsub)

Definition at line 226 of file xact.h.

◆ MinSizeOfXactCommit

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

Definition at line 335 of file xact.h.

◆ MinSizeOfXactInvals

#define MinSizeOfXactInvals   offsetof(xl_xact_invals, msgs)

Definition at line 308 of file xact.h.

◆ MinSizeOfXactRelfileLocators

#define MinSizeOfXactRelfileLocators   offsetof(xl_xact_relfilelocators, xlocators)

Definition at line 274 of file xact.h.

◆ MinSizeOfXactStatsItems

#define MinSizeOfXactStatsItems   offsetof(xl_xact_stats_items, items)

Definition at line 301 of file xact.h.

◆ MinSizeOfXactSubxacts

#define MinSizeOfXactSubxacts   offsetof(xl_xact_subxacts, subxacts)

Definition at line 267 of file xact.h.

◆ SYNCHRONOUS_COMMIT_ON

#define SYNCHRONOUS_COMMIT_ON   SYNCHRONOUS_COMMIT_REMOTE_FLUSH

Definition at line 81 of file xact.h.

◆ XACT_COMPLETION_APPLY_FEEDBACK

#define XACT_COMPLETION_APPLY_FEEDBACK   (1U << 29)

Definition at line 207 of file xact.h.

◆ XACT_COMPLETION_FORCE_SYNC_COMMIT

#define XACT_COMPLETION_FORCE_SYNC_COMMIT   (1U << 31)

Definition at line 209 of file xact.h.

◆ XACT_COMPLETION_UPDATE_RELCACHE_FILE

#define XACT_COMPLETION_UPDATE_RELCACHE_FILE   (1U << 30)

Definition at line 208 of file xact.h.

◆ XACT_FLAGS_ACCESSEDTEMPNAMESPACE

#define XACT_FLAGS_ACCESSEDTEMPNAMESPACE   (1U << 0)

Definition at line 103 of file xact.h.

◆ XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK

#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK   (1U << 1)

Definition at line 109 of file xact.h.

◆ XACT_FLAGS_NEEDIMMEDIATECOMMIT

#define XACT_FLAGS_NEEDIMMEDIATECOMMIT   (1U << 2)

Definition at line 115 of file xact.h.

◆ XACT_FLAGS_PIPELINING

#define XACT_FLAGS_PIPELINING   (1U << 3)

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

◆ XACT_XINFO_HAS_DBINFO

#define XACT_XINFO_HAS_DBINFO   (1U << 0)

Definition at line 189 of file xact.h.

◆ XACT_XINFO_HAS_DROPPED_STATS

#define XACT_XINFO_HAS_DROPPED_STATS   (1U << 8)

Definition at line 197 of file xact.h.

◆ XACT_XINFO_HAS_GID

#define XACT_XINFO_HAS_GID   (1U << 7)

Definition at line 196 of file xact.h.

◆ XACT_XINFO_HAS_INVALS

#define XACT_XINFO_HAS_INVALS   (1U << 3)

Definition at line 192 of file xact.h.

◆ XACT_XINFO_HAS_ORIGIN

#define XACT_XINFO_HAS_ORIGIN   (1U << 5)

Definition at line 194 of file xact.h.

◆ XACT_XINFO_HAS_RELFILELOCATORS

#define XACT_XINFO_HAS_RELFILELOCATORS   (1U << 2)

Definition at line 191 of file xact.h.

◆ XACT_XINFO_HAS_SUBXACTS

#define XACT_XINFO_HAS_SUBXACTS   (1U << 1)

Definition at line 190 of file xact.h.

◆ XACT_XINFO_HAS_TWOPHASE

#define XACT_XINFO_HAS_TWOPHASE   (1U << 4)

Definition at line 193 of file xact.h.

◆ XactCompletionApplyFeedback

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

Definition at line 212 of file xact.h.

◆ XactCompletionForceSyncCommit

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

Definition at line 216 of file xact.h.

◆ XactCompletionRelcacheInitFileInval

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

Definition at line 214 of file xact.h.

◆ XLOG_XACT_ABORT

#define XLOG_XACT_ABORT   0x20

Definition at line 172 of file xact.h.

◆ XLOG_XACT_ABORT_PREPARED

#define XLOG_XACT_ABORT_PREPARED   0x40

Definition at line 174 of file xact.h.

◆ XLOG_XACT_ASSIGNMENT

#define XLOG_XACT_ASSIGNMENT   0x50

Definition at line 175 of file xact.h.

◆ XLOG_XACT_COMMIT

#define XLOG_XACT_COMMIT   0x00

Definition at line 170 of file xact.h.

◆ XLOG_XACT_COMMIT_PREPARED

#define XLOG_XACT_COMMIT_PREPARED   0x30

Definition at line 173 of file xact.h.

◆ XLOG_XACT_HAS_INFO

#define XLOG_XACT_HAS_INFO   0x80

Definition at line 183 of file xact.h.

◆ XLOG_XACT_INVALIDATIONS

#define XLOG_XACT_INVALIDATIONS   0x60

Definition at line 176 of file xact.h.

◆ XLOG_XACT_OPMASK

#define XLOG_XACT_OPMASK   0x70

Definition at line 180 of file xact.h.

◆ XLOG_XACT_PREPARE

#define XLOG_XACT_PREPARE   0x10

Definition at line 171 of file xact.h.

Typedef Documentation

◆ SavedTransactionCharacteristics

◆ SubXactCallback

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

Definition at line 149 of file xact.h.

◆ XactCallback

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

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

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

◆ SyncCommitLevel

Enumerator
SYNCHRONOUS_COMMIT_OFF 
SYNCHRONOUS_COMMIT_LOCAL_FLUSH 
SYNCHRONOUS_COMMIT_REMOTE_WRITE 
SYNCHRONOUS_COMMIT_REMOTE_FLUSH 
SYNCHRONOUS_COMMIT_REMOTE_APPLY 

Definition at line 69 of file xact.h.

70{
71 SYNCHRONOUS_COMMIT_OFF, /* asynchronous commit */
72 SYNCHRONOUS_COMMIT_LOCAL_FLUSH, /* wait for local flush only */
73 SYNCHRONOUS_COMMIT_REMOTE_WRITE, /* wait for local flush and remote
74 * write */
75 SYNCHRONOUS_COMMIT_REMOTE_FLUSH, /* wait for local and remote flush */
76 SYNCHRONOUS_COMMIT_REMOTE_APPLY, /* wait for local and remote flush and
77 * remote apply */
SyncCommitLevel
Definition: xact.h:70
@ SYNCHRONOUS_COMMIT_LOCAL_FLUSH
Definition: xact.h:72
@ SYNCHRONOUS_COMMIT_REMOTE_WRITE
Definition: xact.h:73
@ SYNCHRONOUS_COMMIT_REMOTE_APPLY
Definition: xact.h:76
@ SYNCHRONOUS_COMMIT_REMOTE_FLUSH
Definition: xact.h:75
@ SYNCHRONOUS_COMMIT_OFF
Definition: xact.h:71

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

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

Function Documentation

◆ AbortCurrentTransaction()

void AbortCurrentTransaction ( void  )

Definition at line 3472 of file xact.c.

3473{
3474 /*
3475 * Repeatedly call AbortCurrentTransactionInternal() until all the work is
3476 * done.
3477 */
3479 {
3480 }
3481}
static bool AbortCurrentTransactionInternal(void)
Definition: xact.c:3490

References AbortCurrentTransactionInternal().

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

◆ AbortOutOfAnyTransaction()

void AbortOutOfAnyTransaction ( void  )

Definition at line 4884 of file xact.c.

4885{
4887
4888 /* Ensure we're not running in a doomed memory context */
4890
4891 /*
4892 * Get out of any transaction or nested transaction
4893 */
4894 do
4895 {
4896 switch (s->blockState)
4897 {
4898 case TBLOCK_DEFAULT:
4899 if (s->state == TRANS_DEFAULT)
4900 {
4901 /* Not in a transaction, do nothing */
4902 }
4903 else
4904 {
4905 /*
4906 * We can get here after an error during transaction start
4907 * (state will be TRANS_START). Need to clean up the
4908 * incompletely started transaction. First, adjust the
4909 * low-level state to suppress warning message from
4910 * AbortTransaction.
4911 */
4912 if (s->state == TRANS_START)
4916 }
4917 break;
4918 case TBLOCK_STARTED:
4919 case TBLOCK_BEGIN:
4920 case TBLOCK_INPROGRESS:
4923 case TBLOCK_END:
4925 case TBLOCK_PREPARE:
4926 /* In a transaction, so clean up */
4930 break;
4931 case TBLOCK_ABORT:
4932 case TBLOCK_ABORT_END:
4933
4934 /*
4935 * AbortTransaction is already done, still need Cleanup.
4936 * However, if we failed partway through running ROLLBACK,
4937 * there will be an active portal running that command, which
4938 * we need to shut down before doing CleanupTransaction.
4939 */
4943 break;
4944
4945 /*
4946 * In a subtransaction, so clean it up and abort parent too
4947 */
4948 case TBLOCK_SUBBEGIN:
4950 case TBLOCK_SUBRELEASE:
4951 case TBLOCK_SUBCOMMIT:
4953 case TBLOCK_SUBRESTART:
4956 s = CurrentTransactionState; /* changed by pop */
4957 break;
4958
4959 case TBLOCK_SUBABORT:
4962 /* As above, but AbortSubTransaction already done */
4963 if (s->curTransactionOwner)
4964 {
4965 /* As in TBLOCK_ABORT, might have a live portal to zap */
4970 }
4972 s = CurrentTransactionState; /* changed by pop */
4973 break;
4974 }
4975 } while (s->blockState != TBLOCK_DEFAULT);
4976
4977 /* Should be out of all subxacts now */
4978 Assert(s->parent == NULL);
4979
4980 /*
4981 * Revert to TopMemoryContext, to ensure we exit in a well-defined state
4982 * whether there were any transactions to close or not. (Callers that
4983 * don't intend to exit soon should switch to some other context to avoid
4984 * long-term memory leaks.)
4985 */
4987}
Assert(PointerIsAligned(start, uint64))
MemoryContext TopMemoryContext
Definition: mcxt.c:166
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
void AtAbort_Portals(void)
Definition: portalmem.c:781
void AtSubAbort_Portals(SubTransactionId mySubid, SubTransactionId parentSubid, ResourceOwner myXactOwner, ResourceOwner parentXactOwner)
Definition: portalmem.c:980
TransState state
Definition: xact.c:200
SubTransactionId subTransactionId
Definition: xact.c:197
struct TransactionStateData * parent
Definition: xact.c:219
TBlockState blockState
Definition: xact.c:201
ResourceOwner curTransactionOwner
Definition: xact.c:205
static void CleanupSubTransaction(void)
Definition: xact.c:5405
static void CleanupTransaction(void)
Definition: xact.c:3030
@ TRANS_INPROGRESS
Definition: xact.c:146
@ TRANS_START
Definition: xact.c:145
@ TRANS_DEFAULT
Definition: xact.c:144
static void AbortSubTransaction(void)
Definition: xact.c:5241
static void AtAbort_Memory(void)
Definition: xact.c:1897
@ TBLOCK_DEFAULT
Definition: xact.c:161
@ TBLOCK_SUBABORT_END
Definition: xact.c:181
@ TBLOCK_STARTED
Definition: xact.c:162
@ TBLOCK_SUBCOMMIT
Definition: xact.c:179
@ TBLOCK_IMPLICIT_INPROGRESS
Definition: xact.c:167
@ TBLOCK_ABORT_END
Definition: xact.c:171
@ TBLOCK_PREPARE
Definition: xact.c:173
@ TBLOCK_ABORT_PENDING
Definition: xact.c:172
@ TBLOCK_ABORT
Definition: xact.c:170
@ TBLOCK_SUBRELEASE
Definition: xact.c:178
@ TBLOCK_SUBBEGIN
Definition: xact.c:176
@ TBLOCK_SUBABORT
Definition: xact.c:180
@ TBLOCK_SUBRESTART
Definition: xact.c:183
@ TBLOCK_INPROGRESS
Definition: xact.c:166
@ TBLOCK_END
Definition: xact.c:169
@ TBLOCK_PARALLEL_INPROGRESS
Definition: xact.c:168
@ TBLOCK_SUBABORT_RESTART
Definition: xact.c:184
@ TBLOCK_SUBABORT_PENDING
Definition: xact.c:182
@ TBLOCK_BEGIN
Definition: xact.c:165
@ TBLOCK_SUBINPROGRESS
Definition: xact.c:177
static void AbortTransaction(void)
Definition: xact.c:2824
static TransactionState CurrentTransactionState
Definition: xact.c:261

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(), start_sequence_sync(), and start_table_sync().

◆ BeginImplicitTransactionBlock()

void BeginImplicitTransactionBlock ( void  )

Definition at line 4348 of file xact.c.

4349{
4351
4352 /*
4353 * If we are in STARTED state (that is, no transaction block is open),
4354 * switch to IMPLICIT_INPROGRESS state, creating an implicit transaction
4355 * block.
4356 *
4357 * For caller convenience, we consider all other transaction states as
4358 * legal here; otherwise the caller would need its own state check, which
4359 * seems rather pointless.
4360 */
4361 if (s->blockState == TBLOCK_STARTED)
4363}

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

4717{
4719 bool save_ExitOnAnyError = ExitOnAnyError;
4720
4721 /*
4722 * Errors within this function are improbable, but if one does happen we
4723 * force a FATAL exit. Callers generally aren't prepared to handle losing
4724 * control, and moreover our transaction state is probably corrupted if we
4725 * fail partway through; so an ordinary ERROR longjmp isn't okay.
4726 */
4727 ExitOnAnyError = true;
4728
4729 /*
4730 * We do not check for parallel mode here. It's permissible to start and
4731 * end "internal" subtransactions while in parallel mode, so long as no
4732 * new XIDs or command IDs are assigned. Enforcement of that occurs in
4733 * AssignTransactionId() and CommandCounterIncrement().
4734 */
4735
4736 switch (s->blockState)
4737 {
4738 case TBLOCK_STARTED:
4739 case TBLOCK_INPROGRESS:
4742 case TBLOCK_END:
4743 case TBLOCK_PREPARE:
4745 /* Normal subtransaction start */
4747 s = CurrentTransactionState; /* changed by push */
4748
4749 /*
4750 * Savepoint names, like the TransactionState block itself, live
4751 * in TopTransactionContext.
4752 */
4753 if (name)
4755 break;
4756
4757 /* These cases are invalid. */
4758 case TBLOCK_DEFAULT:
4759 case TBLOCK_BEGIN:
4760 case TBLOCK_SUBBEGIN:
4761 case TBLOCK_SUBRELEASE:
4762 case TBLOCK_SUBCOMMIT:
4763 case TBLOCK_ABORT:
4764 case TBLOCK_SUBABORT:
4765 case TBLOCK_ABORT_END:
4769 case TBLOCK_SUBRESTART:
4771 elog(FATAL, "BeginInternalSubTransaction: unexpected state %s",
4773 break;
4774 }
4775
4778
4779 ExitOnAnyError = save_ExitOnAnyError;
4780}
#define FATAL
Definition: elog.h:41
#define elog(elevel,...)
Definition: elog.h:226
bool ExitOnAnyError
Definition: globals.c:123
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1768
MemoryContext TopTransactionContext
Definition: mcxt.c:171
const char * name
static void PushTransaction(void)
Definition: xact.c:5438
void StartTransactionCommand(void)
Definition: xact.c:3080
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5729
void CommitTransactionCommand(void)
Definition: xact.c:3178

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

3947{
3949
3950 switch (s->blockState)
3951 {
3952 /*
3953 * We are not inside a transaction block, so allow one to begin.
3954 */
3955 case TBLOCK_STARTED:
3957 break;
3958
3959 /*
3960 * BEGIN converts an implicit transaction block to a regular one.
3961 * (Note that we allow this even if we've already done some
3962 * commands, which is a bit odd but matches historical practice.)
3963 */
3966 break;
3967
3968 /*
3969 * Already a transaction block in progress.
3970 */
3971 case TBLOCK_INPROGRESS:
3974 case TBLOCK_ABORT:
3975 case TBLOCK_SUBABORT:
3977 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3978 errmsg("there is already a transaction in progress")));
3979 break;
3980
3981 /* These cases are invalid. */
3982 case TBLOCK_DEFAULT:
3983 case TBLOCK_BEGIN:
3984 case TBLOCK_SUBBEGIN:
3985 case TBLOCK_END:
3986 case TBLOCK_SUBRELEASE:
3987 case TBLOCK_SUBCOMMIT:
3988 case TBLOCK_ABORT_END:
3992 case TBLOCK_SUBRESTART:
3994 case TBLOCK_PREPARE:
3995 elog(FATAL, "BeginTransactionBlock: unexpected state %s",
3997 break;
3998 }
3999}
int errcode(int sqlerrcode)
Definition: elog.c:863
int errmsg(const char *fmt,...)
Definition: elog.c:1080
#define WARNING
Definition: elog.h:36
#define ereport(elevel,...)
Definition: elog.h:150

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

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

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(), ATExecMergePartitions(), ATExecSetAccessMethodNoStorage(), ATExecSetCompression(), ATExecSetExpression(), ATExecSetNotNull(), ATExecSetTableSpace(), ATExecSetTableSpaceNoStorage(), ATExecSplitPartition(), ATParseTransformCmd(), ATRewriteTables(), AttachPartitionEnsureIndexes(), AttachPartitionForeignKey(), btadjustmembers(), CommitSubTransaction(), CommitTransactionCommandInternal(), compute_return_type(), copy_table_data(), create_ctas_internal(), create_toast_table(), CreateFKCheckTrigger(), createForeignKeyActionTriggers(), CreateForeignTable(), createPartitionTable(), CreatePublication(), CreateRole(), CreateSchemaCommand(), createTableConstraints(), CreateTriggerFiringOn(), DefineCollation(), DefineDomain(), DefineIndex(), DefineRange(), 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(), ProcessSyncingTablesForApply(), 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 3178 of file xact.c.

3179{
3180 /*
3181 * Repeatedly call CommitTransactionCommandInternal() until all the work
3182 * is done.
3183 */
3185 {
3186 }
3187}
static bool CommitTransactionCommandInternal(void)
Definition: xact.c:3196

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(), copy_sequences(), DefineIndex(), DisableSubscriptionAndExit(), do_autovacuum(), EventTriggerOnLogin(), exec_replication_command(), finish_xact_command(), FinishSyncWorker(), get_database_list(), get_subscription_list(), HasSubscriptionTablesCached(), IdentifySystem(), index_drop(), initialize_worker_spi(), InitializeLogRepWorker(), InitPostgres(), LogicalRepSyncSequences(), LogicalRepSyncTableStart(), maybe_reread_subscription(), movedb(), pa_start_subtrans(), pa_stream_abort(), ParallelApplyWorkerMain(), ParallelWorkerMain(), ProcessCatchupInterrupt(), ProcessIncomingNotify(), ProcessSequencesForSync(), ProcessSyncingTablesForApply(), ProcessSyncingTablesForSync(), ReindexMultipleInternal(), ReindexRelationConcurrently(), RemoveTempRelationsCallback(), ReplSlotSyncWorkerMain(), run_apply_worker(), shell_check_detail(), stream_abort_internal(), stream_stop_internal(), update_retention_status(), vacuum(), vacuum_rel(), validate_remote_info(), and worker_spi_main().

◆ DefineSavepoint()

void DefineSavepoint ( const char *  name)

Definition at line 4395 of file xact.c.

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

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

4374{
4376
4377 /*
4378 * If we are in IMPLICIT_INPROGRESS state, switch back to STARTED state,
4379 * allowing CommitTransactionCommand to commit whatever happened during
4380 * the implicit transaction block as though it were a single statement.
4381 *
4382 * For caller convenience, we consider all other transaction states as
4383 * legal here; otherwise the caller would need its own state check, which
4384 * seems rather pointless.
4385 */
4388}

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

4067{
4069 bool result = false;
4070
4071 switch (s->blockState)
4072 {
4073 /*
4074 * We are in a transaction block, so tell CommitTransactionCommand
4075 * to COMMIT.
4076 */
4077 case TBLOCK_INPROGRESS:
4079 result = true;
4080 break;
4081
4082 /*
4083 * We are in an implicit transaction block. If AND CHAIN was
4084 * specified, error. Otherwise commit, but issue a warning
4085 * because there was no explicit BEGIN before this.
4086 */
4088 if (chain)
4089 ereport(ERROR,
4090 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4091 /* translator: %s represents an SQL statement name */
4092 errmsg("%s can only be used in transaction blocks",
4093 "COMMIT AND CHAIN")));
4094 else
4096 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4097 errmsg("there is no transaction in progress")));
4099 result = true;
4100 break;
4101
4102 /*
4103 * We are in a failed transaction block. Tell
4104 * CommitTransactionCommand it's time to exit the block.
4105 */
4106 case TBLOCK_ABORT:
4108 break;
4109
4110 /*
4111 * We are in a live subtransaction block. Set up to subcommit all
4112 * open subtransactions and then commit the main transaction.
4113 */
4115 while (s->parent != NULL)
4116 {
4119 else
4120 elog(FATAL, "EndTransactionBlock: unexpected state %s",
4122 s = s->parent;
4123 }
4124 if (s->blockState == TBLOCK_INPROGRESS)
4126 else
4127 elog(FATAL, "EndTransactionBlock: unexpected state %s",
4129 result = true;
4130 break;
4131
4132 /*
4133 * Here we are inside an aborted subtransaction. Treat the COMMIT
4134 * as ROLLBACK: set up to abort everything and exit the main
4135 * transaction.
4136 */
4137 case TBLOCK_SUBABORT:
4138 while (s->parent != NULL)
4139 {
4142 else if (s->blockState == TBLOCK_SUBABORT)
4144 else
4145 elog(FATAL, "EndTransactionBlock: unexpected state %s",
4147 s = s->parent;
4148 }
4149 if (s->blockState == TBLOCK_INPROGRESS)
4151 else if (s->blockState == TBLOCK_ABORT)
4153 else
4154 elog(FATAL, "EndTransactionBlock: unexpected state %s",
4156 break;
4157
4158 /*
4159 * The user issued COMMIT when not inside a transaction. For
4160 * COMMIT without CHAIN, issue a WARNING, staying in
4161 * TBLOCK_STARTED state. The upcoming call to
4162 * CommitTransactionCommand() will then close the transaction and
4163 * put us back into the default state. For COMMIT AND CHAIN,
4164 * error.
4165 */
4166 case TBLOCK_STARTED:
4167 if (chain)
4168 ereport(ERROR,
4169 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4170 /* translator: %s represents an SQL statement name */
4171 errmsg("%s can only be used in transaction blocks",
4172 "COMMIT AND CHAIN")));
4173 else
4175 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4176 errmsg("there is no transaction in progress")));
4177 result = true;
4178 break;
4179
4180 /*
4181 * The user issued a COMMIT that somehow ran inside a parallel
4182 * worker. We can't cope with that.
4183 */
4185 ereport(FATAL,
4186 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4187 errmsg("cannot commit during a parallel operation")));
4188 break;
4189
4190 /* These cases are invalid. */
4191 case TBLOCK_DEFAULT:
4192 case TBLOCK_BEGIN:
4193 case TBLOCK_SUBBEGIN:
4194 case TBLOCK_END:
4195 case TBLOCK_SUBRELEASE:
4196 case TBLOCK_SUBCOMMIT:
4197 case TBLOCK_ABORT_END:
4201 case TBLOCK_SUBRESTART:
4203 case TBLOCK_PREPARE:
4204 elog(FATAL, "EndTransactionBlock: unexpected state %s",
4206 break;
4207 }
4208
4210 s->blockState == TBLOCK_END ||
4213
4214 s->chain = chain;
4215
4216 return result;
4217}

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

5535{
5537 Size nxids = 0;
5539
5540 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5541 {
5543 nxids = add_size(nxids, 1);
5544 nxids = add_size(nxids, s->nChildXids);
5545 }
5546
5547 return add_size(size, mul_size(sizeof(TransactionId), nxids));
5548}
uint32 TransactionId
Definition: c.h:671
size_t Size
Definition: c.h:624
Size add_size(Size s1, Size s2)
Definition: shmem.c:495
Size mul_size(Size s1, Size s2)
Definition: shmem.c:510
FullTransactionId fullTransactionId
Definition: xact.c:196
#define FullTransactionIdIsValid(x)
Definition: transam.h:55
#define SerializedTransactionStateHeaderSize
Definition: xact.c:240

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

1154{
1155 forceSyncCommit = true;
1156}
static bool forceSyncCommit
Definition: xact.c:294

References forceSyncCommit.

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

◆ GetCurrentCommandId()

CommandId GetCurrentCommandId ( bool  used)

Definition at line 830 of file xact.c.

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

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(), MergePartitionsMoveRows(), 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(), SplitPartitionMoveRows(), standard_ExecutorStart(), toast_save_datum(), transientrel_startup(), and UpdateActiveSnapshotCommandId().

◆ GetCurrentFullTransactionId()

FullTransactionId GetCurrentFullTransactionId ( void  )

Definition at line 513 of file xact.c.

514{
516
519 return s->fullTransactionId;
520}
static void AssignTransactionId(TransactionState s)
Definition: xact.c:636

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

Referenced by PrepareTransaction().

◆ GetCurrentFullTransactionIdIfAny()

FullTransactionId GetCurrentFullTransactionIdIfAny ( void  )

Definition at line 531 of file xact.c.

References CurrentTransactionState, and TransactionStateData::fullTransactionId.

◆ GetCurrentStatementStartTimestamp()

TimestampTz GetCurrentStatementStartTimestamp ( void  )

Definition at line 880 of file xact.c.

881{
882 return stmtStartTimestamp;
883}
static TimestampTz stmtStartTimestamp
Definition: xact.c:282

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

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

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

609{
611 static TransactionId stablexid = InvalidTransactionId;
612
613 if (lxid != MyProc->vxid.lxid)
614 {
615 lxid = MyProc->vxid.lxid;
616 stablexid = GetTopTransactionIdIfAny();
617 if (!TransactionIdIsValid(stablexid))
618 stablexid = ReadNextTransactionId();
619 }
620
621 Assert(TransactionIdIsValid(stablexid));
622
623 return stablexid;
624}
uint32 LocalTransactionId
Definition: c.h:673
#define InvalidLocalTransactionId
Definition: lock.h:67
PGPROC * MyProc
Definition: proc.c:67
LocalTransactionId lxid
Definition: proc.h:217
struct PGPROC::@130 vxid
static TransactionId ReadNextTransactionId(void)
Definition: transam.h:377
#define InvalidTransactionId
Definition: transam.h:31
#define TransactionIdIsValid(xid)
Definition: transam.h:41
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:442

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

Referenced by xid_age().

◆ GetTopFullTransactionId()

FullTransactionId GetTopFullTransactionId ( void  )

Definition at line 484 of file xact.c.

485{
489}
static TransactionStateData TopTransactionStateData
Definition: xact.c:248
static FullTransactionId XactTopFullTransactionId
Definition: xact.c:126

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

Referenced by pg_current_xact_id().

◆ GetTopFullTransactionIdIfAny()

FullTransactionId GetTopFullTransactionIdIfAny ( void  )

Definition at line 500 of file xact.c.

501{
503}

References XactTopFullTransactionId.

Referenced by pg_current_xact_id_if_assigned().

◆ GetTopTransactionId()

◆ GetTopTransactionIdIfAny()

◆ IsAbortedTransactionBlockState()

◆ IsInParallelMode()

◆ IsInTransactionBlock()

bool IsInTransactionBlock ( bool  isTopLevel)

Definition at line 3791 of file xact.c.

3792{
3793 /*
3794 * Return true on same conditions that would make
3795 * PreventInTransactionBlock error out
3796 */
3797 if (IsTransactionBlock())
3798 return true;
3799
3800 if (IsSubTransaction())
3801 return true;
3802
3803 if (!isTopLevel)
3804 return true;
3805
3808 return true;
3809
3810 return false;
3811}
bool IsSubTransaction(void)
Definition: xact.c:5066
bool IsTransactionBlock(void)
Definition: xact.c:4993

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

Referenced by vacuum().

◆ IsSubTransaction()

◆ IsSubxactTopXidLogPending()

bool IsSubxactTopXidLogPending ( void  )

Definition at line 560 of file xact.c.

561{
562 /* check whether it is already logged */
564 return false;
565
566 /* effective_wal_level has to be logical */
568 return false;
569
570 /* we need to be in a transaction state */
571 if (!IsTransactionState())
572 return false;
573
574 /* it has to be a subtransaction */
575 if (!IsSubTransaction())
576 return false;
577
578 /* the subtransaction has to have a XID assigned */
580 return false;
581
582 return true;
583}
bool IsTransactionState(void)
Definition: xact.c:388
TransactionId GetCurrentTransactionIdIfAny(void)
Definition: xact.c:472
#define XLogLogicalInfoActive()
Definition: xlog.h:136

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

Referenced by MarkSubxactTopXidLogged(), and XLogRecordAssemble().

◆ IsTransactionBlock()

◆ IsTransactionOrTransactionBlock()

◆ IsTransactionState()

bool IsTransactionState ( void  )

Definition at line 388 of file xact.c.

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

References CurrentTransactionState, TransactionStateData::state, and TRANS_INPROGRESS.

Referenced by AcceptInvalidationMessages(), 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(), ConditionalCatalogCacheInitializeCache(), CreateInitDecodingContext(), ensure_last_message(), FetchRelationStates(), FinishSyncWorker(), IsSubxactTopXidLogPending(), LogicalRepApplyLoop(), LogLogicalMessage(), maybe_reread_subscription(), pa_send_data(), pa_start_subtrans(), pg_do_encoding_conversion(), PrepareClientEncoding(), PrepareTempTablespaces(), ProcessSyncingTablesForApply(), ProcessSyncingTablesForSync(), RelationCacheInvalidate(), RelationFlushRelation(), RelationInitPhysicalAddr(), replorigin_create(), replorigin_drop_by_name(), ReplSlotSyncWorkerMain(), SetMultiXactIdLimit(), SetTransactionIdLimit(), SnapBuildClearExportedSnapshot(), SocketBackend(), stream_stop_internal(), SyncReplicationSlots(), update_retention_status(), and validate_remote_info().

◆ MarkCurrentTransactionIdLoggedIfAny()

void MarkCurrentTransactionIdLoggedIfAny ( void  )

◆ MarkSubxactTopXidLogged()

void MarkSubxactTopXidLogged ( void  )

Definition at line 592 of file xact.c.

593{
595
597}
bool IsSubxactTopXidLogPending(void)
Definition: xact.c:560

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:339
Oid tsId
Definition: xact.h:259
Oid dbId
Definition: xact.h:258
TimestampTz origin_timestamp
Definition: xact.h:318
XLogRecPtr origin_lsn
Definition: xact.h:317
xl_xact_stats_item * stats
Definition: xact.h:426
RelFileLocator * xlocators
Definition: xact.h:423
TransactionId twophase_xid
Definition: xact.h:428
TimestampTz xact_time
Definition: xact.h:413
TransactionId * subxacts
Definition: xact.h:420
XLogRecPtr origin_lsn
Definition: xact.h:431
char twophase_gid[GIDSIZE]
Definition: xact.h:429
TimestampTz origin_timestamp
Definition: xact.h:432
RelFileLocator xlocators[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:272
xl_xact_stats_item items[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:299
TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:265
int nsubxacts
Definition: xact.h:264
TransactionId xid
Definition: xact.h:312
uint32 xinfo
Definition: xact.h:253
struct xl_xact_stats_item xl_xact_stats_item
#define MinSizeOfXactSubxacts
Definition: xact.h:267
struct xl_xact_dbinfo xl_xact_dbinfo
#define XACT_XINFO_HAS_GID
Definition: xact.h:196
struct xl_xact_origin xl_xact_origin
#define XACT_XINFO_HAS_ORIGIN
Definition: xact.h:194
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:193
#define MinSizeOfXactRelfileLocators
Definition: xact.h:274
#define MinSizeOfXactStatsItems
Definition: xact.h:301
#define XACT_XINFO_HAS_RELFILELOCATORS
Definition: xact.h:191
#define MinSizeOfXactAbort
Definition: xact.h:351
struct xl_xact_xinfo xl_xact_xinfo
#define XACT_XINFO_HAS_DBINFO
Definition: xact.h:189
struct xl_xact_twophase xl_xact_twophase
#define XLOG_XACT_HAS_INFO
Definition: xact.h:183
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:190
#define XACT_XINFO_HAS_DROPPED_STATS
Definition: xact.h:197

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:323
SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:306
int nmsgs
Definition: xact.h:305
xl_xact_stats_item * stats
Definition: xact.h:393
TimestampTz xact_time
Definition: xact.h:380
TransactionId twophase_xid
Definition: xact.h:398
RelFileLocator * xlocators
Definition: xact.h:390
TimestampTz origin_timestamp
Definition: xact.h:406
TransactionId * subxacts
Definition: xact.h:387
char twophase_gid[GIDSIZE]
Definition: xact.h:399
XLogRecPtr origin_lsn
Definition: xact.h:405
SharedInvalidationMessage * msgs
Definition: xact.h:396
#define MinSizeOfXactInvals
Definition: xact.h:308
#define MinSizeOfXactCommit
Definition: xact.h:335
#define XACT_XINFO_HAS_INVALS
Definition: xact.h:192

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->nstats = xlrec->ncommitstats;
256 parsed->nabortstats = xlrec->nabortstats;
257 parsed->nmsgs = xlrec->ninvalmsgs;
258
259 strncpy(parsed->twophase_gid, bufptr, xlrec->gidlen);
260 bufptr += MAXALIGN(xlrec->gidlen);
261
262 parsed->subxacts = (TransactionId *) bufptr;
263 bufptr += MAXALIGN(xlrec->nsubxacts * sizeof(TransactionId));
264
265 parsed->xlocators = (RelFileLocator *) bufptr;
266 bufptr += MAXALIGN(xlrec->ncommitrels * sizeof(RelFileLocator));
267
268 parsed->abortlocators = (RelFileLocator *) bufptr;
269 bufptr += MAXALIGN(xlrec->nabortrels * sizeof(RelFileLocator));
270
271 parsed->stats = (xl_xact_stats_item *) bufptr;
272 bufptr += MAXALIGN(xlrec->ncommitstats * sizeof(xl_xact_stats_item));
273
274 parsed->abortstats = (xl_xact_stats_item *) bufptr;
275 bufptr += MAXALIGN(xlrec->nabortstats * sizeof(xl_xact_stats_item));
276
277 parsed->msgs = (SharedInvalidationMessage *) bufptr;
278 bufptr += MAXALIGN(xlrec->ninvalmsgs * sizeof(SharedInvalidationMessage));
279}
#define MAXALIGN(LEN)
Definition: c.h:824
RelFileLocator * abortlocators
Definition: xact.h:401
xl_xact_stats_item * abortstats
Definition: xact.h:403
TimestampTz prepared_at
Definition: xact.h:359
int32 nabortrels
Definition: xact.h:363
int32 ninvalmsgs
Definition: xact.h:366
int32 ncommitstats
Definition: xact.h:364
TimestampTz origin_timestamp
Definition: xact.h:370
uint16 gidlen
Definition: xact.h:368
int32 nabortstats
Definition: xact.h:365
Oid database
Definition: xact.h:358
XLogRecPtr origin_lsn
Definition: xact.h:369
int32 ncommitrels
Definition: xact.h:362
TransactionId xid
Definition: xact.h:357
int32 nsubxacts
Definition: xact.h:361

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_parsed_commit::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_parsed_commit::nstats, 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 4014 of file xact.c.

4015{
4017 bool result;
4018
4019 /* Set up to commit the current transaction */
4020 result = EndTransactionBlock(false);
4021
4022 /* If successful, change outer tblock state to PREPARE */
4023 if (result)
4024 {
4026
4027 while (s->parent != NULL)
4028 s = s->parent;
4029
4030 if (s->blockState == TBLOCK_END)
4031 {
4032 /* Save GID where PrepareTransaction can find it again */
4034
4036 }
4037 else
4038 {
4039 /*
4040 * ignore case where we are not in a transaction;
4041 * EndTransactionBlock already issued a warning.
4042 */
4045 /* Don't send back a PREPARE result tag... */
4046 result = false;
4047 }
4048 }
4049
4050 return result;
4051}
static char * prepareGID
Definition: xact.c:289
bool EndTransactionBlock(bool chain)
Definition: xact.c:4066

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

3670{
3671 /*
3672 * xact block already started?
3673 */
3674 if (IsTransactionBlock())
3675 ereport(ERROR,
3676 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3677 /* translator: %s represents an SQL statement name */
3678 errmsg("%s cannot run inside a transaction block",
3679 stmtType)));
3680
3681 /*
3682 * subtransaction?
3683 */
3684 if (IsSubTransaction())
3685 ereport(ERROR,
3686 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3687 /* translator: %s represents an SQL statement name */
3688 errmsg("%s cannot run inside a subtransaction",
3689 stmtType)));
3690
3691 /*
3692 * inside a function call?
3693 */
3694 if (!isTopLevel)
3695 ereport(ERROR,
3696 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3697 /* translator: %s represents an SQL statement name */
3698 errmsg("%s cannot be executed from a function or procedure",
3699 stmtType)));
3700
3701 /* If we got past IsTransactionBlock test, should be in default state */
3704 elog(FATAL, "cannot prevent transaction chain");
3705
3706 /* All okay. Set the flag to make sure the right thing happens later. */
3708}
int MyXactFlags
Definition: xact.c:137
#define XACT_FLAGS_NEEDIMMEDIATECOMMIT
Definition: xact.h:115

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

3887{
3888 SubXactCallbackItem *item;
3889
3890 item = (SubXactCallbackItem *)
3892 item->callback = callback;
3893 item->arg = arg;
3894 item->next = SubXact_callbacks;
3895 SubXact_callbacks = item;
3896}
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1232
void * arg
struct SubXactCallbackItem * next
Definition: xact.c:323
SubXactCallback callback
Definition: xact.c:324
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46
static SubXactCallbackItem * SubXact_callbacks
Definition: xact.c:328

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

3827{
3828 XactCallbackItem *item;
3829
3830 item = (XactCallbackItem *)
3832 item->callback = callback;
3833 item->arg = arg;
3834 item->next = Xact_callbacks;
3835 Xact_callbacks = item;
3836}
struct XactCallbackItem * next
Definition: xact.c:311
void * arg
Definition: xact.c:313
XactCallback callback
Definition: xact.c:312
static XactCallbackItem * Xact_callbacks
Definition: xact.c:316

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

4791{
4793
4794 /*
4795 * We do not check for parallel mode here. It's permissible to start and
4796 * end "internal" subtransactions while in parallel mode, so long as no
4797 * new XIDs or command IDs are assigned.
4798 */
4799
4801 elog(ERROR, "ReleaseCurrentSubTransaction: unexpected state %s",
4806 s = CurrentTransactionState; /* changed by pop */
4808}
MemoryContext CurTransactionContext
Definition: mcxt.c:172
static void CommitSubTransaction(void)
Definition: xact.c:5126

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

4481{
4483 TransactionState target,
4484 xact;
4485
4486 /*
4487 * Workers synchronize transaction state at the beginning of each parallel
4488 * operation, so we can't account for transaction state change after that
4489 * point. (Note that this check will certainly error out if s->blockState
4490 * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4491 * below.)
4492 */
4494 ereport(ERROR,
4495 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4496 errmsg("cannot release savepoints during a parallel operation")));
4497
4498 switch (s->blockState)
4499 {
4500 /*
4501 * We can't release a savepoint if there is no savepoint defined.
4502 */
4503 case TBLOCK_INPROGRESS:
4504 ereport(ERROR,
4505 (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4506 errmsg("savepoint \"%s\" does not exist", name)));
4507 break;
4508
4510 /* See comment about implicit transactions in DefineSavepoint */
4511 ereport(ERROR,
4512 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4513 /* translator: %s represents an SQL statement name */
4514 errmsg("%s can only be used in transaction blocks",
4515 "RELEASE SAVEPOINT")));
4516 break;
4517
4518 /*
4519 * We are in a non-aborted subtransaction. This is the only valid
4520 * case.
4521 */
4523 break;
4524
4525 /* These cases are invalid. */
4526 case TBLOCK_DEFAULT:
4527 case TBLOCK_STARTED:
4528 case TBLOCK_BEGIN:
4530 case TBLOCK_SUBBEGIN:
4531 case TBLOCK_END:
4532 case TBLOCK_SUBRELEASE:
4533 case TBLOCK_SUBCOMMIT:
4534 case TBLOCK_ABORT:
4535 case TBLOCK_SUBABORT:
4536 case TBLOCK_ABORT_END:
4540 case TBLOCK_SUBRESTART:
4542 case TBLOCK_PREPARE:
4543 elog(FATAL, "ReleaseSavepoint: unexpected state %s",
4545 break;
4546 }
4547
4548 for (target = s; target; target = target->parent)
4549 {
4550 if (target->name && strcmp(target->name, name) == 0)
4551 break;
4552 }
4553
4554 if (!target)
4555 ereport(ERROR,
4556 (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4557 errmsg("savepoint \"%s\" does not exist", name)));
4558
4559 /* disallow crossing savepoint level boundaries */
4560 if (target->savepointLevel != s->savepointLevel)
4561 ereport(ERROR,
4562 (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4563 errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
4564
4565 /*
4566 * Mark "commit pending" all subtransactions up to the target
4567 * subtransaction. The actual commits will happen when control gets to
4568 * CommitTransactionCommand.
4569 */
4571 for (;;)
4572 {
4575 if (xact == target)
4576 break;
4577 xact = xact->parent;
4578 Assert(xact);
4579 }
4580}

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

3739{
3740 CheckTransactionBlock(isTopLevel, true, stmtType);
3741}
static void CheckTransactionBlock(bool isTopLevel, bool throwError, const char *stmtType)
Definition: xact.c:3747

References CheckTransactionBlock().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

◆ RestoreTransactionCharacteristics()

◆ RollbackAndReleaseCurrentSubTransaction()

void RollbackAndReleaseCurrentSubTransaction ( void  )

Definition at line 4818 of file xact.c.

4819{
4821
4822 /*
4823 * We do not check for parallel mode here. It's permissible to start and
4824 * end "internal" subtransactions while in parallel mode, so long as no
4825 * new XIDs or command IDs are assigned.
4826 */
4827
4828 switch (s->blockState)
4829 {
4830 /* Must be in a subtransaction */
4832 case TBLOCK_SUBABORT:
4833 break;
4834
4835 /* These cases are invalid. */
4836 case TBLOCK_DEFAULT:
4837 case TBLOCK_STARTED:
4838 case TBLOCK_BEGIN:
4841 case TBLOCK_SUBBEGIN:
4842 case TBLOCK_INPROGRESS:
4843 case TBLOCK_END:
4844 case TBLOCK_SUBRELEASE:
4845 case TBLOCK_SUBCOMMIT:
4846 case TBLOCK_ABORT:
4847 case TBLOCK_ABORT_END:
4851 case TBLOCK_SUBRESTART:
4853 case TBLOCK_PREPARE:
4854 elog(FATAL, "RollbackAndReleaseCurrentSubTransaction: unexpected state %s",
4856 break;
4857 }
4858
4859 /*
4860 * Abort the current subtransaction, if needed.
4861 */
4864
4865 /* And clean it up, too */
4867
4868 s = CurrentTransactionState; /* changed by pop */
4874}

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

4590{
4592 TransactionState target,
4593 xact;
4594
4595 /*
4596 * Workers synchronize transaction state at the beginning of each parallel
4597 * operation, so we can't account for transaction state change after that
4598 * point. (Note that this check will certainly error out if s->blockState
4599 * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4600 * below.)
4601 */
4603 ereport(ERROR,
4604 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4605 errmsg("cannot rollback to savepoints during a parallel operation")));
4606
4607 switch (s->blockState)
4608 {
4609 /*
4610 * We can't rollback to a savepoint if there is no savepoint
4611 * defined.
4612 */
4613 case TBLOCK_INPROGRESS:
4614 case TBLOCK_ABORT:
4615 ereport(ERROR,
4616 (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4617 errmsg("savepoint \"%s\" does not exist", name)));
4618 break;
4619
4621 /* See comment about implicit transactions in DefineSavepoint */
4622 ereport(ERROR,
4623 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4624 /* translator: %s represents an SQL statement name */
4625 errmsg("%s can only be used in transaction blocks",
4626 "ROLLBACK TO SAVEPOINT")));
4627 break;
4628
4629 /*
4630 * There is at least one savepoint, so proceed.
4631 */
4633 case TBLOCK_SUBABORT:
4634 break;
4635
4636 /* These cases are invalid. */
4637 case TBLOCK_DEFAULT:
4638 case TBLOCK_STARTED:
4639 case TBLOCK_BEGIN:
4641 case TBLOCK_SUBBEGIN:
4642 case TBLOCK_END:
4643 case TBLOCK_SUBRELEASE:
4644 case TBLOCK_SUBCOMMIT:
4645 case TBLOCK_ABORT_END:
4649 case TBLOCK_SUBRESTART:
4651 case TBLOCK_PREPARE:
4652 elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4654 break;
4655 }
4656
4657 for (target = s; target; target = target->parent)
4658 {
4659 if (target->name && strcmp(target->name, name) == 0)
4660 break;
4661 }
4662
4663 if (!target)
4664 ereport(ERROR,
4665 (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4666 errmsg("savepoint \"%s\" does not exist", name)));
4667
4668 /* disallow crossing savepoint level boundaries */
4669 if (target->savepointLevel != s->savepointLevel)
4670 ereport(ERROR,
4671 (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4672 errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
4673
4674 /*
4675 * Mark "abort pending" all subtransactions up to the target
4676 * subtransaction. The actual aborts will happen when control gets to
4677 * CommitTransactionCommand.
4678 */
4680 for (;;)
4681 {
4682 if (xact == target)
4683 break;
4684 if (xact->blockState == TBLOCK_SUBINPROGRESS)
4686 else if (xact->blockState == TBLOCK_SUBABORT)
4688 else
4689 elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4691 xact = xact->parent;
4692 Assert(xact);
4693 }
4694
4695 /* And mark the target as "restart pending" */
4696 if (xact->blockState == TBLOCK_SUBINPROGRESS)
4698 else if (xact->blockState == TBLOCK_SUBABORT)
4700 else
4701 elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4703}

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

5563{
5565 Size nxids = 0;
5566 Size i = 0;
5567 TransactionId *workspace;
5569
5570 result = (SerializedTransactionState *) start_address;
5571
5572 result->xactIsoLevel = XactIsoLevel;
5575 result->currentFullTransactionId =
5578
5579 /*
5580 * If we're running in a parallel worker and launching a parallel worker
5581 * of our own, we can just pass along the information that was passed to
5582 * us.
5583 */
5584 if (nParallelCurrentXids > 0)
5585 {
5587 memcpy(&result->parallelCurrentXids[0], ParallelCurrentXids,
5589 return;
5590 }
5591
5592 /*
5593 * OK, we need to generate a sorted list of XIDs that our workers should
5594 * view as current. First, figure out how many there are.
5595 */
5596 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5597 {
5599 nxids = add_size(nxids, 1);
5600 nxids = add_size(nxids, s->nChildXids);
5601 }
5603 <= maxsize);
5604
5605 /* Copy them to our scratch space. */
5606 workspace = palloc(nxids * sizeof(TransactionId));
5607 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5608 {
5610 workspace[i++] = XidFromFullTransactionId(s->fullTransactionId);
5611 if (s->nChildXids > 0)
5612 memcpy(&workspace[i], s->childXids,
5613 s->nChildXids * sizeof(TransactionId));
5614 i += s->nChildXids;
5615 }
5616 Assert(i == nxids);
5617
5618 /* Sort them. */
5619 qsort(workspace, nxids, sizeof(TransactionId), xidComparator);
5620
5621 /* Copy data into output area. */
5622 result->nParallelCurrentXids = nxids;
5623 memcpy(&result->parallelCurrentXids[0], workspace,
5624 nxids * sizeof(TransactionId));
5625}
int i
Definition: isn.c:77
void * palloc(Size size)
Definition: mcxt.c:1387
#define qsort(a, b, c, d)
Definition: port.h:499
FullTransactionId currentFullTransactionId
Definition: xact.c:233
FullTransactionId topFullTransactionId
Definition: xact.c:232
CommandId currentCommandId
Definition: xact.c:234
TransactionId parallelCurrentXids[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.c:236
TransactionId * childXids
Definition: xact.c:207
static int nParallelCurrentXids
Definition: xact.c:127
static TransactionId * ParallelCurrentXids
Definition: xact.c:128
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 860 of file xact.c.

861{
863 xactStartTimestamp = xact_ts;
864 stmtStartTimestamp = stmt_ts;
865}

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

Referenced by ParallelWorkerMain().

◆ StartParallelWorkerTransaction()

void StartParallelWorkerTransaction ( char *  tstatespace)

◆ StartTransactionCommand()

void StartTransactionCommand ( void  )

Definition at line 3080 of file xact.c.

3081{
3083
3084 switch (s->blockState)
3085 {
3086 /*
3087 * if we aren't in a transaction block, we just do our usual start
3088 * transaction.
3089 */
3090 case TBLOCK_DEFAULT:
3093 break;
3094
3095 /*
3096 * We are somewhere in a transaction block or subtransaction and
3097 * about to start a new command. For now we do nothing, but
3098 * someday we may do command-local resource initialization. (Note
3099 * that any needed CommandCounterIncrement was done by the
3100 * previous CommitTransactionCommand.)
3101 */
3102 case TBLOCK_INPROGRESS:
3105 break;
3106
3107 /*
3108 * Here we are in a failed transaction block (one of the commands
3109 * caused an abort) so we do nothing but remain in the abort
3110 * state. Eventually we will get a ROLLBACK command which will
3111 * get us out of this state. (It is up to other code to ensure
3112 * that no commands other than ROLLBACK will be processed in these
3113 * states.)
3114 */
3115 case TBLOCK_ABORT:
3116 case TBLOCK_SUBABORT:
3117 break;
3118
3119 /* These cases are invalid. */
3120 case TBLOCK_STARTED:
3121 case TBLOCK_BEGIN:
3123 case TBLOCK_SUBBEGIN:
3124 case TBLOCK_END:
3125 case TBLOCK_SUBRELEASE:
3126 case TBLOCK_SUBCOMMIT:
3127 case TBLOCK_ABORT_END:
3131 case TBLOCK_SUBRESTART:
3133 case TBLOCK_PREPARE:
3134 elog(ERROR, "StartTransactionCommand: unexpected state %s",
3136 break;
3137 }
3138
3139 /*
3140 * We must switch to CurTransactionContext before returning. This is
3141 * already done if we called StartTransaction, otherwise not.
3142 */
3145}

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(), copy_sequences(), DefineIndex(), DisableSubscriptionAndExit(), do_autovacuum(), EventTriggerOnLogin(), exec_replication_command(), FetchRelationStates(), FinishSyncWorker(), get_database_list(), get_subscription_list(), IdentifySystem(), index_drop(), initialize_worker_spi(), InitializeLogRepWorker(), InitPostgres(), LogicalRepSyncSequences(), LogicalRepSyncTableStart(), maybe_reread_subscription(), movedb(), pa_start_subtrans(), ParallelApplyWorkerMain(), ParallelWorkerMain(), perform_work_item(), ProcessCatchupInterrupt(), ProcessIncomingNotify(), ProcessSyncingTablesForApply(), ProcessSyncingTablesForSync(), ReindexMultipleInternal(), ReindexRelationConcurrently(), RemoveTempRelationsCallback(), ReorderBufferProcessTXN(), ReplSlotSyncWorkerMain(), run_apply_worker(), shell_check_detail(), SnapBuildExportSnapshot(), start_xact_command(), update_retention_status(), vacuum(), vacuum_rel(), validate_remote_info(), and worker_spi_main().

◆ SubTransactionIsActive()

bool SubTransactionIsActive ( SubTransactionId  subxid)

Definition at line 806 of file xact.c.

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

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

◆ TransactionBlockStatusCode()

char TransactionBlockStatusCode ( void  )

Definition at line 5025 of file xact.c.

5026{
5028
5029 switch (s->blockState)
5030 {
5031 case TBLOCK_DEFAULT:
5032 case TBLOCK_STARTED:
5033 return 'I'; /* idle --- not in transaction */
5034 case TBLOCK_BEGIN:
5035 case TBLOCK_SUBBEGIN:
5036 case TBLOCK_INPROGRESS:
5040 case TBLOCK_END:
5041 case TBLOCK_SUBRELEASE:
5042 case TBLOCK_SUBCOMMIT:
5043 case TBLOCK_PREPARE:
5044 return 'T'; /* in transaction */
5045 case TBLOCK_ABORT:
5046 case TBLOCK_SUBABORT:
5047 case TBLOCK_ABORT_END:
5051 case TBLOCK_SUBRESTART:
5053 return 'E'; /* in failed transaction */
5054 }
5055
5056 /* should never get here */
5057 elog(FATAL, "invalid transaction block state: %s",
5059 return 0; /* keep compiler quiet */
5060}

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

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

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(), HeapTupleCleanMoved(), HeapTupleHeaderAdjustCmax(), HeapTupleHeaderGetCmax(), HeapTupleHeaderGetCmin(), HeapTupleHeaderIsOnlyLocked(), HeapTupleSatisfiesDirty(), HeapTupleSatisfiesMVCC(), HeapTupleSatisfiesSelf(), 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 3899 of file xact.c.

3900{
3901 SubXactCallbackItem *item;
3902 SubXactCallbackItem *prev;
3903
3904 prev = NULL;
3905 for (item = SubXact_callbacks; item; prev = item, item = item->next)
3906 {
3907 if (item->callback == callback && item->arg == arg)
3908 {
3909 if (prev)
3910 prev->next = item->next;
3911 else
3912 SubXact_callbacks = item->next;
3913 pfree(item);
3914 break;
3915 }
3916 }
3917}
void pfree(void *pointer)
Definition: mcxt.c:1616

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

◆ UnregisterXactCallback()

void UnregisterXactCallback ( XactCallback  callback,
void *  arg 
)

Definition at line 3839 of file xact.c.

3840{
3841 XactCallbackItem *item;
3842 XactCallbackItem *prev;
3843
3844 prev = NULL;
3845 for (item = Xact_callbacks; item; prev = item, item = item->next)
3846 {
3847 if (item->callback == callback && item->arg == arg)
3848 {
3849 if (prev)
3850 prev->next = item->next;
3851 else
3852 Xact_callbacks = item->next;
3853 pfree(item);
3854 break;
3855 }
3856 }
3857}

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

◆ UserAbortTransactionBlock()

void UserAbortTransactionBlock ( bool  chain)

Definition at line 4226 of file xact.c.

4227{
4229
4230 switch (s->blockState)
4231 {
4232 /*
4233 * We are inside a transaction block and we got a ROLLBACK command
4234 * from the user, so tell CommitTransactionCommand to abort and
4235 * exit the transaction block.
4236 */
4237 case TBLOCK_INPROGRESS:
4239 break;
4240
4241 /*
4242 * We are inside a failed transaction block and we got a ROLLBACK
4243 * command from the user. Abort processing is already done, so
4244 * CommitTransactionCommand just has to cleanup and go back to
4245 * idle state.
4246 */
4247 case TBLOCK_ABORT:
4249 break;
4250
4251 /*
4252 * We are inside a subtransaction. Mark everything up to top
4253 * level as exitable.
4254 */
4256 case TBLOCK_SUBABORT:
4257 while (s->parent != NULL)
4258 {
4261 else if (s->blockState == TBLOCK_SUBABORT)
4263 else
4264 elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4266 s = s->parent;
4267 }
4268 if (s->blockState == TBLOCK_INPROGRESS)
4270 else if (s->blockState == TBLOCK_ABORT)
4272 else
4273 elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4275 break;
4276
4277 /*
4278 * The user issued ABORT when not inside a transaction. For
4279 * ROLLBACK without CHAIN, issue a WARNING and go to abort state.
4280 * The upcoming call to CommitTransactionCommand() will then put
4281 * us back into the default state. For ROLLBACK AND CHAIN, error.
4282 *
4283 * We do the same thing with ABORT inside an implicit transaction,
4284 * although in this case we might be rolling back actual database
4285 * state changes. (It's debatable whether we should issue a
4286 * WARNING in this case, but we have done so historically.)
4287 */
4288 case TBLOCK_STARTED:
4290 if (chain)
4291 ereport(ERROR,
4292 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4293 /* translator: %s represents an SQL statement name */
4294 errmsg("%s can only be used in transaction blocks",
4295 "ROLLBACK AND CHAIN")));
4296 else
4298 (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
4299 errmsg("there is no transaction in progress")));
4301 break;
4302
4303 /*
4304 * The user issued an ABORT that somehow ran inside a parallel
4305 * worker. We can't cope with that.
4306 */
4308 ereport(FATAL,
4309 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4310 errmsg("cannot abort during a parallel operation")));
4311 break;
4312
4313 /* These cases are invalid. */
4314 case TBLOCK_DEFAULT:
4315 case TBLOCK_BEGIN:
4316 case TBLOCK_SUBBEGIN:
4317 case TBLOCK_END:
4318 case TBLOCK_SUBRELEASE:
4319 case TBLOCK_SUBCOMMIT:
4320 case TBLOCK_ABORT_END:
4324 case TBLOCK_SUBRESTART:
4326 case TBLOCK_PREPARE:
4327 elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4329 break;
4330 }
4331
4334
4335 s->chain = chain;
4336}

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

3733{
3734 CheckTransactionBlock(isTopLevel, false, stmtType);
3735}

References CheckTransactionBlock().

Referenced by ExecSetVariableStmt(), and standard_ProcessUtility().

◆ xact_desc()

void xact_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 439 of file xactdesc.c.

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

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

◆ xact_identify()

const char * xact_identify ( uint8  info)

Definition at line 487 of file xactdesc.c.

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

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

◆ xact_redo()

void xact_redo ( XLogReaderState record)

Definition at line 6385 of file xact.c.

6386{
6387 uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
6388
6389 /* Backup blocks are not used in xact records */
6391
6392 if (info == XLOG_XACT_COMMIT)
6393 {
6394 xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6395 xl_xact_parsed_commit parsed;
6396
6397 ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6398 xact_redo_commit(&parsed, XLogRecGetXid(record),
6399 record->EndRecPtr, XLogRecGetOrigin(record));
6400 }
6401 else if (info == XLOG_XACT_COMMIT_PREPARED)
6402 {
6403 xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6404 xl_xact_parsed_commit parsed;
6405
6406 ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6407 xact_redo_commit(&parsed, parsed.twophase_xid,
6408 record->EndRecPtr, XLogRecGetOrigin(record));
6409
6410 /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6411 LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6412 PrepareRedoRemove(parsed.twophase_xid, false);
6413 LWLockRelease(TwoPhaseStateLock);
6414 }
6415 else if (info == XLOG_XACT_ABORT)
6416 {
6417 xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6418 xl_xact_parsed_abort parsed;
6419
6420 ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6421 xact_redo_abort(&parsed, XLogRecGetXid(record),
6422 record->EndRecPtr, XLogRecGetOrigin(record));
6423 }
6424 else if (info == XLOG_XACT_ABORT_PREPARED)
6425 {
6426 xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6427 xl_xact_parsed_abort parsed;
6428
6429 ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6430 xact_redo_abort(&parsed, parsed.twophase_xid,
6431 record->EndRecPtr, XLogRecGetOrigin(record));
6432
6433 /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6434 LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6435 PrepareRedoRemove(parsed.twophase_xid, false);
6436 LWLockRelease(TwoPhaseStateLock);
6437 }
6438 else if (info == XLOG_XACT_PREPARE)
6439 {
6440 /*
6441 * Store xid and start/end pointers of the WAL record in TwoPhaseState
6442 * gxact entry.
6443 */
6444 LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6446 XLogRecGetData(record),
6447 record->ReadRecPtr,
6448 record->EndRecPtr,
6449 XLogRecGetOrigin(record));
6450 LWLockRelease(TwoPhaseStateLock);
6451 }
6452 else if (info == XLOG_XACT_ASSIGNMENT)
6453 {
6455
6458 xlrec->nsubxacts, xlrec->xsub);
6459 }
6460 else if (info == XLOG_XACT_INVALIDATIONS)
6461 {
6462 /*
6463 * XXX we do ignore this for now, what matters are invalidations
6464 * written into the commit record.
6465 */
6466 }
6467 else
6468 elog(PANIC, "xact_redo: unknown op code %u", info);
6469}
#define PANIC
Definition: elog.h:42
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1178
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1898
@ LW_EXCLUSIVE
Definition: lwlock.h:112
void ProcArrayApplyXidAssignment(TransactionId topxid, int nsubxids, TransactionId *subxids)
Definition: procarray.c:1320
XLogRecPtr EndRecPtr
Definition: xlogreader.h:206
XLogRecPtr ReadRecPtr
Definition: xlogreader.h:205
TransactionId xsub[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:223
#define InvalidFullTransactionId
Definition: transam.h:56
void PrepareRedoRemove(TransactionId xid, bool giveWarning)
Definition: twophase.c:2664
void PrepareRedoAdd(FullTransactionId fxid, char *buf, XLogRecPtr start_lsn, XLogRecPtr end_lsn, RepOriginId origin_id)
Definition: twophase.c:2507
static void xact_redo_commit(xl_xact_parsed_commit *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:6152
static void xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:6306
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:411
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:416
HotStandbyState standbyState
Definition: xlogutils.c:53
@ STANDBY_INITIALIZED
Definition: xlogutils.h:53

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

5813{
5815
5816 if (s->nChildXids == 0)
5817 *ptr = NULL;
5818 else
5819 *ptr = s->childXids;
5820
5821 return s->nChildXids;
5822}

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

6014{
6015 xl_xact_abort xlrec;
6016 xl_xact_xinfo xl_xinfo;
6017 xl_xact_subxacts xl_subxacts;
6018 xl_xact_relfilelocators xl_relfilelocators;
6019 xl_xact_stats_items xl_dropped_stats;
6020 xl_xact_twophase xl_twophase;
6021 xl_xact_dbinfo xl_dbinfo;
6022 xl_xact_origin xl_origin;
6023
6024 uint8 info;
6025
6027
6028 xl_xinfo.xinfo = 0;
6029
6030 /* decide between a plain and 2pc abort */
6031 if (!TransactionIdIsValid(twophase_xid))
6032 info = XLOG_XACT_ABORT;
6033 else
6035
6036
6037 /* First figure out and collect all the information needed */
6038
6039 xlrec.xact_time = abort_time;
6040
6042 xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
6043
6044 if (nsubxacts > 0)
6045 {
6046 xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
6047 xl_subxacts.nsubxacts = nsubxacts;
6048 }
6049
6050 if (nrels > 0)
6051 {
6053 xl_relfilelocators.nrels = nrels;
6054 info |= XLR_SPECIAL_REL_UPDATE;
6055 }
6056
6057 if (ndroppedstats > 0)
6058 {
6060 xl_dropped_stats.nitems = ndroppedstats;
6061 }
6062
6063 if (TransactionIdIsValid(twophase_xid))
6064 {
6065 xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
6066 xl_twophase.xid = twophase_xid;
6067 Assert(twophase_gid != NULL);
6068
6070 xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
6071 }
6072
6073 if (TransactionIdIsValid(twophase_xid) && XLogLogicalInfoActive())
6074 {
6075 xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
6076 xl_dbinfo.dbId = MyDatabaseId;
6077 xl_dbinfo.tsId = MyDatabaseTableSpace;
6078 }
6079
6080 /*
6081 * Dump transaction origin information. We need this during recovery to
6082 * update the replication origin progress.
6083 */
6085 {
6086 xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
6087
6090 }
6091
6092 if (xl_xinfo.xinfo != 0)
6093 info |= XLOG_XACT_HAS_INFO;
6094
6095 /* Then include all the collected data into the abort record. */
6096
6098
6100
6101 if (xl_xinfo.xinfo != 0)
6102 XLogRegisterData(&xl_xinfo, sizeof(xl_xinfo));
6103
6104 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
6105 XLogRegisterData(&xl_dbinfo, sizeof(xl_dbinfo));
6106
6107 if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
6108 {
6109 XLogRegisterData(&xl_subxacts,
6111 XLogRegisterData(subxacts,
6112 nsubxacts * sizeof(TransactionId));
6113 }
6114
6116 {
6117 XLogRegisterData(&xl_relfilelocators,
6119 XLogRegisterData(rels,
6120 nrels * sizeof(RelFileLocator));
6121 }
6122
6123 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
6124 {
6125 XLogRegisterData(&xl_dropped_stats,
6127 XLogRegisterData(droppedstats,
6128 ndroppedstats * sizeof(xl_xact_stats_item));
6129 }
6130
6131 if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
6132 {
6133 XLogRegisterData(&xl_twophase, sizeof(xl_xact_twophase));
6134 if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
6135 XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
6136 }
6137
6138 if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
6139 XLogRegisterData(&xl_origin, sizeof(xl_xact_origin));
6140
6141 /* Include the replication origin */
6143
6144 return XLogInsert(RM_XACT_ID, info);
6145}
Oid MyDatabaseTableSpace
Definition: globals.c:96
volatile uint32 CritSectionCount
Definition: globals.c:45
Oid MyDatabaseId
Definition: globals.c:94
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:109
#define XACT_XINFO_HAS_AE_LOCKS
Definition: xact.h:195
#define XLOG_INCLUDE_ORIGIN
Definition: xlog.h:165
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:478
void XLogRegisterData(const void *data, uint32 len)
Definition: xloginsert.c:368
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:460
void XLogBeginInsert(void)
Definition: xloginsert.c:152
#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 5836 of file xact.c.

5844{
5845 xl_xact_commit xlrec;
5846 xl_xact_xinfo xl_xinfo;
5847 xl_xact_dbinfo xl_dbinfo;
5848 xl_xact_subxacts xl_subxacts;
5849 xl_xact_relfilelocators xl_relfilelocators;
5850 xl_xact_stats_items xl_dropped_stats;
5851 xl_xact_invals xl_invals;
5852 xl_xact_twophase xl_twophase;
5853 xl_xact_origin xl_origin;
5854 uint8 info;
5855
5857
5858 xl_xinfo.xinfo = 0;
5859
5860 /* decide between a plain and 2pc commit */
5861 if (!TransactionIdIsValid(twophase_xid))
5862 info = XLOG_XACT_COMMIT;
5863 else
5865
5866 /* First figure out and collect all the information needed */
5867
5868 xlrec.xact_time = commit_time;
5869
5870 if (relcacheInval)
5872 if (forceSyncCommit)
5875 xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5876
5877 /*
5878 * Check if the caller would like to ask standbys for immediate feedback
5879 * once this commit is applied.
5880 */
5883
5884 /*
5885 * Relcache invalidations requires information about the current database
5886 * and so does logical decoding.
5887 */
5888 if (nmsgs > 0 || XLogLogicalInfoActive())
5889 {
5890 xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5891 xl_dbinfo.dbId = MyDatabaseId;
5892 xl_dbinfo.tsId = MyDatabaseTableSpace;
5893 }
5894
5895 if (nsubxacts > 0)
5896 {
5897 xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5898 xl_subxacts.nsubxacts = nsubxacts;
5899 }
5900
5901 if (nrels > 0)
5902 {
5904 xl_relfilelocators.nrels = nrels;
5905 info |= XLR_SPECIAL_REL_UPDATE;
5906 }
5907
5908 if (ndroppedstats > 0)
5909 {
5911 xl_dropped_stats.nitems = ndroppedstats;
5912 }
5913
5914 if (nmsgs > 0)
5915 {
5916 xl_xinfo.xinfo |= XACT_XINFO_HAS_INVALS;
5917 xl_invals.nmsgs = nmsgs;
5918 }
5919
5920 if (TransactionIdIsValid(twophase_xid))
5921 {
5922 xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5923 xl_twophase.xid = twophase_xid;
5924 Assert(twophase_gid != NULL);
5925
5927 xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
5928 }
5929
5930 /* dump transaction origin information */
5932 {
5933 xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
5934
5937 }
5938
5939 if (xl_xinfo.xinfo != 0)
5940 info |= XLOG_XACT_HAS_INFO;
5941
5942 /* Then include all the collected data into the commit record. */
5943
5945
5946 XLogRegisterData(&xlrec, sizeof(xl_xact_commit));
5947
5948 if (xl_xinfo.xinfo != 0)
5949 XLogRegisterData(&xl_xinfo.xinfo, sizeof(xl_xinfo.xinfo));
5950
5951 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5952 XLogRegisterData(&xl_dbinfo, sizeof(xl_dbinfo));
5953
5954 if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5955 {
5956 XLogRegisterData(&xl_subxacts,
5958 XLogRegisterData(subxacts,
5959 nsubxacts * sizeof(TransactionId));
5960 }
5961
5963 {
5964 XLogRegisterData(&xl_relfilelocators,
5966 XLogRegisterData(rels,
5967 nrels * sizeof(RelFileLocator));
5968 }
5969
5970 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
5971 {
5972 XLogRegisterData(&xl_dropped_stats,
5974 XLogRegisterData(droppedstats,
5975 ndroppedstats * sizeof(xl_xact_stats_item));
5976 }
5977
5978 if (xl_xinfo.xinfo & XACT_XINFO_HAS_INVALS)
5979 {
5981 XLogRegisterData(msgs,
5982 nmsgs * sizeof(SharedInvalidationMessage));
5983 }
5984
5985 if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5986 {
5987 XLogRegisterData(&xl_twophase, sizeof(xl_xact_twophase));
5988 if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
5989 XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
5990 }
5991
5992 if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5993 XLogRegisterData(&xl_origin, sizeof(xl_xact_origin));
5994
5995 /* we allow filtering by xacts */
5997
5998 return XLogInsert(RM_XACT_ID, info);
5999}
int synchronous_commit
Definition: xact.c:88
#define XACT_COMPLETION_UPDATE_RELCACHE_FILE
Definition: xact.h:208
#define XACT_COMPLETION_FORCE_SYNC_COMMIT
Definition: xact.h:209
#define XACT_COMPLETION_APPLY_FEEDBACK
Definition: xact.h:207

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

Referenced by StartTransaction().

◆ DefaultXactIsoLevel

PGDLLIMPORT int DefaultXactIsoLevel
extern

Definition at line 79 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactReadOnly

PGDLLIMPORT bool DefaultXactReadOnly
extern

Definition at line 82 of file xact.c.

Referenced by StartTransaction().

◆ MyXactFlags

◆ synchronous_commit

PGDLLIMPORT int synchronous_commit
extern

Definition at line 88 of file xact.c.

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

◆ xact_is_sampled

PGDLLIMPORT bool xact_is_sampled
extern

Definition at line 297 of file xact.c.

Referenced by check_log_duration(), and StartTransaction().

◆ XactDeferrable

◆ XactIsoLevel

◆ XactReadOnly