PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 charxact_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.

220{
221 TransactionId xtop; /* assigned XID's top-level XID */
222 int nsubxacts; /* number of subtransaction XIDs */
223 TransactionId xsub[FLEXIBLE_ARRAY_MEMBER]; /* assigned subxids */
225
226#define MinSizeOfXactAssignment offsetof(xl_xact_assignment, xsub)
227
228/*
229 * Commit and abort records can contain a lot of information. But a large
230 * portion of the records won't need all possible pieces of information. So we
231 * only include what's needed.
232 *
233 * A minimal commit/abort record only consists of a xl_xact_commit/abort
234 * struct. The presence of additional information is indicated by bits set in
235 * 'xl_xact_xinfo->xinfo'. The presence of the xinfo field itself is signaled
236 * by a set XLOG_XACT_HAS_INFO bit in the xl_info field.
237 *
238 * NB: All the individual data chunks should be sized to multiples of
239 * sizeof(int) and only require int32 alignment. If they require bigger
240 * alignment, they need to be copied upon reading.
241 */
242
243/* sub-records for commit/abort */
244
245typedef struct xl_xact_xinfo
246{
247 /*
248 * Even though we right now only require two bytes of space in xinfo we
249 * use four so following records don't have to care about alignment.
250 * Commit records can be large, so copying large portions isn't
251 * attractive.
252 */
255
256typedef struct xl_xact_dbinfo
257{
258 Oid dbId; /* MyDatabaseId */
259 Oid tsId; /* MyDatabaseTableSpace */
261
262typedef struct xl_xact_subxacts
263{
264 int nsubxacts; /* number of subtransaction XIDs */
267#define MinSizeOfXactSubxacts offsetof(xl_xact_subxacts, subxacts)
268
269typedef struct xl_xact_relfilelocators
270{
271 int nrels; /* number of relations */
274#define MinSizeOfXactRelfileLocators offsetof(xl_xact_relfilelocators, xlocators)
275
276/*
277 * A transactionally dropped statistics entry.
278 *
279 * Declared here rather than pgstat.h because pgstat.h can't be included from
280 * frontend code, but the WAL format needs to be readable by frontend
281 * programs.
282 */
283typedef struct xl_xact_stats_item
284{
285 int kind;
286 Oid dboid;
287
288 /*
289 * This stores the value of PgStat_HashKey.objid as two uint32 as all the
290 * fields of xl_xact_xinfo should be multiples of size(int).
291 */
295
296typedef struct xl_xact_stats_items
297{
298 int nitems;
301#define MinSizeOfXactStatsItems offsetof(xl_xact_stats_items, items)
302
303typedef struct xl_xact_invals
304{
305 int nmsgs; /* number of shared inval msgs */
308#define MinSizeOfXactInvals offsetof(xl_xact_invals, msgs)
309
310typedef struct xl_xact_twophase
311{
314
315typedef struct xl_xact_origin
316{
320
321typedef struct xl_xact_commit
322{
323 TimestampTz xact_time; /* time of commit */
324
325 /* xl_xact_xinfo follows if XLOG_XACT_HAS_INFO */
326 /* xl_xact_dbinfo follows if XINFO_HAS_DBINFO */
327 /* xl_xact_subxacts follows if XINFO_HAS_SUBXACT */
328 /* xl_xact_relfilelocators follows if XINFO_HAS_RELFILELOCATORS */
329 /* xl_xact_stats_items follows if XINFO_HAS_DROPPED_STATS */
330 /* xl_xact_invals follows if XINFO_HAS_INVALS */
331 /* xl_xact_twophase follows if XINFO_HAS_TWOPHASE */
332 /* twophase_gid follows if XINFO_HAS_GID. As a null-terminated string. */
333 /* xl_xact_origin follows if XINFO_HAS_ORIGIN, stored unaligned! */
335#define MinSizeOfXactCommit (offsetof(xl_xact_commit, xact_time) + sizeof(TimestampTz))
336
337typedef struct xl_xact_abort
338{
339 TimestampTz xact_time; /* time of abort */
340
341 /* xl_xact_xinfo follows if XLOG_XACT_HAS_INFO */
342 /* xl_xact_dbinfo follows if XINFO_HAS_DBINFO */
343 /* xl_xact_subxacts follows if XINFO_HAS_SUBXACT */
344 /* xl_xact_relfilelocators follows if XINFO_HAS_RELFILELOCATORS */
345 /* xl_xact_stats_items follows if XINFO_HAS_DROPPED_STATS */
346 /* No invalidation messages needed. */
347 /* xl_xact_twophase follows if XINFO_HAS_TWOPHASE */
348 /* twophase_gid follows if XINFO_HAS_GID. As a null-terminated string. */
349 /* xl_xact_origin follows if XINFO_HAS_ORIGIN, stored unaligned! */
351#define MinSizeOfXactAbort sizeof(xl_xact_abort)
352
353typedef struct xl_xact_prepare
354{
355 uint32 magic; /* format identifier */
356 uint32 total_len; /* actual file length */
357 TransactionId xid; /* original transaction XID */
358 Oid database; /* OID of database it was in */
359 TimestampTz prepared_at; /* time of preparation */
360 Oid owner; /* user running the transaction */
361 int32 nsubxacts; /* number of following subxact XIDs */
362 int32 ncommitrels; /* number of delete-on-commit rels */
363 int32 nabortrels; /* number of delete-on-abort rels */
364 int32 ncommitstats; /* number of stats to drop on commit */
365 int32 nabortstats; /* number of stats to drop on abort */
366 int32 ninvalmsgs; /* number of cache invalidation messages */
367 bool initfileinval; /* does relcache init file need invalidation? */
368 uint16 gidlen; /* length of the GID - GID follows the header */
369 XLogRecPtr origin_lsn; /* lsn of this record at origin node */
370 TimestampTz origin_timestamp; /* time of prepare at origin node */
372
373/*
374 * Commit/Abort records in the above form are a bit verbose to parse, so
375 * there's a deconstructed versions generated by ParseCommit/AbortRecord() for
376 * easier consumption.
377 */
378typedef struct xl_xact_parsed_commit
379{
382
383 Oid dbId; /* MyDatabaseId */
384 Oid tsId; /* MyDatabaseTableSpace */
385
386 int nsubxacts;
388
389 int nrels;
391
392 int nstats;
394
395 int nmsgs;
397
398 TransactionId twophase_xid; /* only for 2PC */
399 char twophase_gid[GIDSIZE]; /* only for 2PC */
400 int nabortrels; /* only for 2PC */
401 RelFileLocator *abortlocators; /* only for 2PC */
402 int nabortstats; /* only for 2PC */
403 xl_xact_stats_item *abortstats; /* only for 2PC */
404
408
410
411typedef struct xl_xact_parsed_abort
412{
415
416 Oid dbId; /* MyDatabaseId */
417 Oid tsId; /* MyDatabaseTableSpace */
418
419 int nsubxacts;
421
422 int nrels;
424
425 int nstats;
427
428 TransactionId twophase_xid; /* only for 2PC */
429 char twophase_gid[GIDSIZE]; /* only for 2PC */
430
434
435
436/* ----------------
437 * extern definitions
438 * ----------------
439 */
440extern bool IsTransactionState(void);
441extern bool IsAbortedTransactionBlockState(void);
453extern bool SubTransactionIsActive(SubTransactionId subxid);
454extern CommandId GetCurrentCommandId(bool used);
455extern void SetParallelStartTimestamps(TimestampTz xact_ts, TimestampTz stmt_ts);
459extern void SetCurrentStatementStartTimestamp(void);
460extern int GetCurrentTransactionNestLevel(void);
462extern void CommandCounterIncrement(void);
463extern void ForceSyncCommit(void);
464extern void StartTransactionCommand(void);
467extern void CommitTransactionCommand(void);
468extern void AbortCurrentTransaction(void);
469extern void BeginTransactionBlock(void);
470extern bool EndTransactionBlock(bool chain);
471extern bool PrepareTransactionBlock(const char *gid);
472extern void UserAbortTransactionBlock(bool chain);
473extern void BeginImplicitTransactionBlock(void);
474extern void EndImplicitTransactionBlock(void);
475extern void ReleaseSavepoint(const char *name);
476extern void DefineSavepoint(const char *name);
477extern void RollbackToSavepoint(const char *name);
478extern void BeginInternalSubTransaction(const char *name);
479extern void ReleaseCurrentSubTransaction(void);
481extern bool IsSubTransaction(void);
485extern void EndParallelWorkerTransaction(void);
486extern bool IsTransactionBlock(void);
487extern bool IsTransactionOrTransactionBlock(void);
488extern char TransactionBlockStatusCode(void);
489extern void AbortOutOfAnyTransaction(void);
490extern void PreventInTransactionBlock(bool isTopLevel, const char *stmtType);
491extern void RequireTransactionBlock(bool isTopLevel, const char *stmtType);
492extern void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType);
493extern bool IsInTransactionBlock(bool isTopLevel);
498
499extern bool IsSubxactTopXidLogPending(void);
500extern void MarkSubxactTopXidLogged(void);
501
503
505 int nsubxacts, TransactionId *subxacts,
506 int nrels, RelFileLocator *rels,
507 int ndroppedstats,
509 int nmsgs, SharedInvalidationMessage *msgs,
510 bool relcacheInval,
511 int xactflags,
512 TransactionId twophase_xid,
513 const char *twophase_gid);
514
516 int nsubxacts, TransactionId *subxacts,
517 int nrels, RelFileLocator *rels,
518 int ndroppedstats,
520 int xactflags, TransactionId twophase_xid,
521 const char *twophase_gid);
522extern void xact_redo(XLogReaderState *record);
523
524/* xactdesc.c */
525extern void xact_desc(StringInfo buf, XLogReaderState *record);
526extern const char *xact_identify(uint8 info);
527
528/* also in xactdesc.c, so they can be shared between front/backend code */
532
533extern void EnterParallelMode(void);
534extern void ExitParallelMode(void);
535extern bool IsInParallelMode(void);
536
537#endif /* XACT_H */
uint8_t uint8
Definition c.h:586
uint32 SubTransactionId
Definition c.h:712
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:522
int32_t int32
Definition c.h:584
uint16_t uint16
Definition c.h:587
uint32_t uint32
Definition c.h:588
uint32 CommandId
Definition c.h:722
uint32 TransactionId
Definition c.h:708
size_t Size
Definition c.h:661
int64 TimestampTz
Definition timestamp.h:39
Datum arg
Definition elog.c:1322
static char buf[DEFAULT_XLOG_SEG_SIZE]
unsigned int Oid
static int fb(int x)
TimestampTz xact_time
Definition xact.h:339
TimestampTz xact_time
Definition xact.h:323
SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER]
Definition xact.h:306
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
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
RelFileLocator * abortlocators
Definition xact.h:401
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
xl_xact_stats_item * abortstats
Definition xact.h:403
SharedInvalidationMessage * msgs
Definition xact.h:396
TimestampTz prepared_at
Definition xact.h:359
int32 nabortrels
Definition xact.h:363
int32 ninvalmsgs
Definition xact.h:366
bool initfileinval
Definition xact.h:367
int32 ncommitstats
Definition xact.h:364
TimestampTz origin_timestamp
Definition xact.h:370
uint16 gidlen
Definition xact.h:368
uint32 total_len
Definition xact.h:356
int32 nabortstats
Definition xact.h:365
XLogRecPtr origin_lsn
Definition xact.h:369
uint32 magic
Definition xact.h:355
int32 ncommitrels
Definition xact.h:362
TransactionId xid
Definition xact.h:357
int32 nsubxacts
Definition xact.h:361
RelFileLocator xlocators[FLEXIBLE_ARRAY_MEMBER]
Definition xact.h:272
uint32 objid_lo
Definition xact.h:292
uint32 objid_hi
Definition xact.h:293
xl_xact_stats_item items[FLEXIBLE_ARRAY_MEMBER]
Definition xact.h:299
TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER]
Definition xact.h:265
TransactionId xid
Definition xact.h:312
uint32 xinfo
Definition xact.h:253
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
const char * name
bool IsTransactionOrTransactionBlock(void)
Definition xact.c:5012
void SerializeTransactionState(Size maxsize, char *start_address)
Definition xact.c:5563
void ExitParallelMode(void)
Definition xact.c:1066
const char * xact_identify(uint8 info)
Definition xactdesc.c:487
void SaveTransactionCharacteristics(SavedTransactionCharacteristics *s)
Definition xact.c:3158
void BeginInternalSubTransaction(const char *name)
Definition xact.c:4717
FullTransactionId GetCurrentFullTransactionId(void)
Definition xact.c:514
void RestoreTransactionCharacteristics(const SavedTransactionCharacteristics *s)
Definition xact.c:3166
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition xact.c:3733
SubTransactionId GetCurrentSubTransactionId(void)
Definition xact.c:793
void(* SubXactCallback)(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg)
Definition xact.h:149
void UserAbortTransactionBlock(bool chain)
Definition xact.c:4227
bool IsInTransactionBlock(bool isTopLevel)
Definition xact.c:3792
bool PrepareTransactionBlock(const char *gid)
Definition xact.c:4015
int GetCurrentTransactionNestLevel(void)
Definition xact.c:931
void xact_redo(XLogReaderState *record)
Definition xact.c:6386
xl_xact_parsed_commit xl_xact_parsed_prepare
Definition xact.h:409
TransactionId GetTopTransactionId(void)
Definition xact.c:428
void EnterParallelMode(void)
Definition xact.c:1053
TransactionId GetStableLatestTransactionId(void)
Definition xact.c:609
void UnregisterSubXactCallback(SubXactCallback callback, void *arg)
Definition xact.c:3900
void BeginImplicitTransactionBlock(void)
Definition xact.c:4349
void(* XactCallback)(XactEvent event, void *arg)
Definition xact.h:139
void RequireTransactionBlock(bool isTopLevel, const char *stmtType)
Definition xact.c:3739
void DefineSavepoint(const char *name)
Definition xact.c:4396
void UnregisterXactCallback(XactCallback callback, void *arg)
Definition xact.c:3840
bool IsTransactionState(void)
Definition xact.c:389
void CommandCounterIncrement(void)
Definition xact.c:1102
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition xact.c:3670
Size EstimateTransactionStateSpace(void)
Definition xact.c:5535
TransactionId GetTopTransactionIdIfAny(void)
Definition xact.c:443
#define GIDSIZE
Definition xact.h:31
char TransactionBlockStatusCode(void)
Definition xact.c:5026
void RollbackAndReleaseCurrentSubTransaction(void)
Definition xact.c:4819
FullTransactionId GetCurrentFullTransactionIdIfAny(void)
Definition xact.c:532
void StartTransactionCommand(void)
Definition xact.c:3081
bool IsAbortedTransactionBlockState(void)
Definition xact.c:409
void ReleaseCurrentSubTransaction(void)
Definition xact.c:4791
void EndImplicitTransactionBlock(void)
Definition xact.c:4374
void StartParallelWorkerTransaction(char *tstatespace)
Definition xact.c:5634
void SetParallelStartTimestamps(TimestampTz xact_ts, TimestampTz stmt_ts)
Definition xact.c:861
void ReleaseSavepoint(const char *name)
Definition xact.c:4481
FullTransactionId GetTopFullTransactionId(void)
Definition xact.c:485
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 xact.c:5837
void ForceSyncCommit(void)
Definition xact.c:1154
bool IsSubTransaction(void)
Definition xact.c:5067
void MarkSubxactTopXidLogged(void)
Definition xact.c:593
void SetCurrentStatementStartTimestamp(void)
Definition xact.c:916
bool TransactionIdIsCurrentTransactionId(TransactionId xid)
Definition xact.c:943
bool IsTransactionBlock(void)
Definition xact.c:4994
bool IsInParallelMode(void)
Definition xact.c:1091
int xactGetCommittedChildren(TransactionId **ptr)
Definition xact.c:5813
TransactionId GetCurrentTransactionIdIfAny(void)
Definition xact.c:473
void BeginTransactionBlock(void)
Definition xact.c:3947
TimestampTz GetCurrentStatementStartTimestamp(void)
Definition xact.c:881
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition xact.c:872
void EndParallelWorkerTransaction(void)
Definition xact.c:5659
void RegisterXactCallback(XactCallback callback, void *arg)
Definition xact.c:3827
void CommitTransactionCommand(void)
Definition xact.c:3179
void RollbackToSavepoint(const char *name)
Definition xact.c:4590
bool SubTransactionIsActive(SubTransactionId subxid)
Definition xact.c:807
void RegisterSubXactCallback(SubXactCallback callback, void *arg)
Definition xact.c:3887
FullTransactionId GetTopFullTransactionIdIfAny(void)
Definition xact.c:501
TransactionId GetCurrentTransactionId(void)
Definition xact.c:456
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
void xact_desc(StringInfo buf, XLogReaderState *record)
Definition xactdesc.c:439
bool EndTransactionBlock(bool chain)
Definition xact.c:4067
bool IsSubxactTopXidLogPending(void)
Definition xact.c:561
void ParsePrepareRecord(uint8 info, xl_xact_prepare *xlrec, xl_xact_parsed_prepare *parsed)
Definition xactdesc.c:239
void AbortOutOfAnyTransaction(void)
Definition xact.c:4885
void AbortCurrentTransaction(void)
Definition xact.c:3473
TimestampTz GetCurrentTransactionStopTimestamp(void)
Definition xact.c:893
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 xact.c:6009
void MarkCurrentTransactionIdLoggedIfAny(void)
Definition xact.c:543
CommandId GetCurrentCommandId(bool used)
Definition xact.c:831
uint64 XLogRecPtr
Definition xlogdefs.h:21

◆ 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

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

◆ 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

◆ xl_xact_prepare

◆ xl_xact_relfilelocators

◆ xl_xact_stats_item

◆ xl_xact_stats_items

◆ xl_xact_subxacts

◆ xl_xact_twophase

◆ 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

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  )
extern

Definition at line 3473 of file xact.c.

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

References AbortCurrentTransactionInternal().

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

◆ AbortOutOfAnyTransaction()

void AbortOutOfAnyTransaction ( void  )
extern

Definition at line 4885 of file xact.c.

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

References AbortSubTransaction(), AbortTransaction(), Assert, AtAbort_Memory(), AtAbort_Portals(), AtSubAbort_Portals(), TransactionStateData::blockState, CleanupSubTransaction(), CleanupTransaction(), CurrentTransactionState, TransactionStateData::curTransactionOwner, fb(), 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  )
extern

Definition at line 4349 of file xact.c.

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

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)
extern

Definition at line 4717 of file xact.c.

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

References TransactionStateData::blockState, BlockStateAsString(), CommitTransactionCommand(), CurrentTransactionState, elog, ExitOnAnyError, FATAL, fb(), 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  )
extern

Definition at line 3947 of file xact.c.

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

References TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg, FATAL, fb(), 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  )
extern

Definition at line 1102 of file xact.c.

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

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

Referenced by _SPI_execute_plan(), acquire_inherited_sample_rows(), addFkConstraint(), AddRoleMems(), AlterPublicationOptions(), AlterRole(), ATAddCheckNNConstraint(), ATExecAddColumn(), ATExecAlterColumnType(), ATExecAlterConstrInheritability(), ATExecCmd(), ATExecDropColumn(), ATExecDropExpression(), ATExecDropIdentity(), ATExecMergePartitions(), ATExecSetAccessMethodNoStorage(), ATExecSetCompression(), ATExecSetExpression(), ATExecSetNotNull(), ATExecSetTableSpace(), ATExecSetTableSpaceNoStorage(), ATExecSplitPartition(), ATParseTransformCmd(), ATRewriteTables(), AttachPartitionEnsureIndexes(), AttachPartitionForeignKey(), btadjustmembers(), CommitSubTransaction(), CommitTransactionCommandInternal(), compute_return_type(), copy_table_data(), create_ctas_internal(), create_toast_table(), CreateFKCheckTrigger(), createForeignKeyActionTriggers(), CreateForeignTable(), createPartitionTable(), CreatePublication(), CreateRole(), CreateSchemaCommand(), createTableConstraints(), CreateTriggerFiringOn(), DefineCollation(), DefineDomain(), DefineIndex(), DefineRange(), DefineRelation(), DefineVirtualRelation(), delete_pg_statistic(), delete_pg_statistic_ext_data(), deleteOneObject(), DetachPartitionFinalize(), do_analyze_rel(), DropClonedTriggersFromPartition(), dropconstraint_internal(), DropForeignKeyConstraintTriggers(), DropRole(), end_replication_step(), EventTriggerDDLCommandEnd(), EventTriggerDDLCommandStart(), EventTriggerInvoke(), EventTriggerSQLDrop(), EventTriggerTableRewrite(), exec_eval_simple_expr(), exec_execute_message(), exec_parse_message(), exec_simple_query(), ExecGrant_common(), ExecGrant_Largeobject(), ExecGrant_Parameter(), ExecGrant_Relation(), execute_sql_string(), ExplainOnePlan(), finish_heap_swap(), fmgr_sql(), hashadjustmembers(), ImportForeignSchema(), index_build(), index_create(), IndexSetParentIndex(), InitTempTableNamespace(), inv_create(), inv_drop(), inv_truncate(), inv_write(), LogicalRepSyncTableStart(), make_new_heap(), makeConfigurationDependencies(), moveArrayTypeName(), objectNamesToOids(), OperatorShellMake(), OperatorUpd(), pg_import_system_collations(), PortalRunMulti(), ProcedureCreate(), process_single_relation(), 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(), upsert_pg_statistic_ext_data(), vacuum(), and validatePartitionedIndex().

◆ CommitTransactionCommand()

void CommitTransactionCommand ( void  )
extern

Definition at line 3179 of file xact.c.

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

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(), copy_sequences(), DefineIndex(), DisableSubscriptionAndExit(), do_autovacuum(), EventTriggerOnLogin(), exec_replication_command(), ExecRepack(), 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(), process_single_relation(), ProcessCatchupInterrupt(), ProcessIncomingNotify(), ProcessSequencesForSync(), ProcessSyncingTablesForApply(), ProcessSyncingTablesForSync(), ReindexMultipleInternal(), ReindexRelationConcurrently(), RemoveTempRelationsCallback(), ReplSlotSyncWorkerMain(), run_apply_worker(), shell_check_detail(), stream_abort_internal(), stream_stop_internal(), update_retention_status(), vacuum(), vacuum_rel(), validate_remote_info(), and worker_spi_main().

◆ DefineSavepoint()

void DefineSavepoint ( const char name)
extern

Definition at line 4396 of file xact.c.

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

References TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg, ERROR, FATAL, fb(), 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  )
extern

Definition at line 4374 of file xact.c.

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

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

Referenced by exec_simple_query(), and PostgresMain().

◆ EndParallelWorkerTransaction()

void EndParallelWorkerTransaction ( void  )
extern

◆ EndTransactionBlock()

bool EndTransactionBlock ( bool  chain)
extern

Definition at line 4067 of file xact.c.

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

References Assert, TransactionStateData::blockState, BlockStateAsString(), TransactionStateData::chain, CurrentTransactionState, elog, ereport, errcode(), errmsg, ERROR, FATAL, fb(), 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  )
extern

Definition at line 5535 of file xact.c.

5536{
5538 Size nxids = 0;
5540
5541 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5542 {
5544 nxids = add_size(nxids, 1);
5546 }
5547
5548 return add_size(size, mul_size(sizeof(TransactionId), nxids));
5549}
Size add_size(Size s1, Size s2)
Definition shmem.c:482
Size mul_size(Size s1, Size s2)
Definition shmem.c:497
FullTransactionId fullTransactionId
Definition xact.c:197
#define FullTransactionIdIsValid(x)
Definition transam.h:55
#define SerializedTransactionStateHeaderSize
Definition xact.c:241

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

Referenced by InitializeParallelDSM().

◆ ExitParallelMode()

◆ ForceSyncCommit()

void ForceSyncCommit ( void  )
extern

Definition at line 1154 of file xact.c.

1155{
1156 forceSyncCommit = true;
1157}
static bool forceSyncCommit
Definition xact.c:295

References forceSyncCommit.

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

◆ GetCurrentCommandId()

CommandId GetCurrentCommandId ( bool  used)
extern

Definition at line 831 of file xact.c.

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

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

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

◆ GetCurrentFullTransactionId()

FullTransactionId GetCurrentFullTransactionId ( void  )
extern

Definition at line 514 of file xact.c.

515{
517
520 return s->fullTransactionId;
521}
static void AssignTransactionId(TransactionState s)
Definition xact.c:637

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

Referenced by PrepareTransaction().

◆ GetCurrentFullTransactionIdIfAny()

FullTransactionId GetCurrentFullTransactionIdIfAny ( void  )
extern

Definition at line 532 of file xact.c.

References CurrentTransactionState, and TransactionStateData::fullTransactionId.

◆ GetCurrentStatementStartTimestamp()

TimestampTz GetCurrentStatementStartTimestamp ( void  )
extern

Definition at line 881 of file xact.c.

882{
883 return stmtStartTimestamp;
884}
static TimestampTz stmtStartTimestamp
Definition xact.c:283

References stmtStartTimestamp.

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

◆ GetCurrentSubTransactionId()

◆ GetCurrentTransactionId()

◆ GetCurrentTransactionIdIfAny()

◆ GetCurrentTransactionNestLevel()

◆ GetCurrentTransactionStartTimestamp()

TimestampTz GetCurrentTransactionStartTimestamp ( void  )
extern

◆ GetCurrentTransactionStopTimestamp()

TimestampTz GetCurrentTransactionStopTimestamp ( void  )
extern

Definition at line 893 of file xact.c.

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

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  )
extern

Definition at line 609 of file xact.c.

610{
613
614 if (lxid != MyProc->vxid.lxid)
615 {
616 lxid = MyProc->vxid.lxid;
620 }
621
623
624 return stablexid;
625}
uint32 LocalTransactionId
Definition c.h:710
#define InvalidLocalTransactionId
Definition lock.h:67
PGPROC * MyProc
Definition proc.c:68
LocalTransactionId lxid
Definition proc.h:223
struct PGPROC::@133 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:443

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

Referenced by xid_age().

◆ GetTopFullTransactionId()

FullTransactionId GetTopFullTransactionId ( void  )
extern

Definition at line 485 of file xact.c.

486{
490}
static TransactionStateData TopTransactionStateData
Definition xact.c:249
static FullTransactionId XactTopFullTransactionId
Definition xact.c:127

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

Referenced by pg_current_xact_id().

◆ GetTopFullTransactionIdIfAny()

FullTransactionId GetTopFullTransactionIdIfAny ( void  )
extern

Definition at line 501 of file xact.c.

502{
504}

References XactTopFullTransactionId.

Referenced by pg_current_xact_id_if_assigned().

◆ GetTopTransactionId()

◆ GetTopTransactionIdIfAny()

◆ IsAbortedTransactionBlockState()

◆ IsInParallelMode()

◆ IsInTransactionBlock()

bool IsInTransactionBlock ( bool  isTopLevel)
extern

Definition at line 3792 of file xact.c.

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

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

Referenced by vacuum().

◆ IsSubTransaction()

◆ IsSubxactTopXidLogPending()

bool IsSubxactTopXidLogPending ( void  )
extern

Definition at line 561 of file xact.c.

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

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

Referenced by MarkSubxactTopXidLogged(), and XLogRecordAssemble().

◆ IsTransactionBlock()

◆ IsTransactionOrTransactionBlock()

◆ IsTransactionState()

bool IsTransactionState ( void  )
extern

Definition at line 389 of file xact.c.

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

References CurrentTransactionState, TransactionStateData::state, and TRANS_INPROGRESS.

Referenced by AcceptInvalidationMessages(), apply_handle_commit_internal(), apply_handle_origin(), assign_transaction_timeout(), begin_replication_step(), check_client_encoding(), check_default_table_access_method(), check_default_tablespace(), check_default_text_search_config(), check_role(), check_session_authorization(), check_temp_tablespaces(), check_transaction_isolation(), check_transaction_read_only(), clear_subscription_skip_lsn(), ConditionalCatalogCacheInitializeCache(), CreateInitDecodingContext(), ensure_last_message(), FetchRelationStates(), FinishSyncWorker(), IsSubxactTopXidLogPending(), LogicalRepApplyLoop(), LogLogicalMessage(), maybe_reread_subscription(), pa_send_data(), pa_start_subtrans(), pg_do_encoding_conversion(), PrepareClientEncoding(), PrepareTempTablespaces(), ProcessSyncingTablesForApply(), ProcessSyncingTablesForSync(), RelationCacheInvalidate(), RelationFlushRelation(), RelationInitPhysicalAddr(), replorigin_create(), replorigin_drop_by_name(), ReplSlotSyncWorkerMain(), SetMultiXactIdLimit(), SetTransactionIdLimit(), SnapBuildClearExportedSnapshot(), SocketBackend(), stream_stop_internal(), SyncReplicationSlots(), update_retention_status(), and validate_remote_info().

◆ MarkCurrentTransactionIdLoggedIfAny()

◆ MarkSubxactTopXidLogged()

void MarkSubxactTopXidLogged ( void  )
extern

Definition at line 593 of file xact.c.

594{
596
598}
bool IsSubxactTopXidLogPending(void)
Definition xact.c:561

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

Referenced by XLogInsertRecord().

◆ ParseAbortRecord()

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

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 {
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 {
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 {
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 {
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 {
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
#define MinSizeOfXactSubxacts
Definition xact.h:267
#define XACT_XINFO_HAS_GID
Definition xact.h:196
#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
#define XACT_XINFO_HAS_DBINFO
Definition xact.h:189
#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, fb(), MinSizeOfXactAbort, MinSizeOfXactRelfileLocators, MinSizeOfXactStatsItems, MinSizeOfXactSubxacts, xl_xact_stats_items::nitems, xl_xact_relfilelocators::nrels, xl_xact_subxacts::nsubxacts, strlcpy(), 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, 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 
)
extern

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 {
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 {
58
59 parsed->dbId = xl_dbinfo->dbId;
60 parsed->tsId = xl_dbinfo->tsId;
61
62 data += sizeof(xl_xact_dbinfo);
63 }
64
66 {
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 {
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 {
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 {
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}
#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, fb(), MinSizeOfXactCommit, MinSizeOfXactInvals, MinSizeOfXactRelfileLocators, MinSizeOfXactStatsItems, MinSizeOfXactSubxacts, xl_xact_stats_items::nitems, xl_xact_invals::nmsgs, xl_xact_relfilelocators::nrels, xl_xact_subxacts::nsubxacts, strlcpy(), 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, 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 
)
extern

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:868

References fb(), and MAXALIGN.

Referenced by xact_decode(), and xact_desc_prepare().

◆ PrepareTransactionBlock()

bool PrepareTransactionBlock ( const char gid)
extern

Definition at line 4015 of file xact.c.

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

References Assert, TransactionStateData::blockState, CurrentTransactionState, EndTransactionBlock(), fb(), 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 
)
extern

Definition at line 3670 of file xact.c.

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

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

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

◆ RegisterSubXactCallback()

void RegisterSubXactCallback ( SubXactCallback  callback,
void arg 
)
extern

Definition at line 3887 of file xact.c.

3888{
3889 SubXactCallbackItem *item;
3890
3891 item = (SubXactCallbackItem *)
3893 item->callback = callback;
3894 item->arg = arg;
3895 item->next = SubXact_callbacks;
3896 SubXact_callbacks = item;
3897}
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1232
struct SubXactCallbackItem * next
Definition xact.c:324
SubXactCallback callback
Definition xact.c:325
static SubXactCallbackItem * SubXact_callbacks
Definition xact.c:329

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 
)
extern

Definition at line 3827 of file xact.c.

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

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  )
extern

Definition at line 4791 of file xact.c.

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

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)
extern

Definition at line 4481 of file xact.c.

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

References Assert, TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg, ERROR, FATAL, fb(), 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 
)
extern

Definition at line 3739 of file xact.c.

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

References CheckTransactionBlock(), and fb().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

◆ RestoreTransactionCharacteristics()

◆ RollbackAndReleaseCurrentSubTransaction()

void RollbackAndReleaseCurrentSubTransaction ( void  )
extern

Definition at line 4819 of file xact.c.

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

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)
extern

Definition at line 4590 of file xact.c.

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

References Assert, TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg, ERROR, FATAL, fb(), 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 
)
extern

Definition at line 5563 of file xact.c.

5564{
5566 Size nxids = 0;
5567 Size i = 0;
5568 TransactionId *workspace;
5570
5572
5573 result->xactIsoLevel = XactIsoLevel;
5576 result->currentFullTransactionId =
5579
5580 /*
5581 * If we're running in a parallel worker and launching a parallel worker
5582 * of our own, we can just pass along the information that was passed to
5583 * us.
5584 */
5585 if (nParallelCurrentXids > 0)
5586 {
5590 return;
5591 }
5592
5593 /*
5594 * OK, we need to generate a sorted list of XIDs that our workers should
5595 * view as current. First, figure out how many there are.
5596 */
5597 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5598 {
5600 nxids = add_size(nxids, 1);
5602 }
5604 <= maxsize);
5605
5606 /* Copy them to our scratch space. */
5607 workspace = palloc(nxids * sizeof(TransactionId));
5608 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5609 {
5611 workspace[i++] = XidFromFullTransactionId(s->fullTransactionId);
5612 if (s->nChildXids > 0)
5613 memcpy(&workspace[i], s->childXids,
5614 s->nChildXids * sizeof(TransactionId));
5615 i += s->nChildXids;
5616 }
5617 Assert(i == nxids);
5618
5619 /* Sort them. */
5620 qsort(workspace, nxids, sizeof(TransactionId), xidComparator);
5621
5622 /* Copy data into output area. */
5623 result->nParallelCurrentXids = nxids;
5624 memcpy(&result->parallelCurrentXids[0], workspace,
5625 nxids * sizeof(TransactionId));
5626}
int i
Definition isn.c:77
void * palloc(Size size)
Definition mcxt.c:1387
#define qsort(a, b, c, d)
Definition port.h:495
FullTransactionId currentFullTransactionId
Definition xact.c:234
FullTransactionId topFullTransactionId
Definition xact.c:233
CommandId currentCommandId
Definition xact.c:235
TransactionId parallelCurrentXids[FLEXIBLE_ARRAY_MEMBER]
Definition xact.c:237
TransactionId * childXids
Definition xact.c:208
static int nParallelCurrentXids
Definition xact.c:128
static TransactionId * ParallelCurrentXids
Definition xact.c:129
int xidComparator(const void *arg1, const void *arg2)
Definition xid.c:152

References add_size(), Assert, TransactionStateData::childXids, SerializedTransactionState::currentCommandId, currentCommandId, SerializedTransactionState::currentFullTransactionId, CurrentTransactionState, fb(), 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 
)
extern

Definition at line 861 of file xact.c.

862{
864 xactStartTimestamp = xact_ts;
865 stmtStartTimestamp = stmt_ts;
866}

References Assert, IsParallelWorker, stmtStartTimestamp, and xactStartTimestamp.

Referenced by ParallelWorkerMain().

◆ StartParallelWorkerTransaction()

void StartParallelWorkerTransaction ( char tstatespace)
extern

◆ StartTransactionCommand()

void StartTransactionCommand ( void  )
extern

Definition at line 3081 of file xact.c.

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

References Assert, TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, CurTransactionContext, elog, ERROR, fb(), 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(), copy_sequences(), DefineIndex(), DisableSubscriptionAndExit(), do_autovacuum(), EventTriggerOnLogin(), exec_replication_command(), ExecRepack(), 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(), process_single_relation(), ProcessCatchupInterrupt(), ProcessIncomingNotify(), ProcessSyncingTablesForApply(), ProcessSyncingTablesForSync(), ReindexMultipleInternal(), ReindexRelationConcurrently(), RemoveTempRelationsCallback(), ReorderBufferProcessTXN(), ReplSlotSyncWorkerMain(), run_apply_worker(), shell_check_detail(), SnapBuildExportSnapshot(), start_xact_command(), update_retention_status(), vacuum(), vacuum_rel(), validate_remote_info(), and worker_spi_main().

◆ SubTransactionIsActive()

bool SubTransactionIsActive ( SubTransactionId  subxid)
extern

Definition at line 807 of file xact.c.

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

References CurrentTransactionState, fb(), TransactionStateData::parent, TransactionStateData::state, TransactionStateData::subTransactionId, and TRANS_ABORT.

◆ TransactionBlockStatusCode()

char TransactionBlockStatusCode ( void  )
extern

Definition at line 5026 of file xact.c.

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

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)
extern

Definition at line 943 of file xact.c.

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

◆ UnregisterSubXactCallback()

void UnregisterSubXactCallback ( SubXactCallback  callback,
void arg 
)
extern

Definition at line 3900 of file xact.c.

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

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

◆ UnregisterXactCallback()

void UnregisterXactCallback ( XactCallback  callback,
void arg 
)
extern

Definition at line 3840 of file xact.c.

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

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

◆ UserAbortTransactionBlock()

void UserAbortTransactionBlock ( bool  chain)
extern

Definition at line 4227 of file xact.c.

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

References Assert, TransactionStateData::blockState, BlockStateAsString(), TransactionStateData::chain, CurrentTransactionState, elog, ereport, errcode(), errmsg, ERROR, FATAL, fb(), 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 
)
extern

Definition at line 3733 of file xact.c.

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

References CheckTransactionBlock(), and fb().

Referenced by ExecSetVariableStmt(), and standard_ProcessUtility().

◆ xact_desc()

void xact_desc ( StringInfo  buf,
XLogReaderState record 
)
extern

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 {
447
449 XLogRecGetOrigin(record));
450 }
451 else if (info == XLOG_XACT_ABORT || info == XLOG_XACT_ABORT_PREPARED)
452 {
454
456 XLogRecGetOrigin(record));
457 }
458 else if (info == XLOG_XACT_PREPARE)
459 {
461
463 XLogRecGetOrigin(record));
464 }
465 else if (info == XLOG_XACT_ASSIGNMENT)
466 {
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 {
480
482 InvalidOid, false);
483 }
484}
#define InvalidOid
void standby_desc_invalidations(StringInfo buf, int nmsgs, SharedInvalidationMessage *msgs, Oid dbId, Oid tsId, bool relcacheInitFileInval)
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
#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, ReplOriginId origin_id)
Definition xactdesc.c:334
static void xact_desc_assignment(StringInfo buf, xl_xact_assignment *xlrec)
Definition xactdesc.c:428
static void xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec, ReplOriginId origin_id)
Definition xactdesc.c:370
static void xact_desc_prepare(StringInfo buf, uint8 info, xl_xact_prepare *xlrec, ReplOriginId 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, fb(), InvalidOid, 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, and XLogRecGetOrigin.

◆ xact_identify()

const char * xact_identify ( uint8  info)
extern

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 fb(), 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)
extern

Definition at line 6386 of file xact.c.

6387{
6388 uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
6389
6390 /* Backup blocks are not used in xact records */
6392
6393 if (info == XLOG_XACT_COMMIT)
6394 {
6397
6400 record->EndRecPtr, XLogRecGetOrigin(record));
6401 }
6402 else if (info == XLOG_XACT_COMMIT_PREPARED)
6403 {
6406
6408 xact_redo_commit(&parsed, parsed.twophase_xid,
6409 record->EndRecPtr, XLogRecGetOrigin(record));
6410
6411 /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6413 PrepareRedoRemove(parsed.twophase_xid, false);
6415 }
6416 else if (info == XLOG_XACT_ABORT)
6417 {
6420
6423 record->EndRecPtr, XLogRecGetOrigin(record));
6424 }
6425 else if (info == XLOG_XACT_ABORT_PREPARED)
6426 {
6429
6431 xact_redo_abort(&parsed, parsed.twophase_xid,
6432 record->EndRecPtr, XLogRecGetOrigin(record));
6433
6434 /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6436 PrepareRedoRemove(parsed.twophase_xid, false);
6438 }
6439 else if (info == XLOG_XACT_PREPARE)
6440 {
6441 /*
6442 * Store xid and start/end pointers of the WAL record in TwoPhaseState
6443 * gxact entry.
6444 */
6447 XLogRecGetData(record),
6448 record->ReadRecPtr,
6449 record->EndRecPtr,
6450 XLogRecGetOrigin(record));
6452 }
6453 else if (info == XLOG_XACT_ASSIGNMENT)
6454 {
6456
6459 xlrec->nsubxacts, xlrec->xsub);
6460 }
6461 else if (info == XLOG_XACT_INVALIDATIONS)
6462 {
6463 /*
6464 * XXX we do ignore this for now, what matters are invalidations
6465 * written into the commit record.
6466 */
6467 }
6468 else
6469 elog(PANIC, "xact_redo: unknown op code %u", info);
6470}
#define PANIC
Definition elog.h:42
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1177
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1794
@ LW_EXCLUSIVE
Definition lwlock.h:112
void ProcArrayApplyXidAssignment(TransactionId topxid, int nsubxids, TransactionId *subxids)
Definition procarray.c:1317
XLogRecPtr EndRecPtr
Definition xlogreader.h:206
XLogRecPtr ReadRecPtr
Definition xlogreader.h:205
#define InvalidFullTransactionId
Definition transam.h:56
void PrepareRedoAdd(FullTransactionId fxid, char *buf, XLogRecPtr start_lsn, XLogRecPtr end_lsn, ReplOriginId origin_id)
Definition twophase.c:2509
void PrepareRedoRemove(TransactionId xid, bool giveWarning)
Definition twophase.c:2666
static void xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid, XLogRecPtr lsn, ReplOriginId origin_id)
Definition xact.c:6307
static void xact_redo_commit(xl_xact_parsed_commit *parsed, TransactionId xid, XLogRecPtr lsn, ReplOriginId origin_id)
Definition xact.c:6153
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, fb(), InvalidFullTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), PANIC, ParseAbortRecord(), ParseCommitRecord(), PrepareRedoAdd(), PrepareRedoRemove(), ProcArrayApplyXidAssignment(), XLogReaderState::ReadRecPtr, STANDBY_INITIALIZED, standbyState, 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, and XLogRecHasAnyBlockRefs.

◆ xactGetCommittedChildren()

int xactGetCommittedChildren ( TransactionId **  ptr)
extern

Definition at line 5813 of file xact.c.

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

References TransactionStateData::childXids, CurrentTransactionState, fb(), 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 
)
extern

Definition at line 6009 of file xact.c.

6015{
6024
6025 uint8 info;
6026
6028
6029 xl_xinfo.xinfo = 0;
6030
6031 /* decide between a plain and 2pc abort */
6032 if (!TransactionIdIsValid(twophase_xid))
6033 info = XLOG_XACT_ABORT;
6034 else
6036
6037
6038 /* First figure out and collect all the information needed */
6039
6040 xlrec.xact_time = abort_time;
6041
6044
6045 if (nsubxacts > 0)
6046 {
6048 xl_subxacts.nsubxacts = nsubxacts;
6049 }
6050
6051 if (nrels > 0)
6052 {
6054 xl_relfilelocators.nrels = nrels;
6055 info |= XLR_SPECIAL_REL_UPDATE;
6056 }
6057
6058 if (ndroppedstats > 0)
6059 {
6062 }
6063
6064 if (TransactionIdIsValid(twophase_xid))
6065 {
6067 xl_twophase.xid = twophase_xid;
6068 Assert(twophase_gid != NULL);
6069
6072 }
6073
6074 if (TransactionIdIsValid(twophase_xid) && XLogLogicalInfoActive())
6075 {
6077 xl_dbinfo.dbId = MyDatabaseId;
6079 }
6080
6081 /*
6082 * Dump transaction origin information. We need this during recovery to
6083 * update the replication origin progress.
6084 */
6086 {
6088
6091 }
6092
6093 if (xl_xinfo.xinfo != 0)
6094 info |= XLOG_XACT_HAS_INFO;
6095
6096 /* Then include all the collected data into the abort record. */
6097
6099
6101
6102 if (xl_xinfo.xinfo != 0)
6104
6105 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
6107
6109 {
6112 XLogRegisterData(subxacts,
6113 nsubxacts * sizeof(TransactionId));
6114 }
6115
6117 {
6120 XLogRegisterData(rels,
6121 nrels * sizeof(RelFileLocator));
6122 }
6123
6125 {
6130 }
6131
6133 {
6135 if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
6136 XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
6137 }
6138
6139 if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
6141
6142 /* Include the replication origin */
6144
6145 return XLogInsert(RM_XACT_ID, info);
6146}
Oid MyDatabaseTableSpace
Definition globals.c:96
volatile uint32 CritSectionCount
Definition globals.c:45
Oid MyDatabaseId
Definition globals.c:94
ReplOriginXactState replorigin_xact_state
Definition origin.c:167
#define InvalidReplOriginId
Definition origin.h:33
ReplOriginId origin
Definition origin.h:45
XLogRecPtr origin_lsn
Definition origin.h:46
TimestampTz origin_timestamp
Definition origin.h:47
#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK
Definition xact.h:109
#define XACT_XINFO_HAS_AE_LOCKS
Definition xact.h:195
#define XLOG_INCLUDE_ORIGIN
Definition xlog.h:165
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition xloginsert.c:478
void XLogRegisterData(const void *data, uint32 len)
Definition xloginsert.c:368
void XLogSetRecordFlags(uint8 flags)
Definition xloginsert.c:460
void XLogBeginInsert(void)
Definition xloginsert.c:152
#define XLR_SPECIAL_REL_UPDATE
Definition xlogrecord.h:82

References Assert, CritSectionCount, fb(), InvalidReplOriginId, MinSizeOfXactAbort, MinSizeOfXactRelfileLocators, MinSizeOfXactStatsItems, MinSizeOfXactSubxacts, MyDatabaseId, MyDatabaseTableSpace, ReplOriginXactState::origin, ReplOriginXactState::origin_lsn, ReplOriginXactState::origin_timestamp, replorigin_xact_state, TransactionIdIsValid, XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK, 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, 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 
)
extern

Definition at line 5837 of file xact.c.

5845{
5855 uint8 info;
5856
5858
5859 xl_xinfo.xinfo = 0;
5860
5861 /* decide between a plain and 2pc commit */
5862 if (!TransactionIdIsValid(twophase_xid))
5863 info = XLOG_XACT_COMMIT;
5864 else
5866
5867 /* First figure out and collect all the information needed */
5868
5869 xlrec.xact_time = commit_time;
5870
5871 if (relcacheInval)
5873 if (forceSyncCommit)
5877
5878 /*
5879 * Check if the caller would like to ask standbys for immediate feedback
5880 * once this commit is applied.
5881 */
5884
5885 /*
5886 * Relcache invalidations requires information about the current database
5887 * and so does logical decoding.
5888 */
5889 if (nmsgs > 0 || XLogLogicalInfoActive())
5890 {
5892 xl_dbinfo.dbId = MyDatabaseId;
5894 }
5895
5896 if (nsubxacts > 0)
5897 {
5899 xl_subxacts.nsubxacts = nsubxacts;
5900 }
5901
5902 if (nrels > 0)
5903 {
5905 xl_relfilelocators.nrels = nrels;
5906 info |= XLR_SPECIAL_REL_UPDATE;
5907 }
5908
5909 if (ndroppedstats > 0)
5910 {
5913 }
5914
5915 if (nmsgs > 0)
5916 {
5918 xl_invals.nmsgs = nmsgs;
5919 }
5920
5921 if (TransactionIdIsValid(twophase_xid))
5922 {
5924 xl_twophase.xid = twophase_xid;
5925 Assert(twophase_gid != NULL);
5926
5929 }
5930
5931 /* dump transaction origin information */
5933 {
5935
5938 }
5939
5940 if (xl_xinfo.xinfo != 0)
5941 info |= XLOG_XACT_HAS_INFO;
5942
5943 /* Then include all the collected data into the commit record. */
5944
5946
5948
5949 if (xl_xinfo.xinfo != 0)
5950 XLogRegisterData(&xl_xinfo.xinfo, sizeof(xl_xinfo.xinfo));
5951
5952 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5954
5956 {
5959 XLogRegisterData(subxacts,
5960 nsubxacts * sizeof(TransactionId));
5961 }
5962
5964 {
5967 XLogRegisterData(rels,
5968 nrels * sizeof(RelFileLocator));
5969 }
5970
5972 {
5977 }
5978
5979 if (xl_xinfo.xinfo & XACT_XINFO_HAS_INVALS)
5980 {
5982 XLogRegisterData(msgs,
5983 nmsgs * sizeof(SharedInvalidationMessage));
5984 }
5985
5987 {
5989 if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
5990 XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
5991 }
5992
5993 if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5995
5996 /* we allow filtering by xacts */
5998
5999 return XLogInsert(RM_XACT_ID, info);
6000}
int synchronous_commit
Definition xact.c:89
#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, fb(), forceSyncCommit, InvalidReplOriginId, MinSizeOfXactInvals, MinSizeOfXactRelfileLocators, MinSizeOfXactStatsItems, MinSizeOfXactSubxacts, MyDatabaseId, MyDatabaseTableSpace, ReplOriginXactState::origin, ReplOriginXactState::origin_lsn, ReplOriginXactState::origin_timestamp, replorigin_xact_state, synchronous_commit, SYNCHRONOUS_COMMIT_REMOTE_APPLY, TransactionIdIsValid, XACT_COMPLETION_APPLY_FEEDBACK, XACT_COMPLETION_FORCE_SYNC_COMMIT, XACT_COMPLETION_UPDATE_RELCACHE_FILE, XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK, 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, 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 86 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactIsoLevel

PGDLLIMPORT int DefaultXactIsoLevel
extern

Definition at line 80 of file xact.c.

Referenced by StartTransaction().

◆ DefaultXactReadOnly

PGDLLIMPORT bool DefaultXactReadOnly
extern

Definition at line 83 of file xact.c.

Referenced by StartTransaction().

◆ MyXactFlags

◆ synchronous_commit

PGDLLIMPORT int synchronous_commit
extern

Definition at line 89 of file xact.c.

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

◆ xact_is_sampled

PGDLLIMPORT bool xact_is_sampled
extern

Definition at line 298 of file xact.c.

Referenced by check_log_duration(), and StartTransaction().

◆ XactDeferrable

◆ XactIsoLevel

◆ XactReadOnly