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)
 
int GetTopReadOnlyTransactionNestLevel (void)
 
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);
463extern void CommandCounterIncrement(void);
464extern void ForceSyncCommit(void);
465extern void StartTransactionCommand(void);
468extern void CommitTransactionCommand(void);
469extern void AbortCurrentTransaction(void);
470extern void BeginTransactionBlock(void);
471extern bool EndTransactionBlock(bool chain);
472extern bool PrepareTransactionBlock(const char *gid);
473extern void UserAbortTransactionBlock(bool chain);
474extern void BeginImplicitTransactionBlock(void);
475extern void EndImplicitTransactionBlock(void);
476extern void ReleaseSavepoint(const char *name);
477extern void DefineSavepoint(const char *name);
478extern void RollbackToSavepoint(const char *name);
479extern void BeginInternalSubTransaction(const char *name);
480extern void ReleaseCurrentSubTransaction(void);
482extern bool IsSubTransaction(void);
486extern void EndParallelWorkerTransaction(void);
487extern bool IsTransactionBlock(void);
488extern bool IsTransactionOrTransactionBlock(void);
489extern char TransactionBlockStatusCode(void);
490extern void AbortOutOfAnyTransaction(void);
491extern void PreventInTransactionBlock(bool isTopLevel, const char *stmtType);
492extern void RequireTransactionBlock(bool isTopLevel, const char *stmtType);
493extern void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType);
494extern bool IsInTransactionBlock(bool isTopLevel);
499
500extern bool IsSubxactTopXidLogPending(void);
501extern void MarkSubxactTopXidLogged(void);
502
504
506 int nsubxacts, TransactionId *subxacts,
507 int nrels, RelFileLocator *rels,
508 int ndroppedstats,
510 int nmsgs, SharedInvalidationMessage *msgs,
511 bool relcacheInval,
512 int xactflags,
513 TransactionId twophase_xid,
514 const char *twophase_gid);
515
517 int nsubxacts, TransactionId *subxacts,
518 int nrels, RelFileLocator *rels,
519 int ndroppedstats,
521 int xactflags, TransactionId twophase_xid,
522 const char *twophase_gid);
523extern void xact_redo(XLogReaderState *record);
524
525/* xactdesc.c */
526extern void xact_desc(StringInfo buf, XLogReaderState *record);
527extern const char *xact_identify(uint8 info);
528
529/* also in xactdesc.c, so they can be shared between front/backend code */
533
534extern void EnterParallelMode(void);
535extern void ExitParallelMode(void);
536extern bool IsInParallelMode(void);
537
538#endif /* XACT_H */
uint8_t uint8
Definition c.h:681
uint32 SubTransactionId
Definition c.h:799
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:617
int32_t int32
Definition c.h:679
uint16_t uint16
Definition c.h:682
uint32_t uint32
Definition c.h:683
uint32 CommandId
Definition c.h:809
uint32 TransactionId
Definition c.h:795
size_t Size
Definition c.h:748
int64 TimestampTz
Definition timestamp.h:39
Datum arg
Definition elog.c:1323
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:5043
void SerializeTransactionState(Size maxsize, char *start_address)
Definition xact.c:5599
void ExitParallelMode(void)
Definition xact.c:1094
const char * xact_identify(uint8 info)
Definition xactdesc.c:487
void SaveTransactionCharacteristics(SavedTransactionCharacteristics *s)
Definition xact.c:3189
void BeginInternalSubTransaction(const char *name)
Definition xact.c:4748
FullTransactionId GetCurrentFullTransactionId(void)
Definition xact.c:514
void RestoreTransactionCharacteristics(const SavedTransactionCharacteristics *s)
Definition xact.c:3197
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition xact.c:3764
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:4258
bool IsInTransactionBlock(bool isTopLevel)
Definition xact.c:3823
bool PrepareTransactionBlock(const char *gid)
Definition xact.c:4046
int GetCurrentTransactionNestLevel(void)
Definition xact.c:931
void xact_redo(XLogReaderState *record)
Definition xact.c:6422
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:1081
TransactionId GetStableLatestTransactionId(void)
Definition xact.c:609
void UnregisterSubXactCallback(SubXactCallback callback, void *arg)
Definition xact.c:3931
void BeginImplicitTransactionBlock(void)
Definition xact.c:4380
void(* XactCallback)(XactEvent event, void *arg)
Definition xact.h:139
void RequireTransactionBlock(bool isTopLevel, const char *stmtType)
Definition xact.c:3770
void DefineSavepoint(const char *name)
Definition xact.c:4427
void UnregisterXactCallback(XactCallback callback, void *arg)
Definition xact.c:3871
bool IsTransactionState(void)
Definition xact.c:389
void CommandCounterIncrement(void)
Definition xact.c:1130
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition xact.c:3701
Size EstimateTransactionStateSpace(void)
Definition xact.c:5571
TransactionId GetTopTransactionIdIfAny(void)
Definition xact.c:443
#define GIDSIZE
Definition xact.h:31
char TransactionBlockStatusCode(void)
Definition xact.c:5057
void RollbackAndReleaseCurrentSubTransaction(void)
Definition xact.c:4850
FullTransactionId GetCurrentFullTransactionIdIfAny(void)
Definition xact.c:532
void StartTransactionCommand(void)
Definition xact.c:3112
bool IsAbortedTransactionBlockState(void)
Definition xact.c:409
void ReleaseCurrentSubTransaction(void)
Definition xact.c:4822
void EndImplicitTransactionBlock(void)
Definition xact.c:4405
void StartParallelWorkerTransaction(char *tstatespace)
Definition xact.c:5670
void SetParallelStartTimestamps(TimestampTz xact_ts, TimestampTz stmt_ts)
Definition xact.c:861
void ReleaseSavepoint(const char *name)
Definition xact.c:4512
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:5873
void ForceSyncCommit(void)
Definition xact.c:1182
int GetTopReadOnlyTransactionNestLevel(void)
Definition xact.c:1062
bool IsSubTransaction(void)
Definition xact.c:5098
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:5025
bool IsInParallelMode(void)
Definition xact.c:1119
int xactGetCommittedChildren(TransactionId **ptr)
Definition xact.c:5849
TransactionId GetCurrentTransactionIdIfAny(void)
Definition xact.c:473
void BeginTransactionBlock(void)
Definition xact.c:3978
TimestampTz GetCurrentStatementStartTimestamp(void)
Definition xact.c:881
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition xact.c:872
void EndParallelWorkerTransaction(void)
Definition xact.c:5695
void RegisterXactCallback(XactCallback callback, void *arg)
Definition xact.c:3858
void CommitTransactionCommand(void)
Definition xact.c:3210
void RollbackToSavepoint(const char *name)
Definition xact.c:4621
bool SubTransactionIsActive(SubTransactionId subxid)
Definition xact.c:807
void RegisterSubXactCallback(SubXactCallback callback, void *arg)
Definition xact.c:3918
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:4098
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:4916
void AbortCurrentTransaction(void)
Definition xact.c:3504
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:6045
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 3504 of file xact.c.

3505{
3506 /*
3507 * Repeatedly call AbortCurrentTransactionInternal() until all the work is
3508 * done.
3509 */
3511 {
3512 }
3513}
static bool AbortCurrentTransactionInternal(void)
Definition xact.c:3522

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

4917{
4919
4920 /* Ensure we're not running in a doomed memory context */
4922
4923 /*
4924 * Get out of any transaction or nested transaction
4925 */
4926 do
4927 {
4928 switch (s->blockState)
4929 {
4930 case TBLOCK_DEFAULT:
4931 if (s->state == TRANS_DEFAULT)
4932 {
4933 /* Not in a transaction, do nothing */
4934 }
4935 else
4936 {
4937 /*
4938 * We can get here after an error during transaction start
4939 * (state will be TRANS_START). Need to clean up the
4940 * incompletely started transaction. First, adjust the
4941 * low-level state to suppress warning message from
4942 * AbortTransaction.
4943 */
4944 if (s->state == TRANS_START)
4948 }
4949 break;
4950 case TBLOCK_STARTED:
4951 case TBLOCK_BEGIN:
4952 case TBLOCK_INPROGRESS:
4955 case TBLOCK_END:
4957 case TBLOCK_PREPARE:
4958 /* In a transaction, so clean up */
4962 break;
4963 case TBLOCK_ABORT:
4964 case TBLOCK_ABORT_END:
4965
4966 /*
4967 * AbortTransaction is already done, still need Cleanup.
4968 * However, if we failed partway through running ROLLBACK,
4969 * there will be an active portal running that command, which
4970 * we need to shut down before doing CleanupTransaction.
4971 */
4975 break;
4976
4977 /*
4978 * In a subtransaction, so clean it up and abort parent too
4979 */
4980 case TBLOCK_SUBBEGIN:
4982 case TBLOCK_SUBRELEASE:
4983 case TBLOCK_SUBCOMMIT:
4985 case TBLOCK_SUBRESTART:
4988 s = CurrentTransactionState; /* changed by pop */
4989 break;
4990
4991 case TBLOCK_SUBABORT:
4994 /* As above, but AbortSubTransaction already done */
4995 if (s->curTransactionOwner)
4996 {
4997 /* As in TBLOCK_ABORT, might have a live portal to zap */
5002 }
5004 s = CurrentTransactionState; /* changed by pop */
5005 break;
5006 }
5007 } while (s->blockState != TBLOCK_DEFAULT);
5008
5009 /* Should be out of all subxacts now */
5010 Assert(s->parent == NULL);
5011
5012 /*
5013 * Revert to TopMemoryContext, to ensure we exit in a well-defined state
5014 * whether there were any transactions to close or not. (Callers that
5015 * don't intend to exit soon should switch to some other context to avoid
5016 * long-term memory leaks.)
5017 */
5019}
#define Assert(condition)
Definition c.h:1002
MemoryContext TopMemoryContext
Definition mcxt.c:167
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:138
void AtAbort_Portals(void)
Definition portalmem.c:782
void AtSubAbort_Portals(SubTransactionId mySubid, SubTransactionId parentSubid, ResourceOwner myXactOwner, ResourceOwner parentXactOwner)
Definition portalmem.c:981
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:5442
static void CleanupTransaction(void)
Definition xact.c:3062
@ 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:5273
static void AtAbort_Memory(void)
Definition xact.c:1926
@ 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:2855
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 4380 of file xact.c.

4381{
4383
4384 /*
4385 * If we are in STARTED state (that is, no transaction block is open),
4386 * switch to IMPLICIT_INPROGRESS state, creating an implicit transaction
4387 * block.
4388 *
4389 * For caller convenience, we consider all other transaction states as
4390 * legal here; otherwise the caller would need its own state check, which
4391 * seems rather pointless.
4392 */
4393 if (s->blockState == TBLOCK_STARTED)
4395}

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

4749{
4752
4753 /*
4754 * Errors within this function are improbable, but if one does happen we
4755 * force a FATAL exit. Callers generally aren't prepared to handle losing
4756 * control, and moreover our transaction state is probably corrupted if we
4757 * fail partway through; so an ordinary ERROR longjmp isn't okay.
4758 */
4759 ExitOnAnyError = true;
4760
4761 /*
4762 * We do not check for parallel mode here. It's permissible to start and
4763 * end "internal" subtransactions while in parallel mode, so long as no
4764 * new XIDs or command IDs are assigned. Enforcement of that occurs in
4765 * AssignTransactionId() and CommandCounterIncrement().
4766 */
4767
4768 switch (s->blockState)
4769 {
4770 case TBLOCK_STARTED:
4771 case TBLOCK_INPROGRESS:
4774 case TBLOCK_END:
4775 case TBLOCK_PREPARE:
4777 /* Normal subtransaction start */
4779 s = CurrentTransactionState; /* changed by push */
4780
4781 /*
4782 * Savepoint names, like the TransactionState block itself, live
4783 * in TopTransactionContext.
4784 */
4785 if (name)
4787 break;
4788
4789 /* These cases are invalid. */
4790 case TBLOCK_DEFAULT:
4791 case TBLOCK_BEGIN:
4792 case TBLOCK_SUBBEGIN:
4793 case TBLOCK_SUBRELEASE:
4794 case TBLOCK_SUBCOMMIT:
4795 case TBLOCK_ABORT:
4796 case TBLOCK_SUBABORT:
4797 case TBLOCK_ABORT_END:
4801 case TBLOCK_SUBRESTART:
4803 elog(FATAL, "BeginInternalSubTransaction: unexpected state %s",
4805 break;
4806 }
4807
4810
4812}
#define FATAL
Definition elog.h:42
#define elog(elevel,...)
Definition elog.h:228
bool ExitOnAnyError
Definition globals.c:125
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition mcxt.c:1897
MemoryContext TopTransactionContext
Definition mcxt.c:172
static void PushTransaction(void)
Definition xact.c:5475
void StartTransactionCommand(void)
Definition xact.c:3112
static const char * BlockStateAsString(TBlockState blockState)
Definition xact.c:5766
void CommitTransactionCommand(void)
Definition xact.c:3210

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

3979{
3981
3982 switch (s->blockState)
3983 {
3984 /*
3985 * We are not inside a transaction block, so allow one to begin.
3986 */
3987 case TBLOCK_STARTED:
3989 break;
3990
3991 /*
3992 * BEGIN converts an implicit transaction block to a regular one.
3993 * (Note that we allow this even if we've already done some
3994 * commands, which is a bit odd but matches historical practice.)
3995 */
3998 break;
3999
4000 /*
4001 * Already a transaction block in progress.
4002 */
4003 case TBLOCK_INPROGRESS:
4006 case TBLOCK_ABORT:
4007 case TBLOCK_SUBABORT:
4010 errmsg("there is already a transaction in progress")));
4011 break;
4012
4013 /* These cases are invalid. */
4014 case TBLOCK_DEFAULT:
4015 case TBLOCK_BEGIN:
4016 case TBLOCK_SUBBEGIN:
4017 case TBLOCK_END:
4018 case TBLOCK_SUBRELEASE:
4019 case TBLOCK_SUBCOMMIT:
4020 case TBLOCK_ABORT_END:
4024 case TBLOCK_SUBRESTART:
4026 case TBLOCK_PREPARE:
4027 elog(FATAL, "BeginTransactionBlock: unexpected state %s",
4029 break;
4030 }
4031}
int errcode(int sqlerrcode)
Definition elog.c:875
#define WARNING
Definition elog.h:37
#define ereport(elevel,...)
Definition elog.h:152
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 1130 of file xact.c.

1131{
1132 /*
1133 * If the current value of the command counter hasn't been "used" to mark
1134 * tuples, we need not increment it, since there's no need to distinguish
1135 * a read-only command from others. This helps postpone command counter
1136 * overflow, and keeps no-op CommandCounterIncrement operations cheap.
1137 */
1139 {
1140 /*
1141 * Workers synchronize transaction state at the beginning of each
1142 * parallel operation, so we can't account for new commands after that
1143 * point.
1144 */
1146 ereport(ERROR,
1148 errmsg("cannot start commands during a parallel operation")));
1149
1150 currentCommandId += 1;
1152 {
1153 currentCommandId -= 1;
1154 ereport(ERROR,
1156 errmsg("cannot have more than 2^32-2 commands in a transaction")));
1157 }
1158 currentCommandIdUsed = false;
1159
1160 /* Propagate new command ID into static snapshots */
1162
1163 /*
1164 * Make any catalog changes done by the just-completed command visible
1165 * in the local syscache. We obviously don't need to do this after a
1166 * read-only command. (But see hacks in inval.c to make real sure we
1167 * don't think a command that queued inval messages was read-only.)
1168 */
1170 }
1171}
#define InvalidCommandId
Definition c.h:812
#define ERROR
Definition elog.h:40
#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:1119
static void AtCCI_LocalCache(void)
Definition xact.c:1621

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(), AlterPropGraph(), AlterPublicationAllFlags(), AlterPublicationOptions(), AlterRole(), apply_concurrent_changes(), 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_attribute_defaults(), copy_index_constraints(), copy_table_data(), create_conflict_log_table(), create_ctas_internal(), create_toast_table(), CreateFKCheckTrigger(), createForeignKeyActionTriggers(), CreateForeignTable(), createPartitionTable(), CreatePropGraph(), 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(), insert_element_record(), 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(), rebuild_relation_finish_concurrent(), recordExtensionInitPrivWorker(), reindex_index(), reindex_relation(), ReindexRelationConcurrently(), relation_statistics_update_internal(), RelationSetNewRelfilenumber(), RemoveInheritedConstraint(), RemoveRoleFromInitPriv(), RemoveRoleFromObjectPolicy(), RenumberEnumType(), ReplaceRoleInInitPriv(), replorigin_create(), replorigin_drop_by_name(), ri_FastPathBatchFlush(), ri_FastPathCheck(), 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 3210 of file xact.c.

3211{
3212 /*
3213 * Repeatedly call CommitTransactionCommandInternal() until all the work
3214 * is done.
3215 */
3217 {
3218 }
3219}
static bool CommitTransactionCommandInternal(void)
Definition xact.c:3228

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(), BuildDatabaseList(), BuildRelationList(), clear_subscription_skip_lsn(), copy_sequences(), DatabaseExists(), 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(), ProcessSingleRelationByOid(), ProcessSyncingTablesForApply(), ProcessSyncingTablesForSync(), ReindexMultipleInternal(), ReindexRelationConcurrently(), RemoveTempRelationsCallback(), RepackWorkerMain(), 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 4427 of file xact.c.

4428{
4430
4431 /*
4432 * Workers synchronize transaction state at the beginning of each parallel
4433 * operation, so we can't account for new subtransactions after that
4434 * point. (Note that this check will certainly error out if s->blockState
4435 * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4436 * below.)
4437 */
4439 ereport(ERROR,
4441 errmsg("cannot define savepoints during a parallel operation")));
4442
4443 switch (s->blockState)
4444 {
4445 case TBLOCK_INPROGRESS:
4447 /* Normal subtransaction start */
4449 s = CurrentTransactionState; /* changed by push */
4450
4451 /*
4452 * Savepoint names, like the TransactionState block itself, live
4453 * in TopTransactionContext.
4454 */
4455 if (name)
4457 break;
4458
4459 /*
4460 * We disallow savepoint commands in implicit transaction blocks.
4461 * There would be no great difficulty in allowing them so far as
4462 * this module is concerned, but a savepoint seems inconsistent
4463 * with exec_simple_query's behavior of abandoning the whole query
4464 * string upon error. Also, the point of an implicit transaction
4465 * block (as opposed to a regular one) is to automatically close
4466 * after an error, so it's hard to see how a savepoint would fit
4467 * into that.
4468 *
4469 * The error messages for this are phrased as if there were no
4470 * active transaction block at all, which is historical but
4471 * perhaps could be improved.
4472 */
4474 ereport(ERROR,
4476 /* translator: %s represents an SQL statement name */
4477 errmsg("%s can only be used in transaction blocks",
4478 "SAVEPOINT")));
4479 break;
4480
4481 /* These cases are invalid. */
4482 case TBLOCK_DEFAULT:
4483 case TBLOCK_STARTED:
4484 case TBLOCK_BEGIN:
4486 case TBLOCK_SUBBEGIN:
4487 case TBLOCK_END:
4488 case TBLOCK_SUBRELEASE:
4489 case TBLOCK_SUBCOMMIT:
4490 case TBLOCK_ABORT:
4491 case TBLOCK_SUBABORT:
4492 case TBLOCK_ABORT_END:
4496 case TBLOCK_SUBRESTART:
4498 case TBLOCK_PREPARE:
4499 elog(FATAL, "DefineSavepoint: unexpected state %s",
4501 break;
4502 }
4503}

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

4406{
4408
4409 /*
4410 * If we are in IMPLICIT_INPROGRESS state, switch back to STARTED state,
4411 * allowing CommitTransactionCommand to commit whatever happened during
4412 * the implicit transaction block as though it were a single statement.
4413 *
4414 * For caller convenience, we consider all other transaction states as
4415 * legal here; otherwise the caller would need its own state check, which
4416 * seems rather pointless.
4417 */
4420}

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

4099{
4101 bool result = false;
4102
4103 switch (s->blockState)
4104 {
4105 /*
4106 * We are in a transaction block, so tell CommitTransactionCommand
4107 * to COMMIT.
4108 */
4109 case TBLOCK_INPROGRESS:
4111 result = true;
4112 break;
4113
4114 /*
4115 * We are in an implicit transaction block. If AND CHAIN was
4116 * specified, error. Otherwise commit, but issue a warning
4117 * because there was no explicit BEGIN before this.
4118 */
4120 if (chain)
4121 ereport(ERROR,
4123 /* translator: %s represents an SQL statement name */
4124 errmsg("%s can only be used in transaction blocks",
4125 "COMMIT AND CHAIN")));
4126 else
4129 errmsg("there is no transaction in progress")));
4131 result = true;
4132 break;
4133
4134 /*
4135 * We are in a failed transaction block. Tell
4136 * CommitTransactionCommand it's time to exit the block.
4137 */
4138 case TBLOCK_ABORT:
4140 break;
4141
4142 /*
4143 * We are in a live subtransaction block. Set up to subcommit all
4144 * open subtransactions and then commit the main transaction.
4145 */
4147 while (s->parent != NULL)
4148 {
4151 else
4152 elog(FATAL, "EndTransactionBlock: unexpected state %s",
4154 s = s->parent;
4155 }
4156 if (s->blockState == TBLOCK_INPROGRESS)
4158 else
4159 elog(FATAL, "EndTransactionBlock: unexpected state %s",
4161 result = true;
4162 break;
4163
4164 /*
4165 * Here we are inside an aborted subtransaction. Treat the COMMIT
4166 * as ROLLBACK: set up to abort everything and exit the main
4167 * transaction.
4168 */
4169 case TBLOCK_SUBABORT:
4170 while (s->parent != NULL)
4171 {
4174 else if (s->blockState == TBLOCK_SUBABORT)
4176 else
4177 elog(FATAL, "EndTransactionBlock: unexpected state %s",
4179 s = s->parent;
4180 }
4181 if (s->blockState == TBLOCK_INPROGRESS)
4183 else if (s->blockState == TBLOCK_ABORT)
4185 else
4186 elog(FATAL, "EndTransactionBlock: unexpected state %s",
4188 break;
4189
4190 /*
4191 * The user issued COMMIT when not inside a transaction. For
4192 * COMMIT without CHAIN, issue a WARNING, staying in
4193 * TBLOCK_STARTED state. The upcoming call to
4194 * CommitTransactionCommand() will then close the transaction and
4195 * put us back into the default state. For COMMIT AND CHAIN,
4196 * error.
4197 */
4198 case TBLOCK_STARTED:
4199 if (chain)
4200 ereport(ERROR,
4202 /* translator: %s represents an SQL statement name */
4203 errmsg("%s can only be used in transaction blocks",
4204 "COMMIT AND CHAIN")));
4205 else
4208 errmsg("there is no transaction in progress")));
4209 result = true;
4210 break;
4211
4212 /*
4213 * The user issued a COMMIT that somehow ran inside a parallel
4214 * worker. We can't cope with that.
4215 */
4217 ereport(FATAL,
4219 errmsg("cannot commit during a parallel operation")));
4220 break;
4221
4222 /* These cases are invalid. */
4223 case TBLOCK_DEFAULT:
4224 case TBLOCK_BEGIN:
4225 case TBLOCK_SUBBEGIN:
4226 case TBLOCK_END:
4227 case TBLOCK_SUBRELEASE:
4228 case TBLOCK_SUBCOMMIT:
4229 case TBLOCK_ABORT_END:
4233 case TBLOCK_SUBRESTART:
4235 case TBLOCK_PREPARE:
4236 elog(FATAL, "EndTransactionBlock: unexpected state %s",
4238 break;
4239 }
4240
4242 s->blockState == TBLOCK_END ||
4245
4246 s->chain = chain;
4247
4248 return result;
4249}
uint32 result

References Assert, TransactionStateData::blockState, BlockStateAsString(), TransactionStateData::chain, CurrentTransactionState, elog, ereport, errcode(), errmsg, ERROR, FATAL, fb(), TransactionStateData::parent, result, 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 5571 of file xact.c.

5572{
5574 Size nxids = 0;
5576
5577 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5578 {
5580 nxids = add_size(nxids, 1);
5582 }
5583
5584 return add_size(size, mul_size(sizeof(TransactionId), nxids));
5585}
Size add_size(Size s1, Size s2)
Definition mcxt.c:1733
Size mul_size(Size s1, Size s2)
Definition mcxt.c:1752
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 1182 of file xact.c.

1183{
1184 forceSyncCommit = true;
1185}
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 apply_concurrent_delete(), apply_concurrent_insert(), apply_concurrent_update(), ATRewriteTable(), CatalogTuplesMultiInsertWithInfo(), CopyFrom(), create_edata_for_relation(), create_estate_for_relation(), FindConflictTuple(), GetSnapshotData(), GetSnapshotDataReuse(), heap_inplace_lock(), heap_insert_for_repack(), intorel_startup(), MergePartitionsMoveRows(), pgrowlocks(), RegisterRelcacheInvalidation(), RelationFindReplTupleByIndex(), RelationFindReplTupleSeq(), ri_LockPKTuple(), 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:1649
#define PG_USED_FOR_ASSERTS_ONLY
Definition c.h:308
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:797
#define InvalidLocalTransactionId
Definition lock.h:68
PGPROC * MyProc
Definition proc.c:71
LocalTransactionId lxid
Definition proc.h:231
struct PGPROC::@134 vxid
static TransactionId ReadNextTransactionId(void)
Definition transam.h:375
#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().

◆ GetTopReadOnlyTransactionNestLevel()

int GetTopReadOnlyTransactionNestLevel ( void  )
extern

Definition at line 1062 of file xact.c.

1063{
1065
1066 if (!XactReadOnly)
1067 return 0;
1068 while (s->nestingLevel > 1)
1069 {
1070 if (!s->prevXactReadOnly)
1071 return s->nestingLevel;
1072 s = s->parent;
1073 }
1074 return s->nestingLevel;
1075}
bool prevXactReadOnly
Definition xact.c:213
bool XactReadOnly
Definition xact.c:84

References CurrentTransactionState, TransactionStateData::nestingLevel, TransactionStateData::parent, TransactionStateData::prevXactReadOnly, and XactReadOnly.

Referenced by begin_remote_xact().

◆ GetTopTransactionId()

◆ GetTopTransactionIdIfAny()

◆ IsAbortedTransactionBlockState()

◆ IsInParallelMode()

◆ IsInTransactionBlock()

bool IsInTransactionBlock ( bool  isTopLevel)
extern

Definition at line 3823 of file xact.c.

3824{
3825 /*
3826 * Return true on same conditions that would make
3827 * PreventInTransactionBlock error out
3828 */
3829 if (IsTransactionBlock())
3830 return true;
3831
3832 if (IsSubTransaction())
3833 return true;
3834
3835 if (!isTopLevel)
3836 return true;
3837
3840 return true;
3841
3842 return false;
3843}
bool IsSubTransaction(void)
Definition xact.c:5098
bool IsTransactionBlock(void)
Definition xact.c:5025

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

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(), LogicalParallelApplyLoop(), 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}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
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(), memcpy(), 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(), memcpy(), 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:955

References fb(), and MAXALIGN.

Referenced by xact_decode(), and xact_desc_prepare().

◆ PrepareTransactionBlock()

bool PrepareTransactionBlock ( const char gid)
extern

Definition at line 4046 of file xact.c.

4047{
4049 bool result;
4050
4051 /* Set up to commit the current transaction */
4052 result = EndTransactionBlock(false);
4053
4054 /* If successful, change outer tblock state to PREPARE */
4055 if (result)
4056 {
4058
4059 while (s->parent != NULL)
4060 s = s->parent;
4061
4062 if (s->blockState == TBLOCK_END)
4063 {
4064 /* Save GID where PrepareTransaction can find it again */
4066
4068 }
4069 else
4070 {
4071 /*
4072 * ignore case where we are not in a transaction;
4073 * EndTransactionBlock already issued a warning.
4074 */
4077 /* Don't send back a PREPARE result tag... */
4078 result = false;
4079 }
4080 }
4081
4082 return result;
4083}
static char * prepareGID
Definition xact.c:290
bool EndTransactionBlock(bool chain)
Definition xact.c:4098

References Assert, TransactionStateData::blockState, CurrentTransactionState, EndTransactionBlock(), fb(), MemoryContextStrdup(), TransactionStateData::parent, prepareGID, result, 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 3701 of file xact.c.

3702{
3703 /*
3704 * xact block already started?
3705 */
3706 if (IsTransactionBlock())
3707 ereport(ERROR,
3709 /* translator: %s represents an SQL statement name */
3710 errmsg("%s cannot run inside a transaction block",
3711 stmtType)));
3712
3713 /*
3714 * subtransaction?
3715 */
3716 if (IsSubTransaction())
3717 ereport(ERROR,
3719 /* translator: %s represents an SQL statement name */
3720 errmsg("%s cannot run inside a subtransaction",
3721 stmtType)));
3722
3723 /*
3724 * inside a function call?
3725 */
3726 if (!isTopLevel)
3727 ereport(ERROR,
3729 /* translator: %s represents an SQL statement name */
3730 errmsg("%s cannot be executed from a function or procedure",
3731 stmtType)));
3732
3733 /* If we got past IsTransactionBlock test, should be in default state */
3736 elog(FATAL, "cannot prevent transaction chain");
3737
3738 /* All okay. Set the flag to make sure the right thing happens later. */
3740}
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(), 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 3918 of file xact.c.

3919{
3920 SubXactCallbackItem *item;
3921
3922 item = (SubXactCallbackItem *)
3924 item->callback = callback;
3925 item->arg = arg;
3926 item->next = SubXact_callbacks;
3927 SubXact_callbacks = item;
3928}
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1235
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 3858 of file xact.c.

3859{
3860 XactCallbackItem *item;
3861
3862 item = (XactCallbackItem *)
3864 item->callback = callback;
3865 item->arg = arg;
3866 item->next = Xact_callbacks;
3867 Xact_callbacks = item;
3868}
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 4822 of file xact.c.

4823{
4825
4826 /*
4827 * We do not check for parallel mode here. It's permissible to start and
4828 * end "internal" subtransactions while in parallel mode, so long as no
4829 * new XIDs or command IDs are assigned.
4830 */
4831
4833 elog(ERROR, "ReleaseCurrentSubTransaction: unexpected state %s",
4838 s = CurrentTransactionState; /* changed by pop */
4840}
MemoryContext CurTransactionContext
Definition mcxt.c:173
static void CommitSubTransaction(void)
Definition xact.c:5158

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

4513{
4515 TransactionState target,
4516 xact;
4517
4518 /*
4519 * Workers synchronize transaction state at the beginning of each parallel
4520 * operation, so we can't account for transaction state change after that
4521 * point. (Note that this check will certainly error out if s->blockState
4522 * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4523 * below.)
4524 */
4526 ereport(ERROR,
4528 errmsg("cannot release savepoints during a parallel operation")));
4529
4530 switch (s->blockState)
4531 {
4532 /*
4533 * We can't release a savepoint if there is no savepoint defined.
4534 */
4535 case TBLOCK_INPROGRESS:
4536 ereport(ERROR,
4538 errmsg("savepoint \"%s\" does not exist", name)));
4539 break;
4540
4542 /* See comment about implicit transactions in DefineSavepoint */
4543 ereport(ERROR,
4545 /* translator: %s represents an SQL statement name */
4546 errmsg("%s can only be used in transaction blocks",
4547 "RELEASE SAVEPOINT")));
4548 break;
4549
4550 /*
4551 * We are in a non-aborted subtransaction. This is the only valid
4552 * case.
4553 */
4555 break;
4556
4557 /* These cases are invalid. */
4558 case TBLOCK_DEFAULT:
4559 case TBLOCK_STARTED:
4560 case TBLOCK_BEGIN:
4562 case TBLOCK_SUBBEGIN:
4563 case TBLOCK_END:
4564 case TBLOCK_SUBRELEASE:
4565 case TBLOCK_SUBCOMMIT:
4566 case TBLOCK_ABORT:
4567 case TBLOCK_SUBABORT:
4568 case TBLOCK_ABORT_END:
4572 case TBLOCK_SUBRESTART:
4574 case TBLOCK_PREPARE:
4575 elog(FATAL, "ReleaseSavepoint: unexpected state %s",
4577 break;
4578 }
4579
4580 for (target = s; target; target = target->parent)
4581 {
4582 if (target->name && strcmp(target->name, name) == 0)
4583 break;
4584 }
4585
4586 if (!target)
4587 ereport(ERROR,
4589 errmsg("savepoint \"%s\" does not exist", name)));
4590
4591 /* disallow crossing savepoint level boundaries */
4592 if (target->savepointLevel != s->savepointLevel)
4593 ereport(ERROR,
4595 errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
4596
4597 /*
4598 * Mark "commit pending" all subtransactions up to the target
4599 * subtransaction. The actual commits will happen when control gets to
4600 * CommitTransactionCommand.
4601 */
4603 for (;;)
4604 {
4605 Assert(xact->blockState == TBLOCK_SUBINPROGRESS);
4606 xact->blockState = TBLOCK_SUBRELEASE;
4607 if (xact == target)
4608 break;
4609 xact = xact->parent;
4610 Assert(xact);
4611 }
4612}

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

3771{
3772 CheckTransactionBlock(isTopLevel, true, stmtType);
3773}
static void CheckTransactionBlock(bool isTopLevel, bool throwError, const char *stmtType)
Definition xact.c:3779

References CheckTransactionBlock(), and fb().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

◆ RestoreTransactionCharacteristics()

◆ RollbackAndReleaseCurrentSubTransaction()

void RollbackAndReleaseCurrentSubTransaction ( void  )
extern

Definition at line 4850 of file xact.c.

4851{
4853
4854 /*
4855 * We do not check for parallel mode here. It's permissible to start and
4856 * end "internal" subtransactions while in parallel mode, so long as no
4857 * new XIDs or command IDs are assigned.
4858 */
4859
4860 switch (s->blockState)
4861 {
4862 /* Must be in a subtransaction */
4864 case TBLOCK_SUBABORT:
4865 break;
4866
4867 /* These cases are invalid. */
4868 case TBLOCK_DEFAULT:
4869 case TBLOCK_STARTED:
4870 case TBLOCK_BEGIN:
4873 case TBLOCK_SUBBEGIN:
4874 case TBLOCK_INPROGRESS:
4875 case TBLOCK_END:
4876 case TBLOCK_SUBRELEASE:
4877 case TBLOCK_SUBCOMMIT:
4878 case TBLOCK_ABORT:
4879 case TBLOCK_ABORT_END:
4883 case TBLOCK_SUBRESTART:
4885 case TBLOCK_PREPARE:
4886 elog(FATAL, "RollbackAndReleaseCurrentSubTransaction: unexpected state %s",
4888 break;
4889 }
4890
4891 /*
4892 * Abort the current subtransaction, if needed.
4893 */
4896
4897 /* And clean it up, too */
4899
4900 s = CurrentTransactionState; /* changed by pop */
4906}

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

4622{
4624 TransactionState target,
4625 xact;
4626
4627 /*
4628 * Workers synchronize transaction state at the beginning of each parallel
4629 * operation, so we can't account for transaction state change after that
4630 * point. (Note that this check will certainly error out if s->blockState
4631 * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
4632 * below.)
4633 */
4635 ereport(ERROR,
4637 errmsg("cannot rollback to savepoints during a parallel operation")));
4638
4639 switch (s->blockState)
4640 {
4641 /*
4642 * We can't rollback to a savepoint if there is no savepoint
4643 * defined.
4644 */
4645 case TBLOCK_INPROGRESS:
4646 case TBLOCK_ABORT:
4647 ereport(ERROR,
4649 errmsg("savepoint \"%s\" does not exist", name)));
4650 break;
4651
4653 /* See comment about implicit transactions in DefineSavepoint */
4654 ereport(ERROR,
4656 /* translator: %s represents an SQL statement name */
4657 errmsg("%s can only be used in transaction blocks",
4658 "ROLLBACK TO SAVEPOINT")));
4659 break;
4660
4661 /*
4662 * There is at least one savepoint, so proceed.
4663 */
4665 case TBLOCK_SUBABORT:
4666 break;
4667
4668 /* These cases are invalid. */
4669 case TBLOCK_DEFAULT:
4670 case TBLOCK_STARTED:
4671 case TBLOCK_BEGIN:
4673 case TBLOCK_SUBBEGIN:
4674 case TBLOCK_END:
4675 case TBLOCK_SUBRELEASE:
4676 case TBLOCK_SUBCOMMIT:
4677 case TBLOCK_ABORT_END:
4681 case TBLOCK_SUBRESTART:
4683 case TBLOCK_PREPARE:
4684 elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4686 break;
4687 }
4688
4689 for (target = s; target; target = target->parent)
4690 {
4691 if (target->name && strcmp(target->name, name) == 0)
4692 break;
4693 }
4694
4695 if (!target)
4696 ereport(ERROR,
4698 errmsg("savepoint \"%s\" does not exist", name)));
4699
4700 /* disallow crossing savepoint level boundaries */
4701 if (target->savepointLevel != s->savepointLevel)
4702 ereport(ERROR,
4704 errmsg("savepoint \"%s\" does not exist within current savepoint level", name)));
4705
4706 /*
4707 * Mark "abort pending" all subtransactions up to the target
4708 * subtransaction. The actual aborts will happen when control gets to
4709 * CommitTransactionCommand.
4710 */
4712 for (;;)
4713 {
4714 if (xact == target)
4715 break;
4716 if (xact->blockState == TBLOCK_SUBINPROGRESS)
4718 else if (xact->blockState == TBLOCK_SUBABORT)
4719 xact->blockState = TBLOCK_SUBABORT_END;
4720 else
4721 elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4722 BlockStateAsString(xact->blockState));
4723 xact = xact->parent;
4724 Assert(xact);
4725 }
4726
4727 /* And mark the target as "restart pending" */
4728 if (xact->blockState == TBLOCK_SUBINPROGRESS)
4729 xact->blockState = TBLOCK_SUBRESTART;
4730 else if (xact->blockState == TBLOCK_SUBABORT)
4731 xact->blockState = TBLOCK_SUBABORT_RESTART;
4732 else
4733 elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4734 BlockStateAsString(xact->blockState));
4735}

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

5600{
5602 Size nxids = 0;
5603 Size i = 0;
5604 TransactionId *workspace;
5606
5608
5610 result->xactDeferrable = XactDeferrable;
5611 result->topFullTransactionId = XactTopFullTransactionId;
5612 result->currentFullTransactionId =
5614 result->currentCommandId = currentCommandId;
5615
5616 /*
5617 * If we're running in a parallel worker and launching a parallel worker
5618 * of our own, we can just pass along the information that was passed to
5619 * us.
5620 */
5621 if (nParallelCurrentXids > 0)
5622 {
5623 result->nParallelCurrentXids = nParallelCurrentXids;
5624 memcpy(&result->parallelCurrentXids[0], ParallelCurrentXids,
5626 return;
5627 }
5628
5629 /*
5630 * OK, we need to generate a sorted list of XIDs that our workers should
5631 * view as current. First, figure out how many there are.
5632 */
5633 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5634 {
5636 nxids = add_size(nxids, 1);
5638 }
5640 <= maxsize);
5641
5642 /* Copy them to our scratch space. */
5643 workspace = palloc(nxids * sizeof(TransactionId));
5644 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5645 {
5647 workspace[i++] = XidFromFullTransactionId(s->fullTransactionId);
5648 if (s->nChildXids > 0)
5649 memcpy(&workspace[i], s->childXids,
5650 s->nChildXids * sizeof(TransactionId));
5651 i += s->nChildXids;
5652 }
5653 Assert(i == nxids);
5654
5655 /* Sort them. */
5656 qsort(workspace, nxids, sizeof(TransactionId), xidComparator);
5657
5658 /* Copy data into output area. */
5659 result->nParallelCurrentXids = nxids;
5660 memcpy(&result->parallelCurrentXids[0], workspace,
5661 nxids * sizeof(TransactionId));
5662}
int i
Definition isn.c:77
void * palloc(Size size)
Definition mcxt.c:1390
#define qsort(a, b, c, d)
Definition port.h:496
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, currentCommandId, CurrentTransactionState, fb(), TransactionStateData::fullTransactionId, FullTransactionIdIsValid, i, memcpy(), TransactionStateData::nChildXids, nParallelCurrentXids, palloc(), ParallelCurrentXids, TransactionStateData::parent, qsort, result, SerializedTransactionStateHeaderSize, 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 3112 of file xact.c.

3113{
3115
3116 switch (s->blockState)
3117 {
3118 /*
3119 * if we aren't in a transaction block, we just do our usual start
3120 * transaction.
3121 */
3122 case TBLOCK_DEFAULT:
3125 break;
3126
3127 /*
3128 * We are somewhere in a transaction block or subtransaction and
3129 * about to start a new command. For now we do nothing, but
3130 * someday we may do command-local resource initialization. (Note
3131 * that any needed CommandCounterIncrement was done by the
3132 * previous CommitTransactionCommand.)
3133 */
3134 case TBLOCK_INPROGRESS:
3137 break;
3138
3139 /*
3140 * Here we are in a failed transaction block (one of the commands
3141 * caused an abort) so we do nothing but remain in the abort
3142 * state. Eventually we will get a ROLLBACK command which will
3143 * get us out of this state. (It is up to other code to ensure
3144 * that no commands other than ROLLBACK will be processed in these
3145 * states.)
3146 */
3147 case TBLOCK_ABORT:
3148 case TBLOCK_SUBABORT:
3149 break;
3150
3151 /* These cases are invalid. */
3152 case TBLOCK_STARTED:
3153 case TBLOCK_BEGIN:
3155 case TBLOCK_SUBBEGIN:
3156 case TBLOCK_END:
3157 case TBLOCK_SUBRELEASE:
3158 case TBLOCK_SUBCOMMIT:
3159 case TBLOCK_ABORT_END:
3163 case TBLOCK_SUBRESTART:
3165 case TBLOCK_PREPARE:
3166 elog(ERROR, "StartTransactionCommand: unexpected state %s",
3168 break;
3169 }
3170
3171 /*
3172 * We must switch to CurTransactionContext before returning. This is
3173 * already done if we called StartTransaction, otherwise not.
3174 */
3177}

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(), BuildDatabaseList(), BuildRelationList(), clear_subscription_skip_lsn(), copy_sequences(), DatabaseExists(), 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(), ProcessSingleRelationByOid(), ProcessSyncingTablesForApply(), ProcessSyncingTablesForSync(), ReindexMultipleInternal(), ReindexRelationConcurrently(), RemoveTempRelationsCallback(), ReorderBufferProcessTXN(), RepackWorkerMain(), 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 5057 of file xact.c.

5058{
5060
5061 switch (s->blockState)
5062 {
5063 case TBLOCK_DEFAULT:
5064 case TBLOCK_STARTED:
5065 return 'I'; /* idle --- not in transaction */
5066 case TBLOCK_BEGIN:
5067 case TBLOCK_SUBBEGIN:
5068 case TBLOCK_INPROGRESS:
5072 case TBLOCK_END:
5073 case TBLOCK_SUBRELEASE:
5074 case TBLOCK_SUBCOMMIT:
5075 case TBLOCK_PREPARE:
5076 return 'T'; /* in transaction */
5077 case TBLOCK_ABORT:
5078 case TBLOCK_SUBABORT:
5079 case TBLOCK_ABORT_END:
5083 case TBLOCK_SUBRESTART:
5085 return 'E'; /* in failed transaction */
5086 }
5087
5088 /* should never get here */
5089 elog(FATAL, "invalid transaction block state: %s",
5091 return 0; /* keep compiler quiet */
5092}

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

3932{
3933 SubXactCallbackItem *item;
3934 SubXactCallbackItem *prev;
3935
3936 prev = NULL;
3937 for (item = SubXact_callbacks; item; prev = item, item = item->next)
3938 {
3939 if (item->callback == callback && item->arg == arg)
3940 {
3941 if (prev)
3942 prev->next = item->next;
3943 else
3944 SubXact_callbacks = item->next;
3945 pfree(item);
3946 break;
3947 }
3948 }
3949}
void pfree(void *pointer)
Definition mcxt.c:1619

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

3872{
3873 XactCallbackItem *item;
3874 XactCallbackItem *prev;
3875
3876 prev = NULL;
3877 for (item = Xact_callbacks; item; prev = item, item = item->next)
3878 {
3879 if (item->callback == callback && item->arg == arg)
3880 {
3881 if (prev)
3882 prev->next = item->next;
3883 else
3884 Xact_callbacks = item->next;
3885 pfree(item);
3886 break;
3887 }
3888 }
3889}

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

◆ UserAbortTransactionBlock()

void UserAbortTransactionBlock ( bool  chain)
extern

Definition at line 4258 of file xact.c.

4259{
4261
4262 switch (s->blockState)
4263 {
4264 /*
4265 * We are inside a transaction block and we got a ROLLBACK command
4266 * from the user, so tell CommitTransactionCommand to abort and
4267 * exit the transaction block.
4268 */
4269 case TBLOCK_INPROGRESS:
4271 break;
4272
4273 /*
4274 * We are inside a failed transaction block and we got a ROLLBACK
4275 * command from the user. Abort processing is already done, so
4276 * CommitTransactionCommand just has to cleanup and go back to
4277 * idle state.
4278 */
4279 case TBLOCK_ABORT:
4281 break;
4282
4283 /*
4284 * We are inside a subtransaction. Mark everything up to top
4285 * level as exitable.
4286 */
4288 case TBLOCK_SUBABORT:
4289 while (s->parent != NULL)
4290 {
4293 else if (s->blockState == TBLOCK_SUBABORT)
4295 else
4296 elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4298 s = s->parent;
4299 }
4300 if (s->blockState == TBLOCK_INPROGRESS)
4302 else if (s->blockState == TBLOCK_ABORT)
4304 else
4305 elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4307 break;
4308
4309 /*
4310 * The user issued ABORT when not inside a transaction. For
4311 * ROLLBACK without CHAIN, issue a WARNING and go to abort state.
4312 * The upcoming call to CommitTransactionCommand() will then put
4313 * us back into the default state. For ROLLBACK AND CHAIN, error.
4314 *
4315 * We do the same thing with ABORT inside an implicit transaction,
4316 * although in this case we might be rolling back actual database
4317 * state changes. (It's debatable whether we should issue a
4318 * WARNING in this case, but we have done so historically.)
4319 */
4320 case TBLOCK_STARTED:
4322 if (chain)
4323 ereport(ERROR,
4325 /* translator: %s represents an SQL statement name */
4326 errmsg("%s can only be used in transaction blocks",
4327 "ROLLBACK AND CHAIN")));
4328 else
4331 errmsg("there is no transaction in progress")));
4333 break;
4334
4335 /*
4336 * The user issued an ABORT that somehow ran inside a parallel
4337 * worker. We can't cope with that.
4338 */
4340 ereport(FATAL,
4342 errmsg("cannot abort during a parallel operation")));
4343 break;
4344
4345 /* These cases are invalid. */
4346 case TBLOCK_DEFAULT:
4347 case TBLOCK_BEGIN:
4348 case TBLOCK_SUBBEGIN:
4349 case TBLOCK_END:
4350 case TBLOCK_SUBRELEASE:
4351 case TBLOCK_SUBCOMMIT:
4352 case TBLOCK_ABORT_END:
4356 case TBLOCK_SUBRESTART:
4358 case TBLOCK_PREPARE:
4359 elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
4361 break;
4362 }
4363
4366
4367 s->chain = chain;
4368}

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

3765{
3766 CheckTransactionBlock(isTopLevel, false, stmtType);
3767}

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:413
#define XLogRecGetInfo(decoder)
Definition xlogreader.h:410
#define XLogRecGetData(decoder)
Definition xlogreader.h:415

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

6423{
6424 uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
6425
6426 /* Backup blocks are not used in xact records */
6428
6429 if (info == XLOG_XACT_COMMIT)
6430 {
6433
6436 record->EndRecPtr, XLogRecGetOrigin(record));
6437 }
6438 else if (info == XLOG_XACT_COMMIT_PREPARED)
6439 {
6442
6444 xact_redo_commit(&parsed, parsed.twophase_xid,
6445 record->EndRecPtr, XLogRecGetOrigin(record));
6446
6447 /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6449 PrepareRedoRemove(parsed.twophase_xid, false);
6451 }
6452 else if (info == XLOG_XACT_ABORT)
6453 {
6456
6459 record->EndRecPtr, XLogRecGetOrigin(record));
6460 }
6461 else if (info == XLOG_XACT_ABORT_PREPARED)
6462 {
6465
6467 xact_redo_abort(&parsed, parsed.twophase_xid,
6468 record->EndRecPtr, XLogRecGetOrigin(record));
6469
6470 /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6472 PrepareRedoRemove(parsed.twophase_xid, false);
6474 }
6475 else if (info == XLOG_XACT_PREPARE)
6476 {
6477 /*
6478 * Store xid and start/end pointers of the WAL record in TwoPhaseState
6479 * gxact entry.
6480 */
6483 XLogRecGetData(record),
6484 record->ReadRecPtr,
6485 record->EndRecPtr,
6486 XLogRecGetOrigin(record));
6488 }
6489 else if (info == XLOG_XACT_ASSIGNMENT)
6490 {
6492
6495 xlrec->nsubxacts, xlrec->xsub);
6496 }
6497 else if (info == XLOG_XACT_INVALIDATIONS)
6498 {
6499 /*
6500 * XXX we do ignore this for now, what matters are invalidations
6501 * written into the commit record.
6502 */
6503 }
6504 else
6505 elog(PANIC, "xact_redo: unknown op code %u", info);
6506}
#define PANIC
Definition elog.h:44
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1150
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1767
@ LW_EXCLUSIVE
Definition lwlock.h:104
void ProcArrayApplyXidAssignment(TransactionId topxid, int nsubxids, TransactionId *subxids)
Definition procarray.c:1309
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:2513
void PrepareRedoRemove(TransactionId xid, bool giveWarning)
Definition twophase.c:2670
static void xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid, XLogRecPtr lsn, ReplOriginId origin_id)
Definition xact.c:6343
static void xact_redo_commit(xl_xact_parsed_commit *parsed, TransactionId xid, XLogRecPtr lsn, ReplOriginId origin_id)
Definition xact.c:6189
void ParseCommitRecord(uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *parsed)
Definition xactdesc.c:35
void ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
Definition xactdesc.c:141
#define XLogRecGetXid(decoder)
Definition xlogreader.h:412
#define XLogRecHasAnyBlockRefs(decoder)
Definition xlogreader.h:417
HotStandbyState standbyState
Definition xlogutils.c:53
@ STANDBY_INITIALIZED
Definition xlogutils.h:53

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

5850{
5852
5853 if (s->nChildXids == 0)
5854 *ptr = NULL;
5855 else
5856 *ptr = s->childXids;
5857
5858 return s->nChildXids;
5859}

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

6051{
6060
6061 uint8 info;
6062
6064
6065 xl_xinfo.xinfo = 0;
6066
6067 /* decide between a plain and 2pc abort */
6068 if (!TransactionIdIsValid(twophase_xid))
6069 info = XLOG_XACT_ABORT;
6070 else
6072
6073
6074 /* First figure out and collect all the information needed */
6075
6076 xlrec.xact_time = abort_time;
6077
6080
6081 if (nsubxacts > 0)
6082 {
6084 xl_subxacts.nsubxacts = nsubxacts;
6085 }
6086
6087 if (nrels > 0)
6088 {
6090 xl_relfilelocators.nrels = nrels;
6091 info |= XLR_SPECIAL_REL_UPDATE;
6092 }
6093
6094 if (ndroppedstats > 0)
6095 {
6098 }
6099
6100 if (TransactionIdIsValid(twophase_xid))
6101 {
6103 xl_twophase.xid = twophase_xid;
6104 Assert(twophase_gid != NULL);
6105
6108 }
6109
6110 if (TransactionIdIsValid(twophase_xid) && XLogLogicalInfoActive())
6111 {
6113 xl_dbinfo.dbId = MyDatabaseId;
6115 }
6116
6117 /*
6118 * Dump transaction origin information. We need this during recovery to
6119 * update the replication origin progress.
6120 */
6122 {
6124
6127 }
6128
6129 if (xl_xinfo.xinfo != 0)
6130 info |= XLOG_XACT_HAS_INFO;
6131
6132 /* Then include all the collected data into the abort record. */
6133
6135
6137
6138 if (xl_xinfo.xinfo != 0)
6140
6141 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
6143
6145 {
6148 XLogRegisterData(subxacts,
6149 nsubxacts * sizeof(TransactionId));
6150 }
6151
6153 {
6156 XLogRegisterData(rels,
6157 nrels * sizeof(RelFileLocator));
6158 }
6159
6161 {
6166 }
6167
6169 {
6171 if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
6172 XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
6173 }
6174
6175 if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
6177
6178 /* Include the replication origin */
6180
6181 return XLogInsert(RM_XACT_ID, info);
6182}
Oid MyDatabaseTableSpace
Definition globals.c:98
volatile uint32 CritSectionCount
Definition globals.c:45
Oid MyDatabaseId
Definition globals.c:96
ReplOriginXactState replorigin_xact_state
Definition origin.c:168
#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:166
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition xloginsert.c:482
void XLogRegisterData(const void *data, uint32 len)
Definition xloginsert.c:372
void XLogSetRecordFlags(uint8 flags)
Definition xloginsert.c:464
void XLogBeginInsert(void)
Definition xloginsert.c:153
#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 5873 of file xact.c.

5881{
5891 uint8 info;
5892
5894
5895 xl_xinfo.xinfo = 0;
5896
5897 /* decide between a plain and 2pc commit */
5898 if (!TransactionIdIsValid(twophase_xid))
5899 info = XLOG_XACT_COMMIT;
5900 else
5902
5903 /* First figure out and collect all the information needed */
5904
5905 xlrec.xact_time = commit_time;
5906
5907 if (relcacheInval)
5909 if (forceSyncCommit)
5913
5914 /*
5915 * Check if the caller would like to ask standbys for immediate feedback
5916 * once this commit is applied.
5917 */
5920
5921 /*
5922 * Relcache invalidations requires information about the current database
5923 * and so does logical decoding.
5924 */
5925 if (nmsgs > 0 || XLogLogicalInfoActive())
5926 {
5928 xl_dbinfo.dbId = MyDatabaseId;
5930 }
5931
5932 if (nsubxacts > 0)
5933 {
5935 xl_subxacts.nsubxacts = nsubxacts;
5936 }
5937
5938 if (nrels > 0)
5939 {
5941 xl_relfilelocators.nrels = nrels;
5942 info |= XLR_SPECIAL_REL_UPDATE;
5943 }
5944
5945 if (ndroppedstats > 0)
5946 {
5949 }
5950
5951 if (nmsgs > 0)
5952 {
5954 xl_invals.nmsgs = nmsgs;
5955 }
5956
5957 if (TransactionIdIsValid(twophase_xid))
5958 {
5960 xl_twophase.xid = twophase_xid;
5961 Assert(twophase_gid != NULL);
5962
5965 }
5966
5967 /* dump transaction origin information */
5969 {
5971
5974 }
5975
5976 if (xl_xinfo.xinfo != 0)
5977 info |= XLOG_XACT_HAS_INFO;
5978
5979 /* Then include all the collected data into the commit record. */
5980
5982
5984
5985 if (xl_xinfo.xinfo != 0)
5986 XLogRegisterData(&xl_xinfo.xinfo, sizeof(xl_xinfo.xinfo));
5987
5988 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5990
5992 {
5995 XLogRegisterData(subxacts,
5996 nsubxacts * sizeof(TransactionId));
5997 }
5998
6000 {
6003 XLogRegisterData(rels,
6004 nrels * sizeof(RelFileLocator));
6005 }
6006
6008 {
6013 }
6014
6015 if (xl_xinfo.xinfo & XACT_XINFO_HAS_INVALS)
6016 {
6018 XLogRegisterData(msgs,
6019 nmsgs * sizeof(SharedInvalidationMessage));
6020 }
6021
6023 {
6025 if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
6026 XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
6027 }
6028
6029 if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
6031
6032 /* we allow filtering by xacts */
6034
6035 return XLogInsert(RM_XACT_ID, info);
6036}
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