PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
xact.h File Reference
#include "access/transam.h"
#include "access/xlogreader.h"
#include "datatype/timestamp.h"
#include "lib/stringinfo.h"
#include "nodes/pg_list.h"
#include "storage/relfilelocator.h"
#include "storage/sinval.h"
Include dependency graph for xact.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

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

Macros

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

Typedefs

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

Enumerations

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

Functions

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

Variables

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

Macro Definition Documentation

◆ GIDSIZE

#define GIDSIZE   200

Definition at line 31 of file xact.h.

◆ IsolationIsSerializable

#define IsolationIsSerializable ( )    (XactIsoLevel == XACT_SERIALIZABLE)

Definition at line 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 3469 of file xact.c.

3470{
3471 /*
3472 * Repeatedly call AbortCurrentTransactionInternal() until all the work is
3473 * done.
3474 */
3476 {
3477 }
3478}
static bool AbortCurrentTransactionInternal(void)
Definition: xact.c:3487

References AbortCurrentTransactionInternal().

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

◆ AbortOutOfAnyTransaction()

void AbortOutOfAnyTransaction ( void  )

Definition at line 4880 of file xact.c.

4881{
4883
4884 /* Ensure we're not running in a doomed memory context */
4886
4887 /*
4888 * Get out of any transaction or nested transaction
4889 */
4890 do
4891 {
4892 switch (s->blockState)
4893 {
4894 case TBLOCK_DEFAULT:
4895 if (s->state == TRANS_DEFAULT)
4896 {
4897 /* Not in a transaction, do nothing */
4898 }
4899 else
4900 {
4901 /*
4902 * We can get here after an error during transaction start
4903 * (state will be TRANS_START). Need to clean up the
4904 * incompletely started transaction. First, adjust the
4905 * low-level state to suppress warning message from
4906 * AbortTransaction.
4907 */
4908 if (s->state == TRANS_START)
4912 }
4913 break;
4914 case TBLOCK_STARTED:
4915 case TBLOCK_BEGIN:
4916 case TBLOCK_INPROGRESS:
4919 case TBLOCK_END:
4921 case TBLOCK_PREPARE:
4922 /* In a transaction, so clean up */
4926 break;
4927 case TBLOCK_ABORT:
4928 case TBLOCK_ABORT_END:
4929
4930 /*
4931 * AbortTransaction is already done, still need Cleanup.
4932 * However, if we failed partway through running ROLLBACK,
4933 * there will be an active portal running that command, which
4934 * we need to shut down before doing CleanupTransaction.
4935 */
4939 break;
4940
4941 /*
4942 * In a subtransaction, so clean it up and abort parent too
4943 */
4944 case TBLOCK_SUBBEGIN:
4946 case TBLOCK_SUBRELEASE:
4947 case TBLOCK_SUBCOMMIT:
4949 case TBLOCK_SUBRESTART:
4952 s = CurrentTransactionState; /* changed by pop */
4953 break;
4954
4955 case TBLOCK_SUBABORT:
4958 /* As above, but AbortSubTransaction already done */
4959 if (s->curTransactionOwner)
4960 {
4961 /* As in TBLOCK_ABORT, might have a live portal to zap */
4966 }
4968 s = CurrentTransactionState; /* changed by pop */
4969 break;
4970 }
4971 } while (s->blockState != TBLOCK_DEFAULT);
4972
4973 /* Should be out of all subxacts now */
4974 Assert(s->parent == NULL);
4975
4976 /*
4977 * Revert to TopMemoryContext, to ensure we exit in a well-defined state
4978 * whether there were any transactions to close or not. (Callers that
4979 * don't intend to exit soon should switch to some other context to avoid
4980 * long-term memory leaks.)
4981 */
4983}
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:979
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:5401
static void CleanupTransaction(void)
Definition: xact.c:3027
@ 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:5237
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:2822
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 4344 of file xact.c.

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

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

4713{
4715 bool save_ExitOnAnyError = ExitOnAnyError;
4716
4717 /*
4718 * Errors within this function are improbable, but if one does happen we
4719 * force a FATAL exit. Callers generally aren't prepared to handle losing
4720 * control, and moreover our transaction state is probably corrupted if we
4721 * fail partway through; so an ordinary ERROR longjmp isn't okay.
4722 */
4723 ExitOnAnyError = true;
4724
4725 /*
4726 * We do not check for parallel mode here. It's permissible to start and
4727 * end "internal" subtransactions while in parallel mode, so long as no
4728 * new XIDs or command IDs are assigned. Enforcement of that occurs in
4729 * AssignTransactionId() and CommandCounterIncrement().
4730 */
4731
4732 switch (s->blockState)
4733 {
4734 case TBLOCK_STARTED:
4735 case TBLOCK_INPROGRESS:
4738 case TBLOCK_END:
4739 case TBLOCK_PREPARE:
4741 /* Normal subtransaction start */
4743 s = CurrentTransactionState; /* changed by push */
4744
4745 /*
4746 * Savepoint names, like the TransactionState block itself, live
4747 * in TopTransactionContext.
4748 */
4749 if (name)
4751 break;
4752
4753 /* These cases are invalid. */
4754 case TBLOCK_DEFAULT:
4755 case TBLOCK_BEGIN:
4756 case TBLOCK_SUBBEGIN:
4757 case TBLOCK_SUBRELEASE:
4758 case TBLOCK_SUBCOMMIT:
4759 case TBLOCK_ABORT:
4760 case TBLOCK_SUBABORT:
4761 case TBLOCK_ABORT_END:
4765 case TBLOCK_SUBRESTART:
4767 elog(FATAL, "BeginInternalSubTransaction: unexpected state %s",
4769 break;
4770 }
4771
4774
4775 ExitOnAnyError = save_ExitOnAnyError;
4776}
#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:1746
MemoryContext TopTransactionContext
Definition: mcxt.c:171
const char * name
static void PushTransaction(void)
Definition: xact.c:5434
void StartTransactionCommand(void)
Definition: xact.c:3077
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5725
void CommitTransactionCommand(void)
Definition: xact.c:3175

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

3943{
3945
3946 switch (s->blockState)
3947 {
3948 /*
3949 * We are not inside a transaction block, so allow one to begin.
3950 */
3951 case TBLOCK_STARTED:
3953 break;
3954
3955 /*
3956 * BEGIN converts an implicit transaction block to a regular one.
3957 * (Note that we allow this even if we've already done some
3958 * commands, which is a bit odd but matches historical practice.)
3959 */
3962 break;
3963
3964 /*
3965 * Already a transaction block in progress.
3966 */
3967 case TBLOCK_INPROGRESS:
3970 case TBLOCK_ABORT:
3971 case TBLOCK_SUBABORT:
3973 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3974 errmsg("there is already a transaction in progress")));
3975 break;
3976
3977 /* These cases are invalid. */
3978 case TBLOCK_DEFAULT:
3979 case TBLOCK_BEGIN:
3980 case TBLOCK_SUBBEGIN:
3981 case TBLOCK_END:
3982 case TBLOCK_SUBRELEASE:
3983 case TBLOCK_SUBCOMMIT:
3984 case TBLOCK_ABORT_END:
3988 case TBLOCK_SUBRESTART:
3990 case TBLOCK_PREPARE:
3991 elog(FATAL, "BeginTransactionBlock: unexpected state %s",
3993 break;
3994 }
3995}
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:678
#define ERROR
Definition: elog.h:39
#define IsParallelWorker()
Definition: parallel.h:60
void SnapshotSetCommandId(CommandId curcid)
Definition: snapmgr.c:488
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(), ATExecSetAccessMethodNoStorage(), ATExecSetCompression(), ATExecSetExpression(), ATExecSetNotNull(), ATExecSetTableSpace(), ATExecSetTableSpaceNoStorage(), ATParseTransformCmd(), ATRewriteTables(), AttachPartitionEnsureIndexes(), AttachPartitionForeignKey(), btadjustmembers(), CommitSubTransaction(), CommitTransactionCommandInternal(), copy_table_data(), create_ctas_internal(), create_toast_table(), CreateFKCheckTrigger(), createForeignKeyActionTriggers(), CreateForeignTable(), CreatePublication(), CreateRole(), CreateSchemaCommand(), CreateTriggerFiringOn(), DefineCollation(), DefineDomain(), DefineIndex(), DefineRelation(), DefineVirtualRelation(), delete_pg_statistic(), deleteOneObject(), DetachPartitionFinalize(), do_analyze_rel(), DropClonedTriggersFromPartition(), dropconstraint_internal(), DropForeignKeyConstraintTriggers(), DropRole(), end_replication_step(), EventTriggerDDLCommandEnd(), EventTriggerDDLCommandStart(), EventTriggerInvoke(), EventTriggerSQLDrop(), EventTriggerTableRewrite(), exec_eval_simple_expr(), exec_execute_message(), exec_parse_message(), exec_simple_query(), ExecGrant_common(), ExecGrant_Largeobject(), ExecGrant_Parameter(), ExecGrant_Relation(), execute_sql_string(), ExplainOnePlan(), finish_heap_swap(), fmgr_sql(), hashadjustmembers(), ImportForeignSchema(), index_build(), index_create(), IndexSetParentIndex(), InitTempTableNamespace(), inv_create(), inv_drop(), inv_truncate(), inv_write(), LogicalRepSyncTableStart(), make_new_heap(), makeConfigurationDependencies(), moveArrayTypeName(), objectNamesToOids(), OperatorShellMake(), OperatorUpd(), pg_import_system_collations(), PortalRunMulti(), ProcedureCreate(), 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 3175 of file xact.c.

3176{
3177 /*
3178 * Repeatedly call CommitTransactionCommandInternal() until all the work
3179 * is done.
3180 */
3182 {
3183 }
3184}
static bool CommitTransactionCommandInternal(void)
Definition: xact.c:3193

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(), run_apply_worker(), shell_check_detail(), stream_abort_internal(), stream_stop_internal(), synchronize_slots(), update_retention_status(), vacuum(), vacuum_rel(), validate_remote_info(), and worker_spi_main().

◆ DefineSavepoint()

void DefineSavepoint ( const char *  name)

Definition at line 4391 of file xact.c.

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

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

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

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

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

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

5531{
5533 Size nxids = 0;
5535
5536 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5537 {
5539 nxids = add_size(nxids, 1);
5540 nxids = add_size(nxids, s->nChildXids);
5541 }
5542
5543 return add_size(size, mul_size(sizeof(TransactionId), nxids));
5544}
uint32 TransactionId
Definition: c.h:661
size_t Size
Definition: c.h:614
Size add_size(Size s1, Size s2)
Definition: shmem.c:494
Size mul_size(Size s1, Size s2)
Definition: shmem.c:511
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(), pgrowlocks(), RegisterRelcacheInvalidation(), RelationFindReplTupleByIndex(), RelationFindReplTupleSeq(), simple_heap_delete(), simple_heap_insert(), simple_heap_update(), simple_table_tuple_delete(), simple_table_tuple_insert(), simple_table_tuple_update(), standard_ExecutorStart(), toast_save_datum(), transientrel_startup(), and UpdateActiveSnapshotCommandId().

◆ GetCurrentFullTransactionId()

FullTransactionId GetCurrentFullTransactionId ( void  )

Definition at line 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:227
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:663
#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 3787 of file xact.c.

3788{
3789 /*
3790 * Return true on same conditions that would make
3791 * PreventInTransactionBlock error out
3792 */
3793 if (IsTransactionBlock())
3794 return true;
3795
3796 if (IsSubTransaction())
3797 return true;
3798
3799 if (!isTopLevel)
3800 return true;
3801
3804 return true;
3805
3806 return false;
3807}
bool IsSubTransaction(void)
Definition: xact.c:5062
bool IsTransactionBlock(void)
Definition: xact.c:4989

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 /* 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:126

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

Referenced by MarkSubxactTopXidLogged(), and XLogRecordAssemble().

◆ IsTransactionBlock()

◆ IsTransactionOrTransactionBlock()

◆ IsTransactionState()

bool IsTransactionState ( void  )

Definition at line 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(), SetMultiXactIdLimit(), SetTransactionIdLimit(), SnapBuildClearExportedSnapshot(), SocketBackend(), stream_stop_internal(), synchronize_slots(), 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:814
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 4010 of file xact.c.

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

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

3667{
3668 /*
3669 * xact block already started?
3670 */
3671 if (IsTransactionBlock())
3672 ereport(ERROR,
3673 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3674 /* translator: %s represents an SQL statement name */
3675 errmsg("%s cannot run inside a transaction block",
3676 stmtType)));
3677
3678 /*
3679 * subtransaction?
3680 */
3681 if (IsSubTransaction())
3682 ereport(ERROR,
3683 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3684 /* translator: %s represents an SQL statement name */
3685 errmsg("%s cannot run inside a subtransaction",
3686 stmtType)));
3687
3688 /*
3689 * inside a function call?
3690 */
3691 if (!isTopLevel)
3692 ereport(ERROR,
3693 (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3694 /* translator: %s represents an SQL statement name */
3695 errmsg("%s cannot be executed from a function", stmtType)));
3696
3697 /* If we got past IsTransactionBlock test, should be in default state */
3700 elog(FATAL, "cannot prevent transaction chain");
3701
3702 /* All okay. Set the flag to make sure the right thing happens later. */
3704}
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 3882 of file xact.c.

3883{
3884 SubXactCallbackItem *item;
3885
3886 item = (SubXactCallbackItem *)
3888 item->callback = callback;
3889 item->arg = arg;
3890 item->next = SubXact_callbacks;
3891 SubXact_callbacks = item;
3892}
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1229
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 3822 of file xact.c.

3823{
3824 XactCallbackItem *item;
3825
3826 item = (XactCallbackItem *)
3828 item->callback = callback;
3829 item->arg = arg;
3830 item->next = Xact_callbacks;
3831 Xact_callbacks = item;
3832}
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 4786 of file xact.c.

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

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

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

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

3735{
3736 CheckTransactionBlock(isTopLevel, true, stmtType);
3737}
static void CheckTransactionBlock(bool isTopLevel, bool throwError, const char *stmtType)
Definition: xact.c:3743

References CheckTransactionBlock().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

◆ RestoreTransactionCharacteristics()

◆ RollbackAndReleaseCurrentSubTransaction()

void RollbackAndReleaseCurrentSubTransaction ( void  )

Definition at line 4814 of file xact.c.

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

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

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

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

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

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

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(), run_apply_worker(), shell_check_detail(), SnapBuildExportSnapshot(), start_xact_command(), synchronize_slots(), 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 5021 of file xact.c.

5022{
5024
5025 switch (s->blockState)
5026 {
5027 case TBLOCK_DEFAULT:
5028 case TBLOCK_STARTED:
5029 return 'I'; /* idle --- not in transaction */
5030 case TBLOCK_BEGIN:
5031 case TBLOCK_SUBBEGIN:
5032 case TBLOCK_INPROGRESS:
5036 case TBLOCK_END:
5037 case TBLOCK_SUBRELEASE:
5038 case TBLOCK_SUBCOMMIT:
5039 case TBLOCK_PREPARE:
5040 return 'T'; /* in transaction */
5041 case TBLOCK_ABORT:
5042 case TBLOCK_SUBABORT:
5043 case TBLOCK_ABORT_END:
5047 case TBLOCK_SUBRESTART:
5049 return 'E'; /* in failed transaction */
5050 }
5051
5052 /* should never get here */
5053 elog(FATAL, "invalid transaction block state: %s",
5055 return 0; /* keep compiler quiet */
5056}

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(), HeapTupleHeaderAdjustCmax(), HeapTupleHeaderGetCmax(), HeapTupleHeaderGetCmin(), HeapTupleHeaderIsOnlyLocked(), HeapTupleSatisfiesDirty(), HeapTupleSatisfiesMVCC(), HeapTupleSatisfiesSelf(), HeapTupleSatisfiesToast(), HeapTupleSatisfiesUpdate(), HeapTupleSatisfiesVacuumHorizon(), MultiXactIdIsRunning(), PredicateLockTID(), SnapBuildWaitSnapshot(), test_lockmode_for_conflict(), TransactionIdIsInProgress(), tts_buffer_is_current_xact_tuple(), and tts_heap_is_current_xact_tuple().

◆ UnregisterSubXactCallback()

void UnregisterSubXactCallback ( SubXactCallback  callback,
void *  arg 
)

Definition at line 3895 of file xact.c.

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

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

◆ UnregisterXactCallback()

void UnregisterXactCallback ( XactCallback  callback,
void *  arg 
)

Definition at line 3835 of file xact.c.

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

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

◆ UserAbortTransactionBlock()

void UserAbortTransactionBlock ( bool  chain)

Definition at line 4222 of file xact.c.

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

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

3729{
3730 CheckTransactionBlock(isTopLevel, false, stmtType);
3731}

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:540
static char * buf
Definition: pg_test_fsync.c:72
#define InvalidOid
Definition: postgres_ext.h:37
void standby_desc_invalidations(StringInfo buf, int nmsgs, SharedInvalidationMessage *msgs, Oid dbId, Oid tsId, bool relcacheInitFileInval)
Definition: standbydesc.c:101
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
TransactionId xtop
Definition: xact.h: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 6381 of file xact.c.

6382{
6383 uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
6384
6385 /* Backup blocks are not used in xact records */
6387
6388 if (info == XLOG_XACT_COMMIT)
6389 {
6390 xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6391 xl_xact_parsed_commit parsed;
6392
6393 ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6394 xact_redo_commit(&parsed, XLogRecGetXid(record),
6395 record->EndRecPtr, XLogRecGetOrigin(record));
6396 }
6397 else if (info == XLOG_XACT_COMMIT_PREPARED)
6398 {
6399 xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
6400 xl_xact_parsed_commit parsed;
6401
6402 ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
6403 xact_redo_commit(&parsed, parsed.twophase_xid,
6404 record->EndRecPtr, XLogRecGetOrigin(record));
6405
6406 /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6407 LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6408 PrepareRedoRemove(parsed.twophase_xid, false);
6409 LWLockRelease(TwoPhaseStateLock);
6410 }
6411 else if (info == XLOG_XACT_ABORT)
6412 {
6413 xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6414 xl_xact_parsed_abort parsed;
6415
6416 ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6417 xact_redo_abort(&parsed, XLogRecGetXid(record),
6418 record->EndRecPtr, XLogRecGetOrigin(record));
6419 }
6420 else if (info == XLOG_XACT_ABORT_PREPARED)
6421 {
6422 xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
6423 xl_xact_parsed_abort parsed;
6424
6425 ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
6426 xact_redo_abort(&parsed, parsed.twophase_xid,
6427 record->EndRecPtr, XLogRecGetOrigin(record));
6428
6429 /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6430 LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6431 PrepareRedoRemove(parsed.twophase_xid, false);
6432 LWLockRelease(TwoPhaseStateLock);
6433 }
6434 else if (info == XLOG_XACT_PREPARE)
6435 {
6436 /*
6437 * Store xid and start/end pointers of the WAL record in TwoPhaseState
6438 * gxact entry.
6439 */
6440 LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
6442 XLogRecGetData(record),
6443 record->ReadRecPtr,
6444 record->EndRecPtr,
6445 XLogRecGetOrigin(record));
6446 LWLockRelease(TwoPhaseStateLock);
6447 }
6448 else if (info == XLOG_XACT_ASSIGNMENT)
6449 {
6451
6454 xlrec->nsubxacts, xlrec->xsub);
6455 }
6456 else if (info == XLOG_XACT_INVALIDATIONS)
6457 {
6458 /*
6459 * XXX we do ignore this for now, what matters are invalidations
6460 * written into the commit record.
6461 */
6462 }
6463 else
6464 elog(PANIC, "xact_redo: unknown op code %u", info);
6465}
#define PANIC
Definition: elog.h:42
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1174
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1894
@ LW_EXCLUSIVE
Definition: lwlock.h:112
void ProcArrayApplyXidAssignment(TransactionId topxid, int nsubxids, TransactionId *subxids)
Definition: procarray.c:1318
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:6148
static void xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:6302
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 5808 of file xact.c.

5809{
5811
5812 if (s->nChildXids == 0)
5813 *ptr = NULL;
5814 else
5815 *ptr = s->childXids;
5816
5817 return s->nChildXids;
5818}

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

6010{
6011 xl_xact_abort xlrec;
6012 xl_xact_xinfo xl_xinfo;
6013 xl_xact_subxacts xl_subxacts;
6014 xl_xact_relfilelocators xl_relfilelocators;
6015 xl_xact_stats_items xl_dropped_stats;
6016 xl_xact_twophase xl_twophase;
6017 xl_xact_dbinfo xl_dbinfo;
6018 xl_xact_origin xl_origin;
6019
6020 uint8 info;
6021
6023
6024 xl_xinfo.xinfo = 0;
6025
6026 /* decide between a plain and 2pc abort */
6027 if (!TransactionIdIsValid(twophase_xid))
6028 info = XLOG_XACT_ABORT;
6029 else
6031
6032
6033 /* First figure out and collect all the information needed */
6034
6035 xlrec.xact_time = abort_time;
6036
6038 xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
6039
6040 if (nsubxacts > 0)
6041 {
6042 xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
6043 xl_subxacts.nsubxacts = nsubxacts;
6044 }
6045
6046 if (nrels > 0)
6047 {
6049 xl_relfilelocators.nrels = nrels;
6050 info |= XLR_SPECIAL_REL_UPDATE;
6051 }
6052
6053 if (ndroppedstats > 0)
6054 {
6056 xl_dropped_stats.nitems = ndroppedstats;
6057 }
6058
6059 if (TransactionIdIsValid(twophase_xid))
6060 {
6061 xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
6062 xl_twophase.xid = twophase_xid;
6063 Assert(twophase_gid != NULL);
6064
6066 xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
6067 }
6068
6069 if (TransactionIdIsValid(twophase_xid) && XLogLogicalInfoActive())
6070 {
6071 xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
6072 xl_dbinfo.dbId = MyDatabaseId;
6073 xl_dbinfo.tsId = MyDatabaseTableSpace;
6074 }
6075
6076 /*
6077 * Dump transaction origin information. We need this during recovery to
6078 * update the replication origin progress.
6079 */
6081 {
6082 xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
6083
6086 }
6087
6088 if (xl_xinfo.xinfo != 0)
6089 info |= XLOG_XACT_HAS_INFO;
6090
6091 /* Then include all the collected data into the abort record. */
6092
6094
6096
6097 if (xl_xinfo.xinfo != 0)
6098 XLogRegisterData(&xl_xinfo, sizeof(xl_xinfo));
6099
6100 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
6101 XLogRegisterData(&xl_dbinfo, sizeof(xl_dbinfo));
6102
6103 if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
6104 {
6105 XLogRegisterData(&xl_subxacts,
6107 XLogRegisterData(subxacts,
6108 nsubxacts * sizeof(TransactionId));
6109 }
6110
6112 {
6113 XLogRegisterData(&xl_relfilelocators,
6115 XLogRegisterData(rels,
6116 nrels * sizeof(RelFileLocator));
6117 }
6118
6119 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
6120 {
6121 XLogRegisterData(&xl_dropped_stats,
6123 XLogRegisterData(droppedstats,
6124 ndroppedstats * sizeof(xl_xact_stats_item));
6125 }
6126
6127 if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
6128 {
6129 XLogRegisterData(&xl_twophase, sizeof(xl_xact_twophase));
6130 if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
6131 XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
6132 }
6133
6134 if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
6135 XLogRegisterData(&xl_origin, sizeof(xl_xact_origin));
6136
6137 /* Include the replication origin */
6139
6140 return XLogInsert(RM_XACT_ID, info);
6141}
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:154
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 5832 of file xact.c.

5840{
5841 xl_xact_commit xlrec;
5842 xl_xact_xinfo xl_xinfo;
5843 xl_xact_dbinfo xl_dbinfo;
5844 xl_xact_subxacts xl_subxacts;
5845 xl_xact_relfilelocators xl_relfilelocators;
5846 xl_xact_stats_items xl_dropped_stats;
5847 xl_xact_invals xl_invals;
5848 xl_xact_twophase xl_twophase;
5849 xl_xact_origin xl_origin;
5850 uint8 info;
5851
5853
5854 xl_xinfo.xinfo = 0;
5855
5856 /* decide between a plain and 2pc commit */
5857 if (!TransactionIdIsValid(twophase_xid))
5858 info = XLOG_XACT_COMMIT;
5859 else
5861
5862 /* First figure out and collect all the information needed */
5863
5864 xlrec.xact_time = commit_time;
5865
5866 if (relcacheInval)
5868 if (forceSyncCommit)
5871 xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5872
5873 /*
5874 * Check if the caller would like to ask standbys for immediate feedback
5875 * once this commit is applied.
5876 */
5879
5880 /*
5881 * Relcache invalidations requires information about the current database
5882 * and so does logical decoding.
5883 */
5884 if (nmsgs > 0 || XLogLogicalInfoActive())
5885 {
5886 xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5887 xl_dbinfo.dbId = MyDatabaseId;
5888 xl_dbinfo.tsId = MyDatabaseTableSpace;
5889 }
5890
5891 if (nsubxacts > 0)
5892 {
5893 xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5894 xl_subxacts.nsubxacts = nsubxacts;
5895 }
5896
5897 if (nrels > 0)
5898 {
5900 xl_relfilelocators.nrels = nrels;
5901 info |= XLR_SPECIAL_REL_UPDATE;
5902 }
5903
5904 if (ndroppedstats > 0)
5905 {
5907 xl_dropped_stats.nitems = ndroppedstats;
5908 }
5909
5910 if (nmsgs > 0)
5911 {
5912 xl_xinfo.xinfo |= XACT_XINFO_HAS_INVALS;
5913 xl_invals.nmsgs = nmsgs;
5914 }
5915
5916 if (TransactionIdIsValid(twophase_xid))
5917 {
5918 xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5919 xl_twophase.xid = twophase_xid;
5920 Assert(twophase_gid != NULL);
5921
5923 xl_xinfo.xinfo |= XACT_XINFO_HAS_GID;
5924 }
5925
5926 /* dump transaction origin information */
5928 {
5929 xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
5930
5933 }
5934
5935 if (xl_xinfo.xinfo != 0)
5936 info |= XLOG_XACT_HAS_INFO;
5937
5938 /* Then include all the collected data into the commit record. */
5939
5941
5942 XLogRegisterData(&xlrec, sizeof(xl_xact_commit));
5943
5944 if (xl_xinfo.xinfo != 0)
5945 XLogRegisterData(&xl_xinfo.xinfo, sizeof(xl_xinfo.xinfo));
5946
5947 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5948 XLogRegisterData(&xl_dbinfo, sizeof(xl_dbinfo));
5949
5950 if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5951 {
5952 XLogRegisterData(&xl_subxacts,
5954 XLogRegisterData(subxacts,
5955 nsubxacts * sizeof(TransactionId));
5956 }
5957
5959 {
5960 XLogRegisterData(&xl_relfilelocators,
5962 XLogRegisterData(rels,
5963 nrels * sizeof(RelFileLocator));
5964 }
5965
5966 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DROPPED_STATS)
5967 {
5968 XLogRegisterData(&xl_dropped_stats,
5970 XLogRegisterData(droppedstats,
5971 ndroppedstats * sizeof(xl_xact_stats_item));
5972 }
5973
5974 if (xl_xinfo.xinfo & XACT_XINFO_HAS_INVALS)
5975 {
5977 XLogRegisterData(msgs,
5978 nmsgs * sizeof(SharedInvalidationMessage));
5979 }
5980
5981 if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5982 {
5983 XLogRegisterData(&xl_twophase, sizeof(xl_xact_twophase));
5984 if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
5985 XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
5986 }
5987
5988 if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5989 XLogRegisterData(&xl_origin, sizeof(xl_xact_origin));
5990
5991 /* we allow filtering by xacts */
5993
5994 return XLogInsert(RM_XACT_ID, info);
5995}
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