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:622
uint32 SubTransactionId
Definition c.h:740
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:558
int32_t int32
Definition c.h:620
uint16_t uint16
Definition c.h:623
uint32_t uint32
Definition c.h:624
uint32 CommandId
Definition c.h:750
uint32 TransactionId
Definition c.h:736
size_t Size
Definition c.h:689
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:5040
void SerializeTransactionState(Size maxsize, char *start_address)
Definition xact.c:5591
void ExitParallelMode(void)
Definition xact.c:1094
const char * xact_identify(uint8 info)
Definition xactdesc.c:487
void SaveTransactionCharacteristics(SavedTransactionCharacteristics *s)
Definition xact.c:3186
void BeginInternalSubTransaction(const char *name)
Definition xact.c:4745
FullTransactionId GetCurrentFullTransactionId(void)
Definition xact.c:514
void RestoreTransactionCharacteristics(const SavedTransactionCharacteristics *s)
Definition xact.c:3194
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition xact.c:3761
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:4255
bool IsInTransactionBlock(bool isTopLevel)
Definition xact.c:3820
bool PrepareTransactionBlock(const char *gid)
Definition xact.c:4043
int GetCurrentTransactionNestLevel(void)
Definition xact.c:931
void xact_redo(XLogReaderState *record)
Definition xact.c:6414
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:3928
void BeginImplicitTransactionBlock(void)
Definition xact.c:4377
void(* XactCallback)(XactEvent event, void *arg)
Definition xact.h:139
void RequireTransactionBlock(bool isTopLevel, const char *stmtType)
Definition xact.c:3767
void DefineSavepoint(const char *name)
Definition xact.c:4424
void UnregisterXactCallback(XactCallback callback, void *arg)
Definition xact.c:3868
bool IsTransactionState(void)
Definition xact.c:389
void CommandCounterIncrement(void)
Definition xact.c:1130
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition xact.c:3698
Size EstimateTransactionStateSpace(void)
Definition xact.c:5563
TransactionId GetTopTransactionIdIfAny(void)
Definition xact.c:443
#define GIDSIZE
Definition xact.h:31
char TransactionBlockStatusCode(void)
Definition xact.c:5054
void RollbackAndReleaseCurrentSubTransaction(void)
Definition xact.c:4847
FullTransactionId GetCurrentFullTransactionIdIfAny(void)
Definition xact.c:532
void StartTransactionCommand(void)
Definition xact.c:3109
bool IsAbortedTransactionBlockState(void)
Definition xact.c:409
void ReleaseCurrentSubTransaction(void)
Definition xact.c:4819
void EndImplicitTransactionBlock(void)
Definition xact.c:4402
void StartParallelWorkerTransaction(char *tstatespace)
Definition xact.c:5662
void SetParallelStartTimestamps(TimestampTz xact_ts, TimestampTz stmt_ts)
Definition xact.c:861
void ReleaseSavepoint(const char *name)
Definition xact.c:4509
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:5865
void ForceSyncCommit(void)
Definition xact.c:1182
int GetTopReadOnlyTransactionNestLevel(void)
Definition xact.c:1062
bool IsSubTransaction(void)
Definition xact.c:5095
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:5022
bool IsInParallelMode(void)
Definition xact.c:1119
int xactGetCommittedChildren(TransactionId **ptr)
Definition xact.c:5841
TransactionId GetCurrentTransactionIdIfAny(void)
Definition xact.c:473
void BeginTransactionBlock(void)
Definition xact.c:3975
TimestampTz GetCurrentStatementStartTimestamp(void)
Definition xact.c:881
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition xact.c:872
void EndParallelWorkerTransaction(void)
Definition xact.c:5687
void RegisterXactCallback(XactCallback callback, void *arg)
Definition xact.c:3855
void CommitTransactionCommand(void)
Definition xact.c:3207
void RollbackToSavepoint(const char *name)
Definition xact.c:4618
bool SubTransactionIsActive(SubTransactionId subxid)
Definition xact.c:807
void RegisterSubXactCallback(SubXactCallback callback, void *arg)
Definition xact.c:3915
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:4095
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:4913
void AbortCurrentTransaction(void)
Definition xact.c:3501
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:6037
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 3501 of file xact.c.

3502{
3503 /*
3504 * Repeatedly call AbortCurrentTransactionInternal() until all the work is
3505 * done.
3506 */
3508 {
3509 }
3510}
static bool AbortCurrentTransactionInternal(void)
Definition xact.c:3519

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

4914{
4916
4917 /* Ensure we're not running in a doomed memory context */
4919
4920 /*
4921 * Get out of any transaction or nested transaction
4922 */
4923 do
4924 {
4925 switch (s->blockState)
4926 {
4927 case TBLOCK_DEFAULT:
4928 if (s->state == TRANS_DEFAULT)
4929 {
4930 /* Not in a transaction, do nothing */
4931 }
4932 else
4933 {
4934 /*
4935 * We can get here after an error during transaction start
4936 * (state will be TRANS_START). Need to clean up the
4937 * incompletely started transaction. First, adjust the
4938 * low-level state to suppress warning message from
4939 * AbortTransaction.
4940 */
4941 if (s->state == TRANS_START)
4945 }
4946 break;
4947 case TBLOCK_STARTED:
4948 case TBLOCK_BEGIN:
4949 case TBLOCK_INPROGRESS:
4952 case TBLOCK_END:
4954 case TBLOCK_PREPARE:
4955 /* In a transaction, so clean up */
4959 break;
4960 case TBLOCK_ABORT:
4961 case TBLOCK_ABORT_END:
4962
4963 /*
4964 * AbortTransaction is already done, still need Cleanup.
4965 * However, if we failed partway through running ROLLBACK,
4966 * there will be an active portal running that command, which
4967 * we need to shut down before doing CleanupTransaction.
4968 */
4972 break;
4973
4974 /*
4975 * In a subtransaction, so clean it up and abort parent too
4976 */
4977 case TBLOCK_SUBBEGIN:
4979 case TBLOCK_SUBRELEASE:
4980 case TBLOCK_SUBCOMMIT:
4982 case TBLOCK_SUBRESTART:
4985 s = CurrentTransactionState; /* changed by pop */
4986 break;
4987
4988 case TBLOCK_SUBABORT:
4991 /* As above, but AbortSubTransaction already done */
4992 if (s->curTransactionOwner)
4993 {
4994 /* As in TBLOCK_ABORT, might have a live portal to zap */
4999 }
5001 s = CurrentTransactionState; /* changed by pop */
5002 break;
5003 }
5004 } while (s->blockState != TBLOCK_DEFAULT);
5005
5006 /* Should be out of all subxacts now */
5007 Assert(s->parent == NULL);
5008
5009 /*
5010 * Revert to TopMemoryContext, to ensure we exit in a well-defined state
5011 * whether there were any transactions to close or not. (Callers that
5012 * don't intend to exit soon should switch to some other context to avoid
5013 * long-term memory leaks.)
5014 */
5016}
#define Assert(condition)
Definition c.h:943
MemoryContext TopMemoryContext
Definition mcxt.c:166
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
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:5434
static void CleanupTransaction(void)
Definition xact.c:3059
@ 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:5270
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:2853
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 4377 of file xact.c.

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

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

4746{
4749
4750 /*
4751 * Errors within this function are improbable, but if one does happen we
4752 * force a FATAL exit. Callers generally aren't prepared to handle losing
4753 * control, and moreover our transaction state is probably corrupted if we
4754 * fail partway through; so an ordinary ERROR longjmp isn't okay.
4755 */
4756 ExitOnAnyError = true;
4757
4758 /*
4759 * We do not check for parallel mode here. It's permissible to start and
4760 * end "internal" subtransactions while in parallel mode, so long as no
4761 * new XIDs or command IDs are assigned. Enforcement of that occurs in
4762 * AssignTransactionId() and CommandCounterIncrement().
4763 */
4764
4765 switch (s->blockState)
4766 {
4767 case TBLOCK_STARTED:
4768 case TBLOCK_INPROGRESS:
4771 case TBLOCK_END:
4772 case TBLOCK_PREPARE:
4774 /* Normal subtransaction start */
4776 s = CurrentTransactionState; /* changed by push */
4777
4778 /*
4779 * Savepoint names, like the TransactionState block itself, live
4780 * in TopTransactionContext.
4781 */
4782 if (name)
4784 break;
4785
4786 /* These cases are invalid. */
4787 case TBLOCK_DEFAULT:
4788 case TBLOCK_BEGIN:
4789 case TBLOCK_SUBBEGIN:
4790 case TBLOCK_SUBRELEASE:
4791 case TBLOCK_SUBCOMMIT:
4792 case TBLOCK_ABORT:
4793 case TBLOCK_SUBABORT:
4794 case TBLOCK_ABORT_END:
4798 case TBLOCK_SUBRESTART:
4800 elog(FATAL, "BeginInternalSubTransaction: unexpected state %s",
4802 break;
4803 }
4804
4807
4809}
#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:1768
MemoryContext TopTransactionContext
Definition mcxt.c:171
static void PushTransaction(void)
Definition xact.c:5467
void StartTransactionCommand(void)
Definition xact.c:3109
static const char * BlockStateAsString(TBlockState blockState)
Definition xact.c:5758
void CommitTransactionCommand(void)
Definition xact.c:3207

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

3976{
3978
3979 switch (s->blockState)
3980 {
3981 /*
3982 * We are not inside a transaction block, so allow one to begin.
3983 */
3984 case TBLOCK_STARTED:
3986 break;
3987
3988 /*
3989 * BEGIN converts an implicit transaction block to a regular one.
3990 * (Note that we allow this even if we've already done some
3991 * commands, which is a bit odd but matches historical practice.)
3992 */
3995 break;
3996
3997 /*
3998 * Already a transaction block in progress.
3999 */
4000 case TBLOCK_INPROGRESS:
4003 case TBLOCK_ABORT:
4004 case TBLOCK_SUBABORT:
4007 errmsg("there is already a transaction in progress")));
4008 break;
4009
4010 /* These cases are invalid. */
4011 case TBLOCK_DEFAULT:
4012 case TBLOCK_BEGIN:
4013 case TBLOCK_SUBBEGIN:
4014 case TBLOCK_END:
4015 case TBLOCK_SUBRELEASE:
4016 case TBLOCK_SUBCOMMIT:
4017 case TBLOCK_ABORT_END:
4021 case TBLOCK_SUBRESTART:
4023 case TBLOCK_PREPARE:
4024 elog(FATAL, "BeginTransactionBlock: unexpected state %s",
4026 break;
4027 }
4028}
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:753
#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_index_constraints(), copy_table_data(), 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(), 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 3207 of file xact.c.

3208{
3209 /*
3210 * Repeatedly call CommitTransactionCommandInternal() until all the work
3211 * is done.
3212 */
3214 {
3215 }
3216}
static bool CommitTransactionCommandInternal(void)
Definition xact.c:3225

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

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

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

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

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

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

5564{
5566 Size nxids = 0;
5568
5569 for (s = CurrentTransactionState; s != NULL; s = s->parent)
5570 {
5572 nxids = add_size(nxids, 1);
5574 }
5575
5576 return add_size(size, mul_size(sizeof(TransactionId), nxids));
5577}
Size add_size(Size s1, Size s2)
Definition shmem.c:1048
Size mul_size(Size s1, Size s2)
Definition shmem.c:1063
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:1639
#define PG_USED_FOR_ASSERTS_ONLY
Definition c.h:249
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:738
#define InvalidLocalTransactionId
Definition lock.h:68
PGPROC * MyProc
Definition proc.c:71
LocalTransactionId lxid
Definition proc.h:231
struct PGPROC::@136 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 3820 of file xact.c.

3821{
3822 /*
3823 * Return true on same conditions that would make
3824 * PreventInTransactionBlock error out
3825 */
3826 if (IsTransactionBlock())
3827 return true;
3828
3829 if (IsSubTransaction())
3830 return true;
3831
3832 if (!isTopLevel)
3833 return true;
3834
3837 return true;
3838
3839 return false;
3840}
bool IsSubTransaction(void)
Definition xact.c:5095
bool IsTransactionBlock(void)
Definition xact.c:5022

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

References fb(), and MAXALIGN.

Referenced by xact_decode(), and xact_desc_prepare().

◆ PrepareTransactionBlock()

bool PrepareTransactionBlock ( const char gid)
extern

Definition at line 4043 of file xact.c.

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

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

3699{
3700 /*
3701 * xact block already started?
3702 */
3703 if (IsTransactionBlock())
3704 ereport(ERROR,
3706 /* translator: %s represents an SQL statement name */
3707 errmsg("%s cannot run inside a transaction block",
3708 stmtType)));
3709
3710 /*
3711 * subtransaction?
3712 */
3713 if (IsSubTransaction())
3714 ereport(ERROR,
3716 /* translator: %s represents an SQL statement name */
3717 errmsg("%s cannot run inside a subtransaction",
3718 stmtType)));
3719
3720 /*
3721 * inside a function call?
3722 */
3723 if (!isTopLevel)
3724 ereport(ERROR,
3726 /* translator: %s represents an SQL statement name */
3727 errmsg("%s cannot be executed from a function or procedure",
3728 stmtType)));
3729
3730 /* If we got past IsTransactionBlock test, should be in default state */
3733 elog(FATAL, "cannot prevent transaction chain");
3734
3735 /* All okay. Set the flag to make sure the right thing happens later. */
3737}
int MyXactFlags
Definition xact.c:138
#define XACT_FLAGS_NEEDIMMEDIATECOMMIT
Definition xact.h:115

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

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

◆ RegisterSubXactCallback()

void RegisterSubXactCallback ( SubXactCallback  callback,
void arg 
)
extern

Definition at line 3915 of file xact.c.

3916{
3917 SubXactCallbackItem *item;
3918
3919 item = (SubXactCallbackItem *)
3921 item->callback = callback;
3922 item->arg = arg;
3923 item->next = SubXact_callbacks;
3924 SubXact_callbacks = item;
3925}
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1232
struct SubXactCallbackItem * next
Definition xact.c:324
SubXactCallback callback
Definition xact.c:325
static SubXactCallbackItem * SubXact_callbacks
Definition xact.c:329

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

Referenced by _PG_init(), GetConnection(), ri_FastPathGetEntry(), and sepgsql_init_client_label().

◆ RegisterXactCallback()

void RegisterXactCallback ( XactCallback  callback,
void arg 
)
extern

Definition at line 3855 of file xact.c.

3856{
3857 XactCallbackItem *item;
3858
3859 item = (XactCallbackItem *)
3861 item->callback = callback;
3862 item->arg = arg;
3863 item->next = Xact_callbacks;
3864 Xact_callbacks = item;
3865}
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(), ri_FastPathGetEntry(), and sepgsql_init_client_label().

◆ ReleaseCurrentSubTransaction()

void ReleaseCurrentSubTransaction ( void  )
extern

Definition at line 4819 of file xact.c.

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

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

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

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

3768{
3769 CheckTransactionBlock(isTopLevel, true, stmtType);
3770}
static void CheckTransactionBlock(bool isTopLevel, bool throwError, const char *stmtType)
Definition xact.c:3776

References CheckTransactionBlock(), and fb().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

◆ RestoreTransactionCharacteristics()

◆ RollbackAndReleaseCurrentSubTransaction()

void RollbackAndReleaseCurrentSubTransaction ( void  )
extern

Definition at line 4847 of file xact.c.

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

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

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

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

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

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

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

5055{
5057
5058 switch (s->blockState)
5059 {
5060 case TBLOCK_DEFAULT:
5061 case TBLOCK_STARTED:
5062 return 'I'; /* idle --- not in transaction */
5063 case TBLOCK_BEGIN:
5064 case TBLOCK_SUBBEGIN:
5065 case TBLOCK_INPROGRESS:
5069 case TBLOCK_END:
5070 case TBLOCK_SUBRELEASE:
5071 case TBLOCK_SUBCOMMIT:
5072 case TBLOCK_PREPARE:
5073 return 'T'; /* in transaction */
5074 case TBLOCK_ABORT:
5075 case TBLOCK_SUBABORT:
5076 case TBLOCK_ABORT_END:
5080 case TBLOCK_SUBRESTART:
5082 return 'E'; /* in failed transaction */
5083 }
5084
5085 /* should never get here */
5086 elog(FATAL, "invalid transaction block state: %s",
5088 return 0; /* keep compiler quiet */
5089}

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

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

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

◆ UnregisterXactCallback()

void UnregisterXactCallback ( XactCallback  callback,
void arg 
)
extern

Definition at line 3868 of file xact.c.

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

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

◆ UserAbortTransactionBlock()

void UserAbortTransactionBlock ( bool  chain)
extern

Definition at line 4255 of file xact.c.

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

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

3762{
3763 CheckTransactionBlock(isTopLevel, false, stmtType);
3764}

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

6415{
6416 uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
6417
6418 /* Backup blocks are not used in xact records */
6420
6421 if (info == XLOG_XACT_COMMIT)
6422 {
6425
6428 record->EndRecPtr, XLogRecGetOrigin(record));
6429 }
6430 else if (info == XLOG_XACT_COMMIT_PREPARED)
6431 {
6434
6436 xact_redo_commit(&parsed, parsed.twophase_xid,
6437 record->EndRecPtr, XLogRecGetOrigin(record));
6438
6439 /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6441 PrepareRedoRemove(parsed.twophase_xid, false);
6443 }
6444 else if (info == XLOG_XACT_ABORT)
6445 {
6448
6451 record->EndRecPtr, XLogRecGetOrigin(record));
6452 }
6453 else if (info == XLOG_XACT_ABORT_PREPARED)
6454 {
6457
6459 xact_redo_abort(&parsed, parsed.twophase_xid,
6460 record->EndRecPtr, XLogRecGetOrigin(record));
6461
6462 /* Delete TwoPhaseState gxact entry and/or 2PC file. */
6464 PrepareRedoRemove(parsed.twophase_xid, false);
6466 }
6467 else if (info == XLOG_XACT_PREPARE)
6468 {
6469 /*
6470 * Store xid and start/end pointers of the WAL record in TwoPhaseState
6471 * gxact entry.
6472 */
6475 XLogRecGetData(record),
6476 record->ReadRecPtr,
6477 record->EndRecPtr,
6478 XLogRecGetOrigin(record));
6480 }
6481 else if (info == XLOG_XACT_ASSIGNMENT)
6482 {
6484
6487 xlrec->nsubxacts, xlrec->xsub);
6488 }
6489 else if (info == XLOG_XACT_INVALIDATIONS)
6490 {
6491 /*
6492 * XXX we do ignore this for now, what matters are invalidations
6493 * written into the commit record.
6494 */
6495 }
6496 else
6497 elog(PANIC, "xact_redo: unknown op code %u", info);
6498}
#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:6335
static void xact_redo_commit(xl_xact_parsed_commit *parsed, TransactionId xid, XLogRecPtr lsn, ReplOriginId origin_id)
Definition xact.c:6181
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 5841 of file xact.c.

5842{
5844
5845 if (s->nChildXids == 0)
5846 *ptr = NULL;
5847 else
5848 *ptr = s->childXids;
5849
5850 return s->nChildXids;
5851}

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

6043{
6052
6053 uint8 info;
6054
6056
6057 xl_xinfo.xinfo = 0;
6058
6059 /* decide between a plain and 2pc abort */
6060 if (!TransactionIdIsValid(twophase_xid))
6061 info = XLOG_XACT_ABORT;
6062 else
6064
6065
6066 /* First figure out and collect all the information needed */
6067
6068 xlrec.xact_time = abort_time;
6069
6072
6073 if (nsubxacts > 0)
6074 {
6076 xl_subxacts.nsubxacts = nsubxacts;
6077 }
6078
6079 if (nrels > 0)
6080 {
6082 xl_relfilelocators.nrels = nrels;
6083 info |= XLR_SPECIAL_REL_UPDATE;
6084 }
6085
6086 if (ndroppedstats > 0)
6087 {
6090 }
6091
6092 if (TransactionIdIsValid(twophase_xid))
6093 {
6095 xl_twophase.xid = twophase_xid;
6096 Assert(twophase_gid != NULL);
6097
6100 }
6101
6102 if (TransactionIdIsValid(twophase_xid) && XLogLogicalInfoActive())
6103 {
6105 xl_dbinfo.dbId = MyDatabaseId;
6107 }
6108
6109 /*
6110 * Dump transaction origin information. We need this during recovery to
6111 * update the replication origin progress.
6112 */
6114 {
6116
6119 }
6120
6121 if (xl_xinfo.xinfo != 0)
6122 info |= XLOG_XACT_HAS_INFO;
6123
6124 /* Then include all the collected data into the abort record. */
6125
6127
6129
6130 if (xl_xinfo.xinfo != 0)
6132
6133 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
6135
6137 {
6140 XLogRegisterData(subxacts,
6141 nsubxacts * sizeof(TransactionId));
6142 }
6143
6145 {
6148 XLogRegisterData(rels,
6149 nrels * sizeof(RelFileLocator));
6150 }
6151
6153 {
6158 }
6159
6161 {
6163 if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
6164 XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
6165 }
6166
6167 if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
6169
6170 /* Include the replication origin */
6172
6173 return XLogInsert(RM_XACT_ID, info);
6174}
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 5865 of file xact.c.

5873{
5883 uint8 info;
5884
5886
5887 xl_xinfo.xinfo = 0;
5888
5889 /* decide between a plain and 2pc commit */
5890 if (!TransactionIdIsValid(twophase_xid))
5891 info = XLOG_XACT_COMMIT;
5892 else
5894
5895 /* First figure out and collect all the information needed */
5896
5897 xlrec.xact_time = commit_time;
5898
5899 if (relcacheInval)
5901 if (forceSyncCommit)
5905
5906 /*
5907 * Check if the caller would like to ask standbys for immediate feedback
5908 * once this commit is applied.
5909 */
5912
5913 /*
5914 * Relcache invalidations requires information about the current database
5915 * and so does logical decoding.
5916 */
5917 if (nmsgs > 0 || XLogLogicalInfoActive())
5918 {
5920 xl_dbinfo.dbId = MyDatabaseId;
5922 }
5923
5924 if (nsubxacts > 0)
5925 {
5927 xl_subxacts.nsubxacts = nsubxacts;
5928 }
5929
5930 if (nrels > 0)
5931 {
5933 xl_relfilelocators.nrels = nrels;
5934 info |= XLR_SPECIAL_REL_UPDATE;
5935 }
5936
5937 if (ndroppedstats > 0)
5938 {
5941 }
5942
5943 if (nmsgs > 0)
5944 {
5946 xl_invals.nmsgs = nmsgs;
5947 }
5948
5949 if (TransactionIdIsValid(twophase_xid))
5950 {
5952 xl_twophase.xid = twophase_xid;
5953 Assert(twophase_gid != NULL);
5954
5957 }
5958
5959 /* dump transaction origin information */
5961 {
5963
5966 }
5967
5968 if (xl_xinfo.xinfo != 0)
5969 info |= XLOG_XACT_HAS_INFO;
5970
5971 /* Then include all the collected data into the commit record. */
5972
5974
5976
5977 if (xl_xinfo.xinfo != 0)
5978 XLogRegisterData(&xl_xinfo.xinfo, sizeof(xl_xinfo.xinfo));
5979
5980 if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5982
5984 {
5987 XLogRegisterData(subxacts,
5988 nsubxacts * sizeof(TransactionId));
5989 }
5990
5992 {
5995 XLogRegisterData(rels,
5996 nrels * sizeof(RelFileLocator));
5997 }
5998
6000 {
6005 }
6006
6007 if (xl_xinfo.xinfo & XACT_XINFO_HAS_INVALS)
6008 {
6010 XLogRegisterData(msgs,
6011 nmsgs * sizeof(SharedInvalidationMessage));
6012 }
6013
6015 {
6017 if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
6018 XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
6019 }
6020
6021 if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
6023
6024 /* we allow filtering by xacts */
6026
6027 return XLogInsert(RM_XACT_ID, info);
6028}
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