PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
xact.h File Reference
#include "access/xlogreader.h"
#include "lib/stringinfo.h"
#include "nodes/pg_list.h"
#include "storage/relfilenode.h"
#include "storage/sinval.h"
#include "utils/datetime.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  xl_xact_assignment
 
struct  xl_xact_xinfo
 
struct  xl_xact_dbinfo
 
struct  xl_xact_subxacts
 
struct  xl_xact_relfilenodes
 
struct  xl_xact_invals
 
struct  xl_xact_twophase
 
struct  xl_xact_origin
 
struct  xl_xact_commit
 
struct  xl_xact_abort
 
struct  xl_xact_parsed_commit
 
struct  xl_xact_parsed_abort
 

Macros

#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 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_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_RELFILENODES   (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_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 MinSizeOfXactRelfilenodes   offsetof(xl_xact_relfilenodes, xnodes)
 
#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 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_relfilenodes xl_xact_relfilenodes
 
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_parsed_commit 
xl_xact_parsed_commit
 
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)
 
void MarkCurrentTransactionIdLoggedIfAny (void)
 
bool SubTransactionIsActive (SubTransactionId subxid)
 
CommandId GetCurrentCommandId (bool used)
 
TimestampTz GetCurrentTransactionStartTimestamp (void)
 
TimestampTz GetCurrentStatementStartTimestamp (void)
 
TimestampTz GetCurrentTransactionStopTimestamp (void)
 
void SetCurrentStatementStartTimestamp (void)
 
int GetCurrentTransactionNestLevel (void)
 
bool TransactionIdIsCurrentTransactionId (TransactionId xid)
 
void CommandCounterIncrement (void)
 
void ForceSyncCommit (void)
 
void StartTransactionCommand (void)
 
void CommitTransactionCommand (void)
 
void AbortCurrentTransaction (void)
 
void BeginTransactionBlock (void)
 
bool EndTransactionBlock (void)
 
bool PrepareTransactionBlock (char *gid)
 
void UserAbortTransactionBlock (void)
 
void ReleaseSavepoint (List *options)
 
void DefineSavepoint (char *name)
 
void RollbackToSavepoint (List *options)
 
void BeginInternalSubTransaction (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 PreventTransactionChain (bool isTopLevel, const char *stmtType)
 
void RequireTransactionChain (bool isTopLevel, const char *stmtType)
 
void WarnNoTransactionChain (bool isTopLevel, const char *stmtType)
 
bool IsInTransactionChain (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)
 
int xactGetCommittedChildren (TransactionId **ptr)
 
XLogRecPtr XactLogCommitRecord (TimestampTz commit_time, int nsubxacts, TransactionId *subxacts, int nrels, RelFileNode *rels, int nmsgs, SharedInvalidationMessage *msgs, bool relcacheInval, bool forceSync, TransactionId twophase_xid)
 
XLogRecPtr XactLogAbortRecord (TimestampTz abort_time, int nsubxacts, TransactionId *subxacts, int nrels, RelFileNode *rels, TransactionId twophase_xid)
 
void xact_redo (XLogReaderState *record)
 
void xact_desc (StringInfo buf, XLogReaderState *record)
 
const char * xact_identify (uint8 info)
 
void ParseCommitRecord (uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *parsed)
 
void ParseAbortRecord (uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
 
void EnterParallelMode (void)
 
void ExitParallelMode (void)
 
bool IsInParallelMode (void)
 

Variables

int DefaultXactIsoLevel
 
PGDLLIMPORT int XactIsoLevel
 
bool DefaultXactReadOnly
 
bool XactReadOnly
 
bool DefaultXactDeferrable
 
bool XactDeferrable
 
int synchronous_commit
 
bool MyXactAccessedTempRel
 

Macro Definition Documentation

#define MinSizeOfXactAbort   sizeof(xl_xact_abort)

Definition at line 260 of file xact.h.

Referenced by ParseAbortRecord(), and XactLogAbortRecord().

#define MinSizeOfXactAssignment   offsetof(xl_xact_assignment, xsub)

Definition at line 168 of file xact.h.

Referenced by AssignTransactionId().

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

Definition at line 247 of file xact.h.

Referenced by ParseCommitRecord().

#define MinSizeOfXactInvals   offsetof(xl_xact_invals, msgs)

Definition at line 222 of file xact.h.

Referenced by ParseCommitRecord(), and XactLogCommitRecord().

#define MinSizeOfXactRelfilenodes   offsetof(xl_xact_relfilenodes, xnodes)
#define MinSizeOfXactSubxacts   offsetof(xl_xact_subxacts, subxacts)
#define SYNCHRONOUS_COMMIT_ON   SYNCHRONOUS_COMMIT_REMOTE_FLUSH

Definition at line 69 of file xact.h.

#define XACT_COMPLETION_APPLY_FEEDBACK   (1U << 29)

Definition at line 149 of file xact.h.

Referenced by XactLogCommitRecord().

#define XACT_COMPLETION_FORCE_SYNC_COMMIT   (1U << 31)

Definition at line 151 of file xact.h.

Referenced by XactLogCommitRecord().

#define XACT_COMPLETION_UPDATE_RELCACHE_FILE   (1U << 30)

Definition at line 150 of file xact.h.

Referenced by XactLogCommitRecord().

#define XACT_READ_COMMITTED   1

Definition at line 29 of file xact.h.

Referenced by check_XactIsoLevel(), InitPostgres(), and show_XactIsoLevel().

#define XACT_READ_UNCOMMITTED   0

Definition at line 28 of file xact.h.

Referenced by check_XactIsoLevel(), and show_XactIsoLevel().

#define XACT_REPEATABLE_READ   2

Definition at line 30 of file xact.h.

Referenced by check_XactIsoLevel(), show_XactIsoLevel(), and SnapBuildExportSnapshot().

#define XACT_SERIALIZABLE   3

Definition at line 31 of file xact.h.

Referenced by check_XactIsoLevel(), ImportSnapshot(), and show_XactIsoLevel().

#define XACT_XINFO_HAS_DBINFO   (1U << 0)

Definition at line 134 of file xact.h.

Referenced by ParseCommitRecord(), and XactLogCommitRecord().

#define XACT_XINFO_HAS_INVALS   (1U << 3)

Definition at line 137 of file xact.h.

Referenced by ParseCommitRecord(), and XactLogCommitRecord().

#define XACT_XINFO_HAS_ORIGIN   (1U << 5)
#define XACT_XINFO_HAS_RELFILENODES   (1U << 2)
#define XACT_XINFO_HAS_SUBXACTS   (1U << 1)
#define XACT_XINFO_HAS_TWOPHASE   (1U << 4)
#define XactCompletionApplyFeedback (   xinfo)    ((xinfo & XACT_COMPLETION_APPLY_FEEDBACK) != 0)

Definition at line 154 of file xact.h.

Referenced by xact_redo_commit().

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

Definition at line 158 of file xact.h.

Referenced by xact_desc_commit(), and xact_redo_commit().

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

Definition at line 156 of file xact.h.

Referenced by xact_desc_commit(), and xact_redo_commit().

#define XLOG_XACT_ABORT   0x20
#define XLOG_XACT_ABORT_PREPARED   0x40
#define XLOG_XACT_ASSIGNMENT   0x50

Definition at line 120 of file xact.h.

Referenced by AssignTransactionId(), DecodeXactOp(), xact_desc(), xact_identify(), and xact_redo().

#define XLOG_XACT_COMMIT_PREPARED   0x30
#define XLOG_XACT_HAS_INFO   0x80
#define XLOG_XACT_PREPARE   0x10

Definition at line 116 of file xact.h.

Referenced by DecodeXactOp(), EndPrepare(), xact_identify(), xact_redo(), and XlogReadTwoPhaseData().

Typedef Documentation

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

Definition at line 102 of file xact.h.

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

Definition at line 92 of file xact.h.

Enumeration Type Documentation

Enumerator
SUBXACT_EVENT_START_SUB 
SUBXACT_EVENT_COMMIT_SUB 
SUBXACT_EVENT_ABORT_SUB 
SUBXACT_EVENT_PRE_COMMIT_SUB 

Definition at line 94 of file xact.h.

Enumerator
SYNCHRONOUS_COMMIT_OFF 
SYNCHRONOUS_COMMIT_LOCAL_FLUSH 
SYNCHRONOUS_COMMIT_REMOTE_WRITE 
SYNCHRONOUS_COMMIT_REMOTE_FLUSH 
SYNCHRONOUS_COMMIT_REMOTE_APPLY 

Definition at line 57 of file xact.h.

58 {
59  SYNCHRONOUS_COMMIT_OFF, /* asynchronous commit */
60  SYNCHRONOUS_COMMIT_LOCAL_FLUSH, /* wait for local flush only */
61  SYNCHRONOUS_COMMIT_REMOTE_WRITE, /* wait for local flush and remote
62  * write */
63  SYNCHRONOUS_COMMIT_REMOTE_FLUSH, /* wait for local and remote flush */
64  SYNCHRONOUS_COMMIT_REMOTE_APPLY /* wait for local flush and remote
65  * apply */
SyncCommitLevel
Definition: xact.h:57
enum XactEvent
Enumerator
XACT_EVENT_COMMIT 
XACT_EVENT_PARALLEL_COMMIT 
XACT_EVENT_ABORT 
XACT_EVENT_PARALLEL_ABORT 
XACT_EVENT_PREPARE 
XACT_EVENT_PRE_COMMIT 
XACT_EVENT_PARALLEL_PRE_COMMIT 
XACT_EVENT_PRE_PREPARE 

Definition at line 80 of file xact.h.

Function Documentation

void AbortCurrentTransaction ( void  )

Definition at line 2984 of file xact.c.

References AbortCurrentTransaction(), AbortSubTransaction(), AbortTransaction(), TransactionStateData::blockState, CleanupSubTransaction(), CleanupTransaction(), CurrentTransactionState, TransactionStateData::state, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, 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, TRANS_DEFAULT, TRANS_INPROGRESS, and TRANS_START.

Referenced by AbortCurrentTransaction(), AutoVacLauncherMain(), PostgresMain(), ReorderBufferCommit(), ReorderBufferImmediateInvalidation(), and SnapBuildClearExportedSnapshot().

2985 {
2987 
2988  switch (s->blockState)
2989  {
2990  case TBLOCK_DEFAULT:
2991  if (s->state == TRANS_DEFAULT)
2992  {
2993  /* we are idle, so nothing to do */
2994  }
2995  else
2996  {
2997  /*
2998  * We can get here after an error during transaction start
2999  * (state will be TRANS_START). Need to clean up the
3000  * incompletely started transaction. First, adjust the
3001  * low-level state to suppress warning message from
3002  * AbortTransaction.
3003  */
3004  if (s->state == TRANS_START)
3005  s->state = TRANS_INPROGRESS;
3006  AbortTransaction();
3008  }
3009  break;
3010 
3011  /*
3012  * if we aren't in a transaction block, we just do the basic abort
3013  * & cleanup transaction.
3014  */
3015  case TBLOCK_STARTED:
3016  AbortTransaction();
3019  break;
3020 
3021  /*
3022  * If we are in TBLOCK_BEGIN it means something screwed up right
3023  * after reading "BEGIN TRANSACTION". We assume that the user
3024  * will interpret the error as meaning the BEGIN failed to get him
3025  * into a transaction block, so we should abort and return to idle
3026  * state.
3027  */
3028  case TBLOCK_BEGIN:
3029  AbortTransaction();
3032  break;
3033 
3034  /*
3035  * We are somewhere in a transaction block and we've gotten a
3036  * failure, so we abort the transaction and set up the persistent
3037  * ABORT state. We will stay in ABORT until we get a ROLLBACK.
3038  */
3039  case TBLOCK_INPROGRESS:
3041  AbortTransaction();
3042  s->blockState = TBLOCK_ABORT;
3043  /* CleanupTransaction happens when we exit TBLOCK_ABORT_END */
3044  break;
3045 
3046  /*
3047  * Here, we failed while trying to COMMIT. Clean up the
3048  * transaction and return to idle state (we do not want to stay in
3049  * the transaction).
3050  */
3051  case TBLOCK_END:
3052  AbortTransaction();
3055  break;
3056 
3057  /*
3058  * Here, we are already in an aborted transaction state and are
3059  * waiting for a ROLLBACK, but for some reason we failed again! So
3060  * we just remain in the abort state.
3061  */
3062  case TBLOCK_ABORT:
3063  case TBLOCK_SUBABORT:
3064  break;
3065 
3066  /*
3067  * We are in a failed transaction and we got the ROLLBACK command.
3068  * We have already aborted, we just need to cleanup and go to idle
3069  * state.
3070  */
3071  case TBLOCK_ABORT_END:
3074  break;
3075 
3076  /*
3077  * We are in a live transaction and we got a ROLLBACK command.
3078  * Abort, cleanup, go to idle state.
3079  */
3080  case TBLOCK_ABORT_PENDING:
3081  AbortTransaction();
3084  break;
3085 
3086  /*
3087  * Here, we failed while trying to PREPARE. Clean up the
3088  * transaction and return to idle state (we do not want to stay in
3089  * the transaction).
3090  */
3091  case TBLOCK_PREPARE:
3092  AbortTransaction();
3095  break;
3096 
3097  /*
3098  * We got an error inside a subtransaction. Abort just the
3099  * subtransaction, and go to the persistent SUBABORT state until
3100  * we get ROLLBACK.
3101  */
3102  case TBLOCK_SUBINPROGRESS:
3105  break;
3106 
3107  /*
3108  * If we failed while trying to create a subtransaction, clean up
3109  * the broken subtransaction and abort the parent. The same
3110  * applies if we get a failure while ending a subtransaction.
3111  */
3112  case TBLOCK_SUBBEGIN:
3113  case TBLOCK_SUBRELEASE:
3114  case TBLOCK_SUBCOMMIT:
3116  case TBLOCK_SUBRESTART:
3120  break;
3121 
3122  /*
3123  * Same as above, except the Abort() was already done.
3124  */
3125  case TBLOCK_SUBABORT_END:
3129  break;
3130  }
3131 }
void AbortCurrentTransaction(void)
Definition: xact.c:2984
static TransactionState CurrentTransactionState
Definition: xact.c:231
TBlockState blockState
Definition: xact.c:176
TransState state
Definition: xact.c:175
static void CleanupTransaction(void)
Definition: xact.c:2626
static void AbortSubTransaction(void)
Definition: xact.c:4543
static void AbortTransaction(void)
Definition: xact.c:2446
static void CleanupSubTransaction(void)
Definition: xact.c:4688
void AbortOutOfAnyTransaction ( void  )

Definition at line 4220 of file xact.c.

References AbortSubTransaction(), AbortTransaction(), Assert, TransactionStateData::blockState, CleanupSubTransaction(), CleanupTransaction(), CurrentTransactionState, NULL, TransactionStateData::parent, TransactionStateData::state, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, 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, TRANS_DEFAULT, TRANS_INPROGRESS, and TRANS_START.

Referenced by do_autovacuum(), RemoveTempRelationsCallback(), and ShutdownPostgres().

4221 {
4223 
4224  /*
4225  * Get out of any transaction or nested transaction
4226  */
4227  do
4228  {
4229  switch (s->blockState)
4230  {
4231  case TBLOCK_DEFAULT:
4232  if (s->state == TRANS_DEFAULT)
4233  {
4234  /* Not in a transaction, do nothing */
4235  }
4236  else
4237  {
4238  /*
4239  * We can get here after an error during transaction start
4240  * (state will be TRANS_START). Need to clean up the
4241  * incompletely started transaction. First, adjust the
4242  * low-level state to suppress warning message from
4243  * AbortTransaction.
4244  */
4245  if (s->state == TRANS_START)
4246  s->state = TRANS_INPROGRESS;
4247  AbortTransaction();
4249  }
4250  break;
4251  case TBLOCK_STARTED:
4252  case TBLOCK_BEGIN:
4253  case TBLOCK_INPROGRESS:
4255  case TBLOCK_END:
4256  case TBLOCK_ABORT_PENDING:
4257  case TBLOCK_PREPARE:
4258  /* In a transaction, so clean up */
4259  AbortTransaction();
4262  break;
4263  case TBLOCK_ABORT:
4264  case TBLOCK_ABORT_END:
4265  /* AbortTransaction already done, still need Cleanup */
4268  break;
4269 
4270  /*
4271  * In a subtransaction, so clean it up and abort parent too
4272  */
4273  case TBLOCK_SUBBEGIN:
4274  case TBLOCK_SUBINPROGRESS:
4275  case TBLOCK_SUBRELEASE:
4276  case TBLOCK_SUBCOMMIT:
4278  case TBLOCK_SUBRESTART:
4281  s = CurrentTransactionState; /* changed by pop */
4282  break;
4283 
4284  case TBLOCK_SUBABORT:
4285  case TBLOCK_SUBABORT_END:
4287  /* As above, but AbortSubTransaction already done */
4289  s = CurrentTransactionState; /* changed by pop */
4290  break;
4291  }
4292  } while (s->blockState != TBLOCK_DEFAULT);
4293 
4294  /* Should be out of all subxacts now */
4295  Assert(s->parent == NULL);
4296 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
TBlockState blockState
Definition: xact.c:176
TransState state
Definition: xact.c:175
static void CleanupTransaction(void)
Definition: xact.c:2626
struct TransactionStateData * parent
Definition: xact.c:190
static void AbortSubTransaction(void)
Definition: xact.c:4543
static void AbortTransaction(void)
Definition: xact.c:2446
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
static void CleanupSubTransaction(void)
Definition: xact.c:4688
void BeginInternalSubTransaction ( char *  name)

Definition at line 4051 of file xact.c.

References TransactionStateData::blockState, BlockStateAsString(), CommitTransactionCommand(), CurrentTransactionState, elog, ereport, errcode(), errmsg(), ERROR, FATAL, IsInParallelMode(), MemoryContextStrdup(), TransactionStateData::name, PushTransaction(), StartTransactionCommand(), TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, 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(), PLy_spi_subtransaction_begin(), PLy_subtransaction_enter(), ReorderBufferCommit(), and ReorderBufferImmediateInvalidation().

4052 {
4054 
4055  /*
4056  * Workers synchronize transaction state at the beginning of each parallel
4057  * operation, so we can't account for new subtransactions after that
4058  * point. We might be able to make an exception for the type of
4059  * subtransaction established by this function, which is typically used in
4060  * contexts where we're going to release or roll back the subtransaction
4061  * before proceeding further, so that no enduring change to the
4062  * transaction state occurs. For now, however, we prohibit this case along
4063  * with all the others.
4064  */
4065  if (IsInParallelMode())
4066  ereport(ERROR,
4067  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4068  errmsg("cannot start subtransactions during a parallel operation")));
4069 
4070  switch (s->blockState)
4071  {
4072  case TBLOCK_STARTED:
4073  case TBLOCK_INPROGRESS:
4074  case TBLOCK_END:
4075  case TBLOCK_PREPARE:
4076  case TBLOCK_SUBINPROGRESS:
4077  /* Normal subtransaction start */
4078  PushTransaction();
4079  s = CurrentTransactionState; /* changed by push */
4080 
4081  /*
4082  * Savepoint names, like the TransactionState block itself, live
4083  * in TopTransactionContext.
4084  */
4085  if (name)
4087  break;
4088 
4089  /* These cases are invalid. */
4090  case TBLOCK_DEFAULT:
4091  case TBLOCK_BEGIN:
4093  case TBLOCK_SUBBEGIN:
4094  case TBLOCK_SUBRELEASE:
4095  case TBLOCK_SUBCOMMIT:
4096  case TBLOCK_ABORT:
4097  case TBLOCK_SUBABORT:
4098  case TBLOCK_ABORT_END:
4099  case TBLOCK_SUBABORT_END:
4100  case TBLOCK_ABORT_PENDING:
4102  case TBLOCK_SUBRESTART:
4104  elog(FATAL, "BeginInternalSubTransaction: unexpected state %s",
4106  break;
4107  }
4108 
4111 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
MemoryContext TopTransactionContext
Definition: mcxt.c:48
void CommitTransactionCommand(void)
Definition: xact.c:2745
int errcode(int sqlerrcode)
Definition: elog.c:575
TBlockState blockState
Definition: xact.c:176
bool IsInParallelMode(void)
Definition: xact.c:912
#define ERROR
Definition: elog.h:43
#define FATAL
Definition: elog.h:52
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5001
#define ereport(elevel, rest)
Definition: elog.h:122
static void PushTransaction(void)
Definition: xact.c:4721
void StartTransactionCommand(void)
Definition: xact.c:2675
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1152
#define elog
Definition: elog.h:219
void BeginTransactionBlock ( void  )

Definition at line 3413 of file xact.c.

References TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg(), FATAL, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, TBLOCK_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().

3414 {
3416 
3417  switch (s->blockState)
3418  {
3419  /*
3420  * We are not inside a transaction block, so allow one to begin.
3421  */
3422  case TBLOCK_STARTED:
3423  s->blockState = TBLOCK_BEGIN;
3424  break;
3425 
3426  /*
3427  * Already a transaction block in progress.
3428  */
3429  case TBLOCK_INPROGRESS:
3431  case TBLOCK_SUBINPROGRESS:
3432  case TBLOCK_ABORT:
3433  case TBLOCK_SUBABORT:
3434  ereport(WARNING,
3435  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3436  errmsg("there is already a transaction in progress")));
3437  break;
3438 
3439  /* These cases are invalid. */
3440  case TBLOCK_DEFAULT:
3441  case TBLOCK_BEGIN:
3442  case TBLOCK_SUBBEGIN:
3443  case TBLOCK_END:
3444  case TBLOCK_SUBRELEASE:
3445  case TBLOCK_SUBCOMMIT:
3446  case TBLOCK_ABORT_END:
3447  case TBLOCK_SUBABORT_END:
3448  case TBLOCK_ABORT_PENDING:
3450  case TBLOCK_SUBRESTART:
3452  case TBLOCK_PREPARE:
3453  elog(FATAL, "BeginTransactionBlock: unexpected state %s",
3455  break;
3456  }
3457 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
int errcode(int sqlerrcode)
Definition: elog.c:575
TBlockState blockState
Definition: xact.c:176
#define FATAL
Definition: elog.h:52
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5001
#define ereport(elevel, rest)
Definition: elog.h:122
#define WARNING
Definition: elog.h:40
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
void CommandCounterIncrement ( void  )

Definition at line 921 of file xact.c.

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

Referenced by _SPI_execute_plan(), acquire_inherited_sample_rows(), AddRoleMems(), AlterPublicationOptions(), AlterRole(), apply_handle_delete(), apply_handle_insert(), apply_handle_update(), ATAddCheckConstraint(), ATExecAddColumn(), ATExecAlterColumnType(), ATExecCmd(), ATExecDropColumn(), ATExecDropConstraint(), ATExecSetTableSpace(), CommitSubTransaction(), CommitTransactionCommand(), create_ctas_internal(), create_toast_table(), CreateFKCheckTrigger(), createForeignKeyTriggers(), CreateForeignTable(), CreatePublication(), CreateRole(), CreateSchemaCommand(), DefineCollation(), DefineDomain(), DefineQueryRewrite(), DefineRange(), DefineRelation(), DefineType(), DefineVirtualRelation(), deleteOneObject(), DelRoleMems(), DropRole(), EventTriggerDDLCommandEnd(), EventTriggerDDLCommandStart(), EventTriggerInvoke(), EventTriggerSQLDrop(), EventTriggerTableRewrite(), exec_eval_simple_expr(), exec_execute_message(), exec_parse_message(), exec_simple_query(), ExecGrant_Database(), ExecGrant_Fdw(), ExecGrant_ForeignServer(), ExecGrant_Function(), ExecGrant_Language(), ExecGrant_Largeobject(), ExecGrant_Namespace(), ExecGrant_Relation(), ExecGrant_Tablespace(), ExecGrant_Type(), execute_sql_string(), ExplainOnePlan(), findTypeInputFunction(), findTypeOutputFunction(), fmgr_sql(), ImportForeignSchema(), index_build(), index_create(), InitTempTableNamespace(), inv_create(), inv_drop(), inv_truncate(), inv_write(), make_new_heap(), makeConfigurationDependencies(), moveArrayTypeName(), OperatorShellMake(), OperatorUpd(), pg_import_system_collations(), PortalRunMulti(), PreCommit_on_commit_actions(), ProcedureCreate(), ProcessUtilitySlow(), recordExtensionInitPrivWorker(), reindex_relation(), RelationSetNewRelfilenode(), RenumberEnumType(), replorigin_create(), replorigin_drop(), ri_PerformCheck(), SetMatViewPopulatedState(), shdepReassignOwned(), SPI_cursor_open_internal(), and StoreConstraints().

922 {
923  /*
924  * If the current value of the command counter hasn't been "used" to mark
925  * tuples, we need not increment it, since there's no need to distinguish
926  * a read-only command from others. This helps postpone command counter
927  * overflow, and keeps no-op CommandCounterIncrement operations cheap.
928  */
930  {
931  /*
932  * Workers synchronize transaction state at the beginning of each
933  * parallel operation, so we can't account for new commands after that
934  * point.
935  */
937  elog(ERROR, "cannot start commands during a parallel operation");
938 
939  currentCommandId += 1;
941  {
942  currentCommandId -= 1;
943  ereport(ERROR,
944  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
945  errmsg("cannot have more than 2^32-2 commands in a transaction")));
946  }
947  currentCommandIdUsed = false;
948 
949  /* Propagate new command ID into static snapshots */
951 
952  /*
953  * Make any catalog changes done by the just-completed command visible
954  * in the local syscache. We obviously don't need to do this after a
955  * read-only command. (But see hacks in inval.c to make real sure we
956  * don't think a command that queued inval messages was read-only.)
957  */
959  }
960 }
int errcode(int sqlerrcode)
Definition: elog.c:575
bool IsInParallelMode(void)
Definition: xact.c:912
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define IsParallelWorker()
Definition: parallel.h:53
#define InvalidCommandId
Definition: c.h:411
static void AtCCI_LocalCache(void)
Definition: xact.c:1363
void SnapshotSetCommandId(CommandId curcid)
Definition: snapmgr.c:540
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
static CommandId currentCommandId
Definition: xact.c:238
static bool currentCommandIdUsed
Definition: xact.c:239
void CommitTransactionCommand ( void  )

Definition at line 2745 of file xact.c.

References AbortSubTransaction(), AbortTransaction(), Assert, AssertState, TransactionStateData::blockState, BlockStateAsString(), CleanupSubTransaction(), CleanupTransaction(), CommandCounterIncrement(), CommitSubTransaction(), CommitTransaction(), CommitTransactionCommand(), CurrentTransactionState, DefineSavepoint(), elog, ERROR, FATAL, TransactionStateData::name, name, NULL, TransactionStateData::parent, PrepareTransaction(), TransactionStateData::savepointLevel, StartSubTransaction(), TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, 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 apply_handle_commit(), ApplyLoop(), ApplyWorkerMain(), BeginInternalSubTransaction(), cluster(), CommitTransactionCommand(), DefineIndex(), do_autovacuum(), finish_xact_command(), get_database_list(), get_subscription_list(), IdentifySystem(), index_drop(), initialize_worker_spi(), InitPostgres(), movedb(), ParallelWorkerMain(), ProcessCatchupInterrupt(), ProcessCompletedNotifies(), ProcessIncomingNotify(), ReindexMultipleTables(), RemoveTempRelationsCallback(), vacuum(), and vacuum_rel().

2746 {
2748 
2749  switch (s->blockState)
2750  {
2751  /*
2752  * These shouldn't happen. TBLOCK_DEFAULT means the previous
2753  * StartTransactionCommand didn't set the STARTED state
2754  * appropriately, while TBLOCK_PARALLEL_INPROGRESS should be ended
2755  * by EndParallelWorkerTransaction(), not this function.
2756  */
2757  case TBLOCK_DEFAULT:
2759  elog(FATAL, "CommitTransactionCommand: unexpected state %s",
2761  break;
2762 
2763  /*
2764  * If we aren't in a transaction block, just do our usual
2765  * transaction commit, and return to the idle state.
2766  */
2767  case TBLOCK_STARTED:
2770  break;
2771 
2772  /*
2773  * We are completing a "BEGIN TRANSACTION" command, so we change
2774  * to the "transaction block in progress" state and return. (We
2775  * assume the BEGIN did nothing to the database, so we need no
2776  * CommandCounterIncrement.)
2777  */
2778  case TBLOCK_BEGIN:
2780  break;
2781 
2782  /*
2783  * This is the case when we have finished executing a command
2784  * someplace within a transaction block. We increment the command
2785  * counter and return.
2786  */
2787  case TBLOCK_INPROGRESS:
2788  case TBLOCK_SUBINPROGRESS:
2790  break;
2791 
2792  /*
2793  * We are completing a "COMMIT" command. Do it and return to the
2794  * idle state.
2795  */
2796  case TBLOCK_END:
2799  break;
2800 
2801  /*
2802  * Here we are in the middle of a transaction block but one of the
2803  * commands caused an abort so we do nothing but remain in the
2804  * abort state. Eventually we will get a ROLLBACK command.
2805  */
2806  case TBLOCK_ABORT:
2807  case TBLOCK_SUBABORT:
2808  break;
2809 
2810  /*
2811  * Here we were in an aborted transaction block and we just got
2812  * the ROLLBACK command from the user, so clean up the
2813  * already-aborted transaction and return to the idle state.
2814  */
2815  case TBLOCK_ABORT_END:
2818  break;
2819 
2820  /*
2821  * Here we were in a perfectly good transaction block but the user
2822  * told us to ROLLBACK anyway. We have to abort the transaction
2823  * and then clean up.
2824  */
2825  case TBLOCK_ABORT_PENDING:
2826  AbortTransaction();
2829  break;
2830 
2831  /*
2832  * We are completing a "PREPARE TRANSACTION" command. Do it and
2833  * return to the idle state.
2834  */
2835  case TBLOCK_PREPARE:
2838  break;
2839 
2840  /*
2841  * We were just issued a SAVEPOINT inside a transaction block.
2842  * Start a subtransaction. (DefineSavepoint already did
2843  * PushTransaction, so as to have someplace to put the SUBBEGIN
2844  * state.)
2845  */
2846  case TBLOCK_SUBBEGIN:
2849  break;
2850 
2851  /*
2852  * We were issued a RELEASE command, so we end the current
2853  * subtransaction and return to the parent transaction. The parent
2854  * might be ended too, so repeat till we find an INPROGRESS
2855  * transaction or subtransaction.
2856  */
2857  case TBLOCK_SUBRELEASE:
2858  do
2859  {
2861  s = CurrentTransactionState; /* changed by pop */
2862  } while (s->blockState == TBLOCK_SUBRELEASE);
2863 
2866  break;
2867 
2868  /*
2869  * We were issued a COMMIT, so we end the current subtransaction
2870  * hierarchy and perform final commit. We do this by rolling up
2871  * any subtransactions into their parent, which leads to O(N^2)
2872  * operations with respect to resource owners - this isn't that
2873  * bad until we approach a thousands of savepoints but is
2874  * necessary for correctness should after triggers create new
2875  * resource owners.
2876  */
2877  case TBLOCK_SUBCOMMIT:
2878  do
2879  {
2881  s = CurrentTransactionState; /* changed by pop */
2882  } while (s->blockState == TBLOCK_SUBCOMMIT);
2883  /* If we had a COMMIT command, finish off the main xact too */
2884  if (s->blockState == TBLOCK_END)
2885  {
2886  Assert(s->parent == NULL);
2889  }
2890  else if (s->blockState == TBLOCK_PREPARE)
2891  {
2892  Assert(s->parent == NULL);
2895  }
2896  else
2897  elog(ERROR, "CommitTransactionCommand: unexpected state %s",
2899  break;
2900 
2901  /*
2902  * The current already-failed subtransaction is ending due to a
2903  * ROLLBACK or ROLLBACK TO command, so pop it and recursively
2904  * examine the parent (which could be in any of several states).
2905  */
2906  case TBLOCK_SUBABORT_END:
2909  break;
2910 
2911  /*
2912  * As above, but it's not dead yet, so abort first.
2913  */
2918  break;
2919 
2920  /*
2921  * The current subtransaction is the target of a ROLLBACK TO
2922  * command. Abort and pop it, then start a new subtransaction
2923  * with the same name.
2924  */
2925  case TBLOCK_SUBRESTART:
2926  {
2927  char *name;
2928  int savepointLevel;
2929 
2930  /* save name and keep Cleanup from freeing it */
2931  name = s->name;
2932  s->name = NULL;
2933  savepointLevel = s->savepointLevel;
2934 
2937 
2939  s = CurrentTransactionState; /* changed by push */
2940  s->name = name;
2941  s->savepointLevel = savepointLevel;
2942 
2943  /* This is the same as TBLOCK_SUBBEGIN case */
2947  }
2948  break;
2949 
2950  /*
2951  * Same as above, but the subtransaction had already failed, so we
2952  * don't need AbortSubTransaction.
2953  */
2955  {
2956  char *name;
2957  int savepointLevel;
2958 
2959  /* save name and keep Cleanup from freeing it */
2960  name = s->name;
2961  s->name = NULL;
2962  savepointLevel = s->savepointLevel;
2963 
2965 
2967  s = CurrentTransactionState; /* changed by push */
2968  s->name = name;
2969  s->savepointLevel = savepointLevel;
2970 
2971  /* This is the same as TBLOCK_SUBBEGIN case */
2975  }
2976  break;
2977  }
2978 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
#define AssertState(condition)
Definition: c.h:674
void CommitTransactionCommand(void)
Definition: xact.c:2745
TBlockState blockState
Definition: xact.c:176
static void PrepareTransaction(void)
Definition: xact.c:2177
#define ERROR
Definition: elog.h:43
static void CommitSubTransaction(void)
Definition: xact.c:4435
#define FATAL
Definition: elog.h:52
static void CleanupTransaction(void)
Definition: xact.c:2626
struct TransactionStateData * parent
Definition: xact.c:190
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5001
static void AbortSubTransaction(void)
Definition: xact.c:4543
void DefineSavepoint(char *name)
Definition: xact.c:3746
void CommandCounterIncrement(void)
Definition: xact.c:921
static void AbortTransaction(void)
Definition: xact.c:2446
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
static void CleanupSubTransaction(void)
Definition: xact.c:4688
const char * name
Definition: encode.c:521
static void CommitTransaction(void)
Definition: xact.c:1938
#define elog
Definition: elog.h:219
static void StartSubTransaction(void)
Definition: xact.c:4397
void DefineSavepoint ( char *  name)

Definition at line 3746 of file xact.c.

References TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg(), ERROR, FATAL, IsInParallelMode(), MemoryContextStrdup(), TransactionStateData::name, PushTransaction(), TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, 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 CommitTransactionCommand(), and standard_ProcessUtility().

3747 {
3749 
3750  /*
3751  * Workers synchronize transaction state at the beginning of each parallel
3752  * operation, so we can't account for new subtransactions after that
3753  * point. (Note that this check will certainly error out if s->blockState
3754  * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
3755  * below.)
3756  */
3757  if (IsInParallelMode())
3758  ereport(ERROR,
3759  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
3760  errmsg("cannot define savepoints during a parallel operation")));
3761 
3762  switch (s->blockState)
3763  {
3764  case TBLOCK_INPROGRESS:
3765  case TBLOCK_SUBINPROGRESS:
3766  /* Normal subtransaction start */
3767  PushTransaction();
3768  s = CurrentTransactionState; /* changed by push */
3769 
3770  /*
3771  * Savepoint names, like the TransactionState block itself, live
3772  * in TopTransactionContext.
3773  */
3774  if (name)
3776  break;
3777 
3778  /* These cases are invalid. */
3779  case TBLOCK_DEFAULT:
3780  case TBLOCK_STARTED:
3781  case TBLOCK_BEGIN:
3783  case TBLOCK_SUBBEGIN:
3784  case TBLOCK_END:
3785  case TBLOCK_SUBRELEASE:
3786  case TBLOCK_SUBCOMMIT:
3787  case TBLOCK_ABORT:
3788  case TBLOCK_SUBABORT:
3789  case TBLOCK_ABORT_END:
3790  case TBLOCK_SUBABORT_END:
3791  case TBLOCK_ABORT_PENDING:
3793  case TBLOCK_SUBRESTART:
3795  case TBLOCK_PREPARE:
3796  elog(FATAL, "DefineSavepoint: unexpected state %s",
3798  break;
3799  }
3800 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
MemoryContext TopTransactionContext
Definition: mcxt.c:48
int errcode(int sqlerrcode)
Definition: elog.c:575
TBlockState blockState
Definition: xact.c:176
bool IsInParallelMode(void)
Definition: xact.c:912
#define ERROR
Definition: elog.h:43
#define FATAL
Definition: elog.h:52
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5001
#define ereport(elevel, rest)
Definition: elog.h:122
static void PushTransaction(void)
Definition: xact.c:4721
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1152
#define elog
Definition: elog.h:219
void EndParallelWorkerTransaction ( void  )

Definition at line 4938 of file xact.c.

References Assert, TransactionStateData::blockState, CommitTransaction(), TBLOCK_DEFAULT, and TBLOCK_PARALLEL_INPROGRESS.

Referenced by ParallelWorkerMain().

4939 {
4943 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
TBlockState blockState
Definition: xact.c:176
#define Assert(condition)
Definition: c.h:671
static void CommitTransaction(void)
Definition: xact.c:1938
bool EndTransactionBlock ( void  )

Definition at line 3523 of file xact.c.

References TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg(), FATAL, NULL, TransactionStateData::parent, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, 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 PrepareTransactionBlock(), and standard_ProcessUtility().

3524 {
3526  bool result = false;
3527 
3528  switch (s->blockState)
3529  {
3530  /*
3531  * We are in a transaction block, so tell CommitTransactionCommand
3532  * to COMMIT.
3533  */
3534  case TBLOCK_INPROGRESS:
3535  s->blockState = TBLOCK_END;
3536  result = true;
3537  break;
3538 
3539  /*
3540  * We are in a failed transaction block. Tell
3541  * CommitTransactionCommand it's time to exit the block.
3542  */
3543  case TBLOCK_ABORT:
3545  break;
3546 
3547  /*
3548  * We are in a live subtransaction block. Set up to subcommit all
3549  * open subtransactions and then commit the main transaction.
3550  */
3551  case TBLOCK_SUBINPROGRESS:
3552  while (s->parent != NULL)
3553  {
3554  if (s->blockState == TBLOCK_SUBINPROGRESS)
3556  else
3557  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3559  s = s->parent;
3560  }
3561  if (s->blockState == TBLOCK_INPROGRESS)
3562  s->blockState = TBLOCK_END;
3563  else
3564  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3566  result = true;
3567  break;
3568 
3569  /*
3570  * Here we are inside an aborted subtransaction. Treat the COMMIT
3571  * as ROLLBACK: set up to abort everything and exit the main
3572  * transaction.
3573  */
3574  case TBLOCK_SUBABORT:
3575  while (s->parent != NULL)
3576  {
3577  if (s->blockState == TBLOCK_SUBINPROGRESS)
3579  else if (s->blockState == TBLOCK_SUBABORT)
3581  else
3582  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3584  s = s->parent;
3585  }
3586  if (s->blockState == TBLOCK_INPROGRESS)
3588  else if (s->blockState == TBLOCK_ABORT)
3590  else
3591  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3593  break;
3594 
3595  /*
3596  * The user issued COMMIT when not inside a transaction. Issue a
3597  * WARNING, staying in TBLOCK_STARTED state. The upcoming call to
3598  * CommitTransactionCommand() will then close the transaction and
3599  * put us back into the default state.
3600  */
3601  case TBLOCK_STARTED:
3602  ereport(WARNING,
3603  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
3604  errmsg("there is no transaction in progress")));
3605  result = true;
3606  break;
3607 
3608  /*
3609  * The user issued a COMMIT that somehow ran inside a parallel
3610  * worker. We can't cope with that.
3611  */
3613  ereport(FATAL,
3614  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
3615  errmsg("cannot commit during a parallel operation")));
3616  break;
3617 
3618  /* These cases are invalid. */
3619  case TBLOCK_DEFAULT:
3620  case TBLOCK_BEGIN:
3621  case TBLOCK_SUBBEGIN:
3622  case TBLOCK_END:
3623  case TBLOCK_SUBRELEASE:
3624  case TBLOCK_SUBCOMMIT:
3625  case TBLOCK_ABORT_END:
3626  case TBLOCK_SUBABORT_END:
3627  case TBLOCK_ABORT_PENDING:
3629  case TBLOCK_SUBRESTART:
3631  case TBLOCK_PREPARE:
3632  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3634  break;
3635  }
3636 
3637  return result;
3638 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
int errcode(int sqlerrcode)
Definition: elog.c:575
TBlockState blockState
Definition: xact.c:176
#define FATAL
Definition: elog.h:52
struct TransactionStateData * parent
Definition: xact.c:190
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5001
#define ereport(elevel, rest)
Definition: elog.h:122
#define WARNING
Definition: elog.h:40
#define NULL
Definition: c.h:226
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
void EnterParallelMode ( void  )

Definition at line 879 of file xact.c.

References Assert, CurrentTransactionState, and TransactionStateData::parallelModeLevel.

Referenced by CommitTransaction(), ExecutePlan(), and ParallelWorkerMain().

880 {
882 
883  Assert(s->parallelModeLevel >= 0);
884 
885  ++s->parallelModeLevel;
886 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
int parallelModeLevel
Definition: xact.c:189
#define Assert(condition)
Definition: c.h:671
Size EstimateTransactionStateSpace ( void  )

Definition at line 4814 of file xact.c.

References add_size(), mul_size(), TransactionStateData::nChildXids, nParallelCurrentXids, NULL, TransactionStateData::parent, TransactionStateData::transactionId, and TransactionIdIsValid.

Referenced by InitializeParallelDSM().

4815 {
4816  TransactionState s;
4817  Size nxids = 6; /* iso level, deferrable, top & current XID,
4818  * command counter, XID count */
4819 
4820  for (s = CurrentTransactionState; s != NULL; s = s->parent)
4821  {
4823  nxids = add_size(nxids, 1);
4824  nxids = add_size(nxids, s->nChildXids);
4825  }
4826 
4827  nxids = add_size(nxids, nParallelCurrentXids);
4828  return mul_size(nxids, sizeof(TransactionId));
4829 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
uint32 TransactionId
Definition: c.h:394
int nParallelCurrentXids
Definition: xact.c:108
struct TransactionStateData * parent
Definition: xact.c:190
Size mul_size(Size s1, Size s2)
Definition: shmem.c:492
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
TransactionId transactionId
Definition: xact.c:171
#define NULL
Definition: c.h:226
size_t Size
Definition: c.h:353
#define TransactionIdIsValid(xid)
Definition: transam.h:41
void ExitParallelMode ( void  )

Definition at line 892 of file xact.c.

References Assert, CurrentTransactionState, ParallelContextActive(), and TransactionStateData::parallelModeLevel.

Referenced by ExecutePlan(), and ParallelWorkerMain().

893 {
895 
896  Assert(s->parallelModeLevel > 0);
898 
899  --s->parallelModeLevel;
900 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
bool ParallelContextActive(void)
Definition: parallel.c:681
int parallelModeLevel
Definition: xact.c:189
#define Assert(condition)
Definition: c.h:671
void ForceSyncCommit ( void  )

Definition at line 969 of file xact.c.

References forceSyncCommit.

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

970 {
971  forceSyncCommit = true;
972 }
static bool forceSyncCommit
Definition: xact.c:261
CommandId GetCurrentCommandId ( bool  used)

Definition at line 686 of file xact.c.

References Assert, currentCommandId, currentCommandIdUsed, and TransactionStateData::parallelModeLevel.

Referenced by ATRewriteTable(), CopyFrom(), GetSnapshotData(), intorel_startup(), pgrowlocks(), RegisterRelcacheInvalidation(), RelationFindReplTupleByIndex(), RelationFindReplTupleSeq(), simple_heap_delete(), simple_heap_insert(), simple_heap_update(), standard_ExecutorStart(), toast_save_datum(), transientrel_startup(), and UpdateActiveSnapshotCommandId().

687 {
688  /* this is global to a transaction, not subtransaction-local */
689  if (used)
690  {
691  /*
692  * Forbid setting currentCommandIdUsed in parallel mode, because we
693  * have no provision for communicating this back to the master. We
694  * could relax this restriction when currentCommandIdUsed was already
695  * true at the start of the parallel operation.
696  */
698  currentCommandIdUsed = true;
699  }
700  return currentCommandId;
701 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
int parallelModeLevel
Definition: xact.c:189
#define Assert(condition)
Definition: c.h:671
static CommandId currentCommandId
Definition: xact.c:238
static bool currentCommandIdUsed
Definition: xact.c:239
TimestampTz GetCurrentStatementStartTimestamp ( void  )

Definition at line 716 of file xact.c.

References stmtStartTimestamp.

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

717 {
718  return stmtStartTimestamp;
719 }
static TimestampTz stmtStartTimestamp
Definition: xact.c:249
TransactionId GetCurrentTransactionIdIfAny ( void  )

Definition at line 433 of file xact.c.

References TransactionStateData::transactionId.

Referenced by RecordTransactionAbort(), ReorderBufferCommit(), and XLogRecordAssemble().

434 {
436 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
TransactionId transactionId
Definition: xact.c:171
TimestampTz GetCurrentTransactionStartTimestamp ( void  )
TimestampTz GetCurrentTransactionStopTimestamp ( void  )

Definition at line 728 of file xact.c.

References GetCurrentTimestamp(), and xactStopTimestamp.

Referenced by pgstat_report_stat().

729 {
730  if (xactStopTimestamp != 0)
731  return xactStopTimestamp;
732  return GetCurrentTimestamp();
733 }
static TimestampTz xactStopTimestamp
Definition: xact.c:250
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1569
TransactionId GetStableLatestTransactionId ( void  )

Definition at line 460 of file xact.c.

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

Referenced by xid_age().

461 {
463  static TransactionId stablexid = InvalidTransactionId;
464 
465  if (lxid != MyProc->lxid)
466  {
467  lxid = MyProc->lxid;
468  stablexid = GetTopTransactionIdIfAny();
469  if (!TransactionIdIsValid(stablexid))
470  stablexid = ReadNewTransactionId();
471  }
472 
473  Assert(TransactionIdIsValid(stablexid));
474 
475  return stablexid;
476 }
uint32 TransactionId
Definition: c.h:394
PGPROC * MyProc
Definition: proc.c:67
#define InvalidTransactionId
Definition: transam.h:31
TransactionId ReadNewTransactionId(void)
Definition: varsup.c:250
uint32 LocalTransactionId
Definition: c.h:396
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:403
#define Assert(condition)
Definition: c.h:671
#define InvalidLocalTransactionId
Definition: lock.h:70
#define TransactionIdIsValid(xid)
Definition: transam.h:41
LocalTransactionId lxid
Definition: proc.h:95
TransactionId GetTopTransactionId ( void  )

Definition at line 388 of file xact.c.

References AssignTransactionId(), TransactionIdIsValid, and XactTopTransactionId.

Referenced by AlterSequence(), AssignTransactionId(), AtEOXact_Snapshot(), do_setval(), ExportSnapshot(), fill_seq_with_data(), log_heap_new_cid(), LogAccessExclusiveLock(), LogAccessExclusiveLockPrepare(), nextval_internal(), SnapBuildExportSnapshot(), and txid_current().

389 {
392  return XactTopTransactionId;
393 }
TransactionId XactTopTransactionId
Definition: xact.c:107
static TransactionStateData TopTransactionStateData
Definition: xact.c:200
#define TransactionIdIsValid(xid)
Definition: transam.h:41
static void AssignTransactionId(TransactionState s)
Definition: xact.c:488
bool IsAbortedTransactionBlockState ( void  )
bool IsInTransactionChain ( bool  isTopLevel)

Definition at line 3268 of file xact.c.

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

Referenced by vacuum().

3269 {
3270  /*
3271  * Return true on same conditions that would make PreventTransactionChain
3272  * error out
3273  */
3274  if (IsTransactionBlock())
3275  return true;
3276 
3277  if (IsSubTransaction())
3278  return true;
3279 
3280  if (!isTopLevel)
3281  return true;
3282 
3285  return true;
3286 
3287  return false;
3288 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
TBlockState blockState
Definition: xact.c:176
bool IsTransactionBlock(void)
Definition: xact.c:4302
bool IsSubTransaction(void)
Definition: xact.c:4374
bool IsSubTransaction ( void  )
bool IsTransactionBlock ( void  )

Definition at line 4302 of file xact.c.

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

Referenced by CheckTransactionChain(), IsInTransactionChain(), and PreventTransactionChain().

4303 {
4305 
4307  return false;
4308 
4309  return true;
4310 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
TBlockState blockState
Definition: xact.c:176
bool IsTransactionOrTransactionBlock ( void  )

Definition at line 4320 of file xact.c.

References TransactionStateData::blockState, CurrentTransactionState, and TBLOCK_DEFAULT.

Referenced by PostgresMain(), ProcessCatchupInterrupt(), ProcessNotifyInterrupt(), RecoveryConflictInterrupt(), ReorderBufferCommit(), ReorderBufferImmediateInvalidation(), SnapBuildExportSnapshot(), and StartupDecodingContext().

4321 {
4323 
4324  if (s->blockState == TBLOCK_DEFAULT)
4325  return false;
4326 
4327  return true;
4328 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
TBlockState blockState
Definition: xact.c:176
bool IsTransactionState ( void  )

Definition at line 349 of file xact.c.

References CurrentTransactionState, TransactionStateData::state, and TRANS_INPROGRESS.

Referenced by apply_handle_commit(), apply_handle_origin(), check_client_encoding(), check_default_tablespace(), check_role(), check_session_authorization(), check_temp_tablespaces(), check_transaction_read_only(), check_TSCurrentConfig(), check_XactIsoLevel(), CreateInitDecodingContext(), ensure_transaction(), LogLogicalMessage(), pg_do_encoding_conversion(), PrepareClientEncoding(), PrepareTempTablespaces(), RelationClearRelation(), RelationIdGetRelation(), RelationInitPhysicalAddr(), replorigin_create(), replorigin_drop(), SearchCatCache(), SetMultiXactIdLimit(), SetTransactionIdLimit(), SnapBuildClearExportedSnapshot(), and SocketBackend().

350 {
352 
353  /*
354  * TRANS_DEFAULT and TRANS_ABORT are obviously unsafe states. However, we
355  * also reject the startup/shutdown states TRANS_START, TRANS_COMMIT,
356  * TRANS_PREPARE since it might be too soon or too late within those
357  * transition states to do anything interesting. Hence, the only "valid"
358  * state is TRANS_INPROGRESS.
359  */
360  return (s->state == TRANS_INPROGRESS);
361 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
TransState state
Definition: xact.c:175
void MarkCurrentTransactionIdLoggedIfAny ( void  )

Definition at line 444 of file xact.c.

References TransactionStateData::didLogXid, TransactionStateData::transactionId, and TransactionIdIsValid.

Referenced by XLogInsertRecord().

445 {
448 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
TransactionId transactionId
Definition: xact.c:171
#define TransactionIdIsValid(xid)
Definition: transam.h:41
void ParseAbortRecord ( uint8  info,
xl_xact_abort xlrec,
xl_xact_parsed_abort parsed 
)

Definition at line 122 of file xactdesc.c.

References MinSizeOfXactAbort, MinSizeOfXactRelfilenodes, MinSizeOfXactSubxacts, xl_xact_relfilenodes::nrels, xl_xact_parsed_abort::nrels, xl_xact_subxacts::nsubxacts, xl_xact_parsed_abort::nsubxacts, xl_xact_subxacts::subxacts, xl_xact_parsed_abort::subxacts, xl_xact_parsed_abort::twophase_xid, xl_xact_abort::xact_time, xl_xact_parsed_abort::xact_time, XACT_XINFO_HAS_RELFILENODES, XACT_XINFO_HAS_SUBXACTS, XACT_XINFO_HAS_TWOPHASE, xl_xact_twophase::xid, xl_xact_xinfo::xinfo, xl_xact_parsed_abort::xinfo, XLOG_XACT_HAS_INFO, xl_xact_relfilenodes::xnodes, and xl_xact_parsed_abort::xnodes.

Referenced by DecodeXactOp(), recoveryStopsAfter(), recoveryStopsBefore(), xact_desc_abort(), and xact_redo().

123 {
124  char *data = ((char *) xlrec) + MinSizeOfXactAbort;
125 
126  memset(parsed, 0, sizeof(*parsed));
127 
128  parsed->xinfo = 0; /* default, if no XLOG_XACT_HAS_INFO is
129  * present */
130 
131  parsed->xact_time = xlrec->xact_time;
132 
133  if (info & XLOG_XACT_HAS_INFO)
134  {
135  xl_xact_xinfo *xl_xinfo = (xl_xact_xinfo *) data;
136 
137  parsed->xinfo = xl_xinfo->xinfo;
138 
139  data += sizeof(xl_xact_xinfo);
140  }
141 
142  if (parsed->xinfo & XACT_XINFO_HAS_SUBXACTS)
143  {
144  xl_xact_subxacts *xl_subxacts = (xl_xact_subxacts *) data;
145 
146  parsed->nsubxacts = xl_subxacts->nsubxacts;
147  parsed->subxacts = xl_subxacts->subxacts;
148 
149  data += MinSizeOfXactSubxacts;
150  data += parsed->nsubxacts * sizeof(TransactionId);
151  }
152 
153  if (parsed->xinfo & XACT_XINFO_HAS_RELFILENODES)
154  {
155  xl_xact_relfilenodes *xl_relfilenodes = (xl_xact_relfilenodes *) data;
156 
157  parsed->nrels = xl_relfilenodes->nrels;
158  parsed->xnodes = xl_relfilenodes->xnodes;
159 
161  data += xl_relfilenodes->nrels * sizeof(RelFileNode);
162  }
163 
164  if (parsed->xinfo & XACT_XINFO_HAS_TWOPHASE)
165  {
166  xl_xact_twophase *xl_twophase = (xl_xact_twophase *) data;
167 
168  parsed->twophase_xid = xl_twophase->xid;
169 
170  data += sizeof(xl_xact_twophase);
171  }
172 }
struct xl_xact_xinfo xl_xact_xinfo
uint32 TransactionId
Definition: c.h:394
TransactionId xid
Definition: xact.h:226
#define MinSizeOfXactAbort
Definition: xact.h:260
#define XLOG_XACT_HAS_INFO
Definition: xact.h:128
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:135
#define MinSizeOfXactRelfilenodes
Definition: xact.h:215
TimestampTz xact_time
Definition: xact.h:251
RelFileNode xnodes[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:213
#define MinSizeOfXactSubxacts
Definition: xact.h:208
struct RelFileNode RelFileNode
struct xl_xact_twophase xl_xact_twophase
TransactionId * subxacts
Definition: xact.h:297
uint32 xinfo
Definition: xact.h:194
RelFileNode * xnodes
Definition: xact.h:300
int nsubxacts
Definition: xact.h:205
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:138
TransactionId twophase_xid
Definition: xact.h:302
TimestampTz xact_time
Definition: xact.h:293
#define XACT_XINFO_HAS_RELFILENODES
Definition: xact.h:136
TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:206
void ParseCommitRecord ( uint8  info,
xl_xact_commit xlrec,
xl_xact_parsed_commit parsed 
)

Definition at line 35 of file xactdesc.c.

References xl_xact_dbinfo::dbId, xl_xact_parsed_commit::dbId, MinSizeOfXactCommit, MinSizeOfXactInvals, MinSizeOfXactRelfilenodes, MinSizeOfXactSubxacts, xl_xact_invals::msgs, xl_xact_parsed_commit::msgs, xl_xact_invals::nmsgs, xl_xact_parsed_commit::nmsgs, xl_xact_relfilenodes::nrels, xl_xact_parsed_commit::nrels, xl_xact_subxacts::nsubxacts, xl_xact_parsed_commit::nsubxacts, xl_xact_origin::origin_lsn, xl_xact_parsed_commit::origin_lsn, xl_xact_origin::origin_timestamp, xl_xact_parsed_commit::origin_timestamp, xl_xact_subxacts::subxacts, xl_xact_parsed_commit::subxacts, xl_xact_dbinfo::tsId, xl_xact_parsed_commit::tsId, xl_xact_parsed_commit::twophase_xid, xl_xact_commit::xact_time, xl_xact_parsed_commit::xact_time, XACT_XINFO_HAS_DBINFO, XACT_XINFO_HAS_INVALS, XACT_XINFO_HAS_ORIGIN, XACT_XINFO_HAS_RELFILENODES, XACT_XINFO_HAS_SUBXACTS, XACT_XINFO_HAS_TWOPHASE, xl_xact_twophase::xid, xl_xact_xinfo::xinfo, xl_xact_parsed_commit::xinfo, XLOG_XACT_HAS_INFO, xl_xact_relfilenodes::xnodes, and xl_xact_parsed_commit::xnodes.

Referenced by DecodeXactOp(), recoveryStopsAfter(), recoveryStopsBefore(), xact_desc_commit(), and xact_redo().

36 {
37  char *data = ((char *) xlrec) + MinSizeOfXactCommit;
38 
39  memset(parsed, 0, sizeof(*parsed));
40 
41  parsed->xinfo = 0; /* default, if no XLOG_XACT_HAS_INFO is
42  * present */
43 
44  parsed->xact_time = xlrec->xact_time;
45 
46  if (info & XLOG_XACT_HAS_INFO)
47  {
48  xl_xact_xinfo *xl_xinfo = (xl_xact_xinfo *) data;
49 
50  parsed->xinfo = xl_xinfo->xinfo;
51 
52  data += sizeof(xl_xact_xinfo);
53  }
54 
55  if (parsed->xinfo & XACT_XINFO_HAS_DBINFO)
56  {
57  xl_xact_dbinfo *xl_dbinfo = (xl_xact_dbinfo *) data;
58 
59  parsed->dbId = xl_dbinfo->dbId;
60  parsed->tsId = xl_dbinfo->tsId;
61 
62  data += sizeof(xl_xact_dbinfo);
63  }
64 
65  if (parsed->xinfo & XACT_XINFO_HAS_SUBXACTS)
66  {
67  xl_xact_subxacts *xl_subxacts = (xl_xact_subxacts *) data;
68 
69  parsed->nsubxacts = xl_subxacts->nsubxacts;
70  parsed->subxacts = xl_subxacts->subxacts;
71 
72  data += MinSizeOfXactSubxacts;
73  data += parsed->nsubxacts * sizeof(TransactionId);
74  }
75 
76  if (parsed->xinfo & XACT_XINFO_HAS_RELFILENODES)
77  {
78  xl_xact_relfilenodes *xl_relfilenodes = (xl_xact_relfilenodes *) data;
79 
80  parsed->nrels = xl_relfilenodes->nrels;
81  parsed->xnodes = xl_relfilenodes->xnodes;
82 
84  data += xl_relfilenodes->nrels * sizeof(RelFileNode);
85  }
86 
87  if (parsed->xinfo & XACT_XINFO_HAS_INVALS)
88  {
89  xl_xact_invals *xl_invals = (xl_xact_invals *) data;
90 
91  parsed->nmsgs = xl_invals->nmsgs;
92  parsed->msgs = xl_invals->msgs;
93 
94  data += MinSizeOfXactInvals;
95  data += xl_invals->nmsgs * sizeof(SharedInvalidationMessage);
96  }
97 
98  if (parsed->xinfo & XACT_XINFO_HAS_TWOPHASE)
99  {
100  xl_xact_twophase *xl_twophase = (xl_xact_twophase *) data;
101 
102  parsed->twophase_xid = xl_twophase->xid;
103 
104  data += sizeof(xl_xact_twophase);
105  }
106 
107  if (parsed->xinfo & XACT_XINFO_HAS_ORIGIN)
108  {
109  xl_xact_origin xl_origin;
110 
111  /* we're only guaranteed 4 byte alignment, so copy onto stack */
112  memcpy(&xl_origin, data, sizeof(xl_origin));
113 
114  parsed->origin_lsn = xl_origin.origin_lsn;
115  parsed->origin_timestamp = xl_origin.origin_timestamp;
116 
117  data += sizeof(xl_xact_origin);
118  }
119 }
RelFileNode * xnodes
Definition: xact.h:280
#define XACT_XINFO_HAS_ORIGIN
Definition: xact.h:139
struct xl_xact_xinfo xl_xact_xinfo
uint32 TransactionId
Definition: c.h:394
TimestampTz origin_timestamp
Definition: xact.h:288
TransactionId xid
Definition: xact.h:226
TransactionId twophase_xid
Definition: xact.h:285
TransactionId * subxacts
Definition: xact.h:277
#define XLOG_XACT_HAS_INFO
Definition: xact.h:128
SharedInvalidationMessage * msgs
Definition: xact.h:283
XLogRecPtr origin_lsn
Definition: xact.h:287
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:135
struct xl_xact_dbinfo xl_xact_dbinfo
#define MinSizeOfXactRelfilenodes
Definition: xact.h:215
Oid tsId
Definition: xact.h:200
struct xl_xact_origin xl_xact_origin
RelFileNode xnodes[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:213
#define MinSizeOfXactSubxacts
Definition: xact.h:208
#define MinSizeOfXactCommit
Definition: xact.h:247
SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:220
struct RelFileNode RelFileNode
TimestampTz xact_time
Definition: xact.h:237
struct xl_xact_twophase xl_xact_twophase
#define MinSizeOfXactInvals
Definition: xact.h:222
#define XACT_XINFO_HAS_DBINFO
Definition: xact.h:134
XLogRecPtr origin_lsn
Definition: xact.h:231
uint32 xinfo
Definition: xact.h:194
int nsubxacts
Definition: xact.h:205
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:138
Oid dbId
Definition: xact.h:199
TimestampTz origin_timestamp
Definition: xact.h:232
#define XACT_XINFO_HAS_INVALS
Definition: xact.h:137
#define XACT_XINFO_HAS_RELFILENODES
Definition: xact.h:136
int nmsgs
Definition: xact.h:219
TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:206
TimestampTz xact_time
Definition: xact.h:269
bool PrepareTransactionBlock ( char *  gid)

Definition at line 3472 of file xact.c.

References Assert, TransactionStateData::blockState, CurrentTransactionState, EndTransactionBlock(), MemoryContextStrdup(), NULL, TransactionStateData::parent, prepareGID, TBLOCK_END, TBLOCK_PREPARE, TBLOCK_STARTED, and TopTransactionContext.

Referenced by standard_ProcessUtility().

3473 {
3474  TransactionState s;
3475  bool result;
3476 
3477  /* Set up to commit the current transaction */
3478  result = EndTransactionBlock();
3479 
3480  /* If successful, change outer tblock state to PREPARE */
3481  if (result)
3482  {
3484 
3485  while (s->parent != NULL)
3486  s = s->parent;
3487 
3488  if (s->blockState == TBLOCK_END)
3489  {
3490  /* Save GID where PrepareTransaction can find it again */
3492 
3494  }
3495  else
3496  {
3497  /*
3498  * ignore case where we are not in a transaction;
3499  * EndTransactionBlock already issued a warning.
3500  */
3502  /* Don't send back a PREPARE result tag... */
3503  result = false;
3504  }
3505  }
3506 
3507  return result;
3508 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
MemoryContext TopTransactionContext
Definition: mcxt.c:48
bool EndTransactionBlock(void)
Definition: xact.c:3523
TBlockState blockState
Definition: xact.c:176
struct TransactionStateData * parent
Definition: xact.c:190
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1152
static char * prepareGID
Definition: xact.c:256
void PreventTransactionChain ( bool  isTopLevel,
const char *  stmtType 
)

Definition at line 3152 of file xact.c.

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

Referenced by AlterDatabase(), cluster(), DiscardAll(), ExecDropStmt(), ProcessUtilitySlow(), standard_ProcessUtility(), and vacuum().

3153 {
3154  /*
3155  * xact block already started?
3156  */
3157  if (IsTransactionBlock())
3158  ereport(ERROR,
3159  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3160  /* translator: %s represents an SQL statement name */
3161  errmsg("%s cannot run inside a transaction block",
3162  stmtType)));
3163 
3164  /*
3165  * subtransaction?
3166  */
3167  if (IsSubTransaction())
3168  ereport(ERROR,
3169  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3170  /* translator: %s represents an SQL statement name */
3171  errmsg("%s cannot run inside a subtransaction",
3172  stmtType)));
3173 
3174  /*
3175  * inside a function call?
3176  */
3177  if (!isTopLevel)
3178  ereport(ERROR,
3179  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3180  /* translator: %s represents an SQL statement name */
3181  errmsg("%s cannot be executed from a function or multi-command string",
3182  stmtType)));
3183 
3184  /* If we got past IsTransactionBlock test, should be in default state */
3187  elog(FATAL, "cannot prevent transaction chain");
3188  /* all okay */
3189 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
int errcode(int sqlerrcode)
Definition: elog.c:575
TBlockState blockState
Definition: xact.c:176
bool IsTransactionBlock(void)
Definition: xact.c:4302
#define ERROR
Definition: elog.h:43
#define FATAL
Definition: elog.h:52
#define ereport(elevel, rest)
Definition: elog.h:122
bool IsSubTransaction(void)
Definition: xact.c:4374
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
void RegisterSubXactCallback ( SubXactCallback  callback,
void *  arg 
)

Definition at line 3358 of file xact.c.

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

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

3359 {
3360  SubXactCallbackItem *item;
3361 
3362  item = (SubXactCallbackItem *)
3364  item->callback = callback;
3365  item->arg = arg;
3366  item->next = SubXact_callbacks;
3367  SubXact_callbacks = item;
3368 }
static SubXactCallbackItem * SubXact_callbacks
Definition: xact.c:292
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:49
struct SubXactCallbackItem * next
Definition: xact.c:287
SubXactCallback callback
Definition: xact.c:288
MemoryContext TopMemoryContext
Definition: mcxt.c:43
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:749
void * arg
void RegisterXactCallback ( XactCallback  callback,
void *  arg 
)

Definition at line 3303 of file xact.c.

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

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

3304 {
3305  XactCallbackItem *item;
3306 
3307  item = (XactCallbackItem *)
3309  item->callback = callback;
3310  item->arg = arg;
3311  item->next = Xact_callbacks;
3312  Xact_callbacks = item;
3313 }
struct XactCallbackItem * next
Definition: xact.c:275
void * arg
Definition: xact.c:277
XactCallback callback
Definition: xact.c:276
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:49
MemoryContext TopMemoryContext
Definition: mcxt.c:43
static XactCallbackItem * Xact_callbacks
Definition: xact.c:280
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:749
void * arg
void ReleaseCurrentSubTransaction ( void  )

Definition at line 4121 of file xact.c.

References Assert, TransactionStateData::blockState, BlockStateAsString(), CommitSubTransaction(), CurrentTransactionState, CurTransactionContext, elog, ereport, errcode(), errmsg(), ERROR, IsInParallelMode(), 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(), PLy_spi_subtransaction_commit(), and PLy_subtransaction_exit().

4122 {
4124 
4125  /*
4126  * Workers synchronize transaction state at the beginning of each parallel
4127  * operation, so we can't account for commit of subtransactions after that
4128  * point. This should not happen anyway. Code calling this would
4129  * typically have called BeginInternalSubTransaction() first, failing
4130  * there.
4131  */
4132  if (IsInParallelMode())
4133  ereport(ERROR,
4134  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4135  errmsg("cannot commit subtransactions during a parallel operation")));
4136 
4137  if (s->blockState != TBLOCK_SUBINPROGRESS)
4138  elog(ERROR, "ReleaseCurrentSubTransaction: unexpected state %s",
4140  Assert(s->state == TRANS_INPROGRESS);
4143  s = CurrentTransactionState; /* changed by pop */
4144  Assert(s->state == TRANS_INPROGRESS);
4145 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
MemoryContext CurTransactionContext
Definition: mcxt.c:49
int errcode(int sqlerrcode)
Definition: elog.c:575
TBlockState blockState
Definition: xact.c:176
TransState state
Definition: xact.c:175
bool IsInParallelMode(void)
Definition: xact.c:912
#define ERROR
Definition: elog.h:43
static void CommitSubTransaction(void)
Definition: xact.c:4435
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5001
#define ereport(elevel, rest)
Definition: elog.h:122
#define Assert(condition)
Definition: c.h:671
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
void ReleaseSavepoint ( List options)

Definition at line 3809 of file xact.c.

References DefElem::arg, Assert, TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, DefElem::defname, elog, ereport, errcode(), errmsg(), ERROR, FATAL, IsInParallelMode(), lfirst, TransactionStateData::name, name, NULL, TransactionStateData::parent, PointerIsValid, TransactionStateData::savepointLevel, strVal, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, 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().

3810 {
3812  TransactionState target,
3813  xact;
3814  ListCell *cell;
3815  char *name = NULL;
3816 
3817  /*
3818  * Workers synchronize transaction state at the beginning of each parallel
3819  * operation, so we can't account for transaction state change after that
3820  * point. (Note that this check will certainly error out if s->blockState
3821  * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
3822  * below.)
3823  */
3824  if (IsInParallelMode())
3825  ereport(ERROR,
3826  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
3827  errmsg("cannot release savepoints during a parallel operation")));
3828 
3829  switch (s->blockState)
3830  {
3831  /*
3832  * We can't rollback to a savepoint if there is no savepoint
3833  * defined.
3834  */
3835  case TBLOCK_INPROGRESS:
3836  ereport(ERROR,
3837  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
3838  errmsg("no such savepoint")));
3839  break;
3840 
3841  /*
3842  * We are in a non-aborted subtransaction. This is the only valid
3843  * case.
3844  */
3845  case TBLOCK_SUBINPROGRESS:
3846  break;
3847 
3848  /* These cases are invalid. */
3849  case TBLOCK_DEFAULT:
3850  case TBLOCK_STARTED:
3851  case TBLOCK_BEGIN:
3853  case TBLOCK_SUBBEGIN:
3854  case TBLOCK_END:
3855  case TBLOCK_SUBRELEASE:
3856  case TBLOCK_SUBCOMMIT:
3857  case TBLOCK_ABORT:
3858  case TBLOCK_SUBABORT:
3859  case TBLOCK_ABORT_END:
3860  case TBLOCK_SUBABORT_END:
3861  case TBLOCK_ABORT_PENDING:
3863  case TBLOCK_SUBRESTART:
3865  case TBLOCK_PREPARE:
3866  elog(FATAL, "ReleaseSavepoint: unexpected state %s",
3868  break;
3869  }
3870 
3871  foreach(cell, options)
3872  {
3873  DefElem *elem = lfirst(cell);
3874 
3875  if (strcmp(elem->defname, "savepoint_name") == 0)
3876  name = strVal(elem->arg);
3877  }
3878 
3879  Assert(PointerIsValid(name));
3880 
3881  for (target = s; PointerIsValid(target); target = target->parent)
3882  {
3883  if (PointerIsValid(target->name) && strcmp(target->name, name) == 0)
3884  break;
3885  }
3886 
3887  if (!PointerIsValid(target))
3888  ereport(ERROR,
3889  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
3890  errmsg("no such savepoint")));
3891 
3892  /* disallow crossing savepoint level boundaries */
3893  if (target->savepointLevel != s->savepointLevel)
3894  ereport(ERROR,
3895  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
3896  errmsg("no such savepoint")));
3897 
3898  /*
3899  * Mark "commit pending" all subtransactions up to the target
3900  * subtransaction. The actual commits will happen when control gets to
3901  * CommitTransactionCommand.
3902  */
3903  xact = CurrentTransactionState;
3904  for (;;)
3905  {
3907  xact->blockState = TBLOCK_SUBRELEASE;
3908  if (xact == target)
3909  break;
3910  xact = xact->parent;
3911  Assert(PointerIsValid(xact));
3912  }
3913 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
TBlockState blockState
Definition: xact.c:176
bool IsInParallelMode(void)
Definition: xact.c:912
#define ERROR
Definition: elog.h:43
#define FATAL
Definition: elog.h:52
struct TransactionStateData * parent
Definition: xact.c:190
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5001
#define ereport(elevel, rest)
Definition: elog.h:122
Node * arg
Definition: parsenodes.h:676
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define lfirst(lc)
Definition: pg_list.h:106
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * defname
Definition: parsenodes.h:675
#define elog
Definition: elog.h:219
#define PointerIsValid(pointer)
Definition: c.h:522
void RequireTransactionChain ( bool  isTopLevel,
const char *  stmtType 
)

Definition at line 3206 of file xact.c.

References CheckTransactionChain().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

3207 {
3208  CheckTransactionChain(isTopLevel, true, stmtType);
3209 }
static void CheckTransactionChain(bool isTopLevel, bool throwError, const char *stmtType)
Definition: xact.c:3229
void RollbackAndReleaseCurrentSubTransaction ( void  )

Definition at line 4155 of file xact.c.

References AbortSubTransaction(), AssertState, TransactionStateData::blockState, BlockStateAsString(), CleanupSubTransaction(), CurrentTransactionState, elog, FATAL, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, 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(), PLy_abort_open_subtransactions(), PLy_spi_subtransaction_abort(), PLy_subtransaction_exit(), ReorderBufferCommit(), and ReorderBufferImmediateInvalidation().

4156 {
4158 
4159  /*
4160  * Unlike ReleaseCurrentSubTransaction(), this is nominally permitted
4161  * during parallel operations. That's because we may be in the master,
4162  * recovering from an error thrown while we were in parallel mode. We
4163  * won't reach here in a worker, because BeginInternalSubTransaction()
4164  * will have failed.
4165  */
4166 
4167  switch (s->blockState)
4168  {
4169  /* Must be in a subtransaction */
4170  case TBLOCK_SUBINPROGRESS:
4171  case TBLOCK_SUBABORT:
4172  break;
4173 
4174  /* These cases are invalid. */
4175  case TBLOCK_DEFAULT:
4176  case TBLOCK_STARTED:
4177  case TBLOCK_BEGIN:
4179  case TBLOCK_SUBBEGIN:
4180  case TBLOCK_INPROGRESS:
4181  case TBLOCK_END:
4182  case TBLOCK_SUBRELEASE:
4183  case TBLOCK_SUBCOMMIT:
4184  case TBLOCK_ABORT:
4185  case TBLOCK_ABORT_END:
4186  case TBLOCK_SUBABORT_END:
4187  case TBLOCK_ABORT_PENDING:
4189  case TBLOCK_SUBRESTART:
4191  case TBLOCK_PREPARE:
4192  elog(FATAL, "RollbackAndReleaseCurrentSubTransaction: unexpected state %s",
4194  break;
4195  }
4196 
4197  /*
4198  * Abort the current subtransaction, if needed.
4199  */
4200  if (s->blockState == TBLOCK_SUBINPROGRESS)
4202 
4203  /* And clean it up, too */
4205 
4206  s = CurrentTransactionState; /* changed by pop */
4208  s->blockState == TBLOCK_INPROGRESS ||
4209  s->blockState == TBLOCK_STARTED);
4210 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
#define AssertState(condition)
Definition: c.h:674
TBlockState blockState
Definition: xact.c:176
#define FATAL
Definition: elog.h:52
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5001
static void AbortSubTransaction(void)
Definition: xact.c:4543
static void CleanupSubTransaction(void)
Definition: xact.c:4688
#define elog
Definition: elog.h:219
void RollbackToSavepoint ( List options)

Definition at line 3922 of file xact.c.

References DefElem::arg, Assert, TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, DefElem::defname, elog, ereport, errcode(), errmsg(), ERROR, FATAL, IsInParallelMode(), lfirst, TransactionStateData::name, name, NULL, TransactionStateData::parent, PointerIsValid, TransactionStateData::savepointLevel, strVal, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, 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().

3923 {
3925  TransactionState target,
3926  xact;
3927  ListCell *cell;
3928  char *name = NULL;
3929 
3930  /*
3931  * Workers synchronize transaction state at the beginning of each parallel
3932  * operation, so we can't account for transaction state change after that
3933  * point. (Note that this check will certainly error out if s->blockState
3934  * is TBLOCK_PARALLEL_INPROGRESS, so we can treat that as an invalid case
3935  * below.)
3936  */
3937  if (IsInParallelMode())
3938  ereport(ERROR,
3939  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
3940  errmsg("cannot rollback to savepoints during a parallel operation")));
3941 
3942  switch (s->blockState)
3943  {
3944  /*
3945  * We can't rollback to a savepoint if there is no savepoint
3946  * defined.
3947  */
3948  case TBLOCK_INPROGRESS:
3949  case TBLOCK_ABORT:
3950  ereport(ERROR,
3951  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
3952  errmsg("no such savepoint")));
3953  break;
3954 
3955  /*
3956  * There is at least one savepoint, so proceed.
3957  */
3958  case TBLOCK_SUBINPROGRESS:
3959  case TBLOCK_SUBABORT:
3960  break;
3961 
3962  /* These cases are invalid. */
3963  case TBLOCK_DEFAULT:
3964  case TBLOCK_STARTED:
3965  case TBLOCK_BEGIN:
3967  case TBLOCK_SUBBEGIN:
3968  case TBLOCK_END:
3969  case TBLOCK_SUBRELEASE:
3970  case TBLOCK_SUBCOMMIT:
3971  case TBLOCK_ABORT_END:
3972  case TBLOCK_SUBABORT_END:
3973  case TBLOCK_ABORT_PENDING:
3975  case TBLOCK_SUBRESTART:
3977  case TBLOCK_PREPARE:
3978  elog(FATAL, "RollbackToSavepoint: unexpected state %s",
3980  break;
3981  }
3982 
3983  foreach(cell, options)
3984  {
3985  DefElem *elem = lfirst(cell);
3986 
3987  if (strcmp(elem->defname, "savepoint_name") == 0)
3988  name = strVal(elem->arg);
3989  }
3990 
3991  Assert(PointerIsValid(name));
3992 
3993  for (target = s; PointerIsValid(target); target = target->parent)
3994  {
3995  if (PointerIsValid(target->name) && strcmp(target->name, name) == 0)
3996  break;
3997  }
3998 
3999  if (!PointerIsValid(target))
4000  ereport(ERROR,
4001  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4002  errmsg("no such savepoint")));
4003 
4004  /* disallow crossing savepoint level boundaries */
4005  if (target->savepointLevel != s->savepointLevel)
4006  ereport(ERROR,
4007  (errcode(ERRCODE_S_E_INVALID_SPECIFICATION),
4008  errmsg("no such savepoint")));
4009 
4010  /*
4011  * Mark "abort pending" all subtransactions up to the target
4012  * subtransaction. The actual aborts will happen when control gets to
4013  * CommitTransactionCommand.
4014  */
4015  xact = CurrentTransactionState;
4016  for (;;)
4017  {
4018  if (xact == target)
4019  break;
4020  if (xact->blockState == TBLOCK_SUBINPROGRESS)
4022  else if (xact->blockState == TBLOCK_SUBABORT)
4024  else
4025  elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4027  xact = xact->parent;
4028  Assert(PointerIsValid(xact));
4029  }
4030 
4031  /* And mark the target as "restart pending" */
4032  if (xact->blockState == TBLOCK_SUBINPROGRESS)
4033  xact->blockState = TBLOCK_SUBRESTART;
4034  else if (xact->blockState == TBLOCK_SUBABORT)
4036  else
4037  elog(FATAL, "RollbackToSavepoint: unexpected state %s",
4039 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
TBlockState blockState
Definition: xact.c:176
bool IsInParallelMode(void)
Definition: xact.c:912
#define ERROR
Definition: elog.h:43
#define FATAL
Definition: elog.h:52
struct TransactionStateData * parent
Definition: xact.c:190
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5001
#define ereport(elevel, rest)
Definition: elog.h:122
Node * arg
Definition: parsenodes.h:676
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define lfirst(lc)
Definition: pg_list.h:106
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * defname
Definition: parsenodes.h:675
#define elog
Definition: elog.h:219
#define PointerIsValid(pointer)
Definition: c.h:522
void SerializeTransactionState ( Size  maxsize,
char *  start_address 
)

Definition at line 4847 of file xact.c.

References add_size(), Assert, TransactionStateData::childXids, currentCommandId, i, TransactionStateData::nChildXids, nParallelCurrentXids, NULL, palloc(), ParallelCurrentXids, TransactionStateData::parent, qsort, TransactionStateData::transactionId, TransactionIdIsValid, XactDeferrable, XactIsoLevel, XactTopTransactionId, and xidComparator().

Referenced by InitializeParallelDSM().

4848 {
4849  TransactionState s;
4850  Size nxids = 0;
4851  Size i = 0;
4852  Size c = 0;
4853  TransactionId *workspace;
4854  TransactionId *result = (TransactionId *) start_address;
4855 
4856  result[c++] = (TransactionId) XactIsoLevel;
4857  result[c++] = (TransactionId) XactDeferrable;
4858  result[c++] = XactTopTransactionId;
4859  result[c++] = CurrentTransactionState->transactionId;
4860  result[c++] = (TransactionId) currentCommandId;
4861  Assert(maxsize >= c * sizeof(TransactionId));
4862 
4863  /*
4864  * If we're running in a parallel worker and launching a parallel worker
4865  * of our own, we can just pass along the information that was passed to
4866  * us.
4867  */
4868  if (nParallelCurrentXids > 0)
4869  {
4870  result[c++] = nParallelCurrentXids;
4871  Assert(maxsize >= (nParallelCurrentXids + c) * sizeof(TransactionId));
4872  memcpy(&result[c], ParallelCurrentXids,
4874  return;
4875  }
4876 
4877  /*
4878  * OK, we need to generate a sorted list of XIDs that our workers should
4879  * view as current. First, figure out how many there are.
4880  */
4881  for (s = CurrentTransactionState; s != NULL; s = s->parent)
4882  {
4884  nxids = add_size(nxids, 1);
4885  nxids = add_size(nxids, s->nChildXids);
4886  }
4887  Assert((c + 1 + nxids) * sizeof(TransactionId) <= maxsize);
4888 
4889  /* Copy them to our scratch space. */
4890  workspace = palloc(nxids * sizeof(TransactionId));
4891  for (s = CurrentTransactionState; s != NULL; s = s->parent)
4892  {
4894  workspace[i++] = s->transactionId;
4895  memcpy(&workspace[i], s->childXids,
4896  s->nChildXids * sizeof(TransactionId));
4897  i += s->nChildXids;
4898  }
4899  Assert(i == nxids);
4900 
4901  /* Sort them. */
4902  qsort(workspace, nxids, sizeof(TransactionId), xidComparator);
4903 
4904  /* Copy data into output area. */
4905  result[c++] = (TransactionId) nxids;
4906  memcpy(&result[c], workspace, nxids * sizeof(TransactionId));
4907 }
TransactionId XactTopTransactionId
Definition: xact.c:107
bool XactDeferrable
Definition: xact.c:80
static TransactionState CurrentTransactionState
Definition: xact.c:231
uint32 TransactionId
Definition: c.h:394
int nParallelCurrentXids
Definition: xact.c:108
TransactionId * childXids
Definition: xact.c:181
struct TransactionStateData * parent
Definition: xact.c:190
char * c
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
TransactionId transactionId
Definition: xact.c:171
TransactionId * ParallelCurrentXids
Definition: xact.c:109
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
size_t Size
Definition: c.h:353
int XactIsoLevel
Definition: xact.c:74
void * palloc(Size size)
Definition: mcxt.c:891
int i
#define qsort(a, b, c, d)
Definition: port.h:440
static CommandId currentCommandId
Definition: xact.c:238
#define TransactionIdIsValid(xid)
Definition: transam.h:41
int xidComparator(const void *arg1, const void *arg2)
Definition: xid.c:138
void SetCurrentStatementStartTimestamp ( void  )

Definition at line 739 of file xact.c.

References GetCurrentTimestamp(), and stmtStartTimestamp.

Referenced by autovac_report_activity(), initialize_worker_spi(), InitPostgres(), and PostgresMain().

740 {
742 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1569
static TimestampTz stmtStartTimestamp
Definition: xact.c:249
void StartParallelWorkerTransaction ( char *  tstatespace)

Definition at line 4915 of file xact.c.

References Assert, TransactionStateData::blockState, currentCommandId, nParallelCurrentXids, ParallelCurrentXids, StartTransaction(), TBLOCK_DEFAULT, TBLOCK_PARALLEL_INPROGRESS, TransactionStateData::transactionId, XactDeferrable, XactIsoLevel, and XactTopTransactionId.

Referenced by ParallelWorkerMain().

4916 {
4917  TransactionId *tstate = (TransactionId *) tstatespace;
4918 
4920  StartTransaction();
4921 
4922  XactIsoLevel = (int) tstate[0];
4923  XactDeferrable = (bool) tstate[1];
4924  XactTopTransactionId = tstate[2];
4926  currentCommandId = tstate[4];
4927  nParallelCurrentXids = (int) tstate[5];
4928  ParallelCurrentXids = &tstate[6];
4929 
4931 }
TransactionId XactTopTransactionId
Definition: xact.c:107
bool XactDeferrable
Definition: xact.c:80
static TransactionState CurrentTransactionState
Definition: xact.c:231
uint32 TransactionId
Definition: c.h:394
int nParallelCurrentXids
Definition: xact.c:108
char bool
Definition: c.h:199
TBlockState blockState
Definition: xact.c:176
TransactionId transactionId
Definition: xact.c:171
static void StartTransaction(void)
Definition: xact.c:1800
TransactionId * ParallelCurrentXids
Definition: xact.c:109
#define Assert(condition)
Definition: c.h:671
int XactIsoLevel
Definition: xact.c:74
static CommandId currentCommandId
Definition: xact.c:238
void StartTransactionCommand ( void  )

Definition at line 2675 of file xact.c.

References Assert, TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, CurTransactionContext, elog, ERROR, MemoryContextSwitchTo(), NULL, StartTransaction(), TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, 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 ApplyLoop(), ApplyWorkerMain(), BeginInternalSubTransaction(), cluster(), DefineIndex(), do_autovacuum(), ensure_transaction(), get_database_list(), get_subscription_list(), IdentifySystem(), index_drop(), initialize_worker_spi(), InitPostgres(), movedb(), ParallelWorkerMain(), ProcessCatchupInterrupt(), ProcessCompletedNotifies(), ProcessIncomingNotify(), ReindexMultipleTables(), RemoveTempRelationsCallback(), ReorderBufferCommit(), SnapBuildExportSnapshot(), start_xact_command(), vacuum(), and vacuum_rel().

2676 {
2678 
2679  switch (s->blockState)
2680  {
2681  /*
2682  * if we aren't in a transaction block, we just do our usual start
2683  * transaction.
2684  */
2685  case TBLOCK_DEFAULT:
2686  StartTransaction();
2688  break;
2689 
2690  /*
2691  * We are somewhere in a transaction block or subtransaction and
2692  * about to start a new command. For now we do nothing, but
2693  * someday we may do command-local resource initialization. (Note
2694  * that any needed CommandCounterIncrement was done by the
2695  * previous CommitTransactionCommand.)
2696  */
2697  case TBLOCK_INPROGRESS:
2698  case TBLOCK_SUBINPROGRESS:
2699  break;
2700 
2701  /*
2702  * Here we are in a failed transaction block (one of the commands
2703  * caused an abort) so we do nothing but remain in the abort
2704  * state. Eventually we will get a ROLLBACK command which will
2705  * get us out of this state. (It is up to other code to ensure
2706  * that no commands other than ROLLBACK will be processed in these
2707  * states.)
2708  */
2709  case TBLOCK_ABORT:
2710  case TBLOCK_SUBABORT:
2711  break;
2712 
2713  /* These cases are invalid. */
2714  case TBLOCK_STARTED:
2715  case TBLOCK_BEGIN:
2717  case TBLOCK_SUBBEGIN:
2718  case TBLOCK_END:
2719  case TBLOCK_SUBRELEASE:
2720  case TBLOCK_SUBCOMMIT:
2721  case TBLOCK_ABORT_END:
2722  case TBLOCK_SUBABORT_END:
2723  case TBLOCK_ABORT_PENDING:
2725  case TBLOCK_SUBRESTART:
2727  case TBLOCK_PREPARE:
2728  elog(ERROR, "StartTransactionCommand: unexpected state %s",
2730  break;
2731  }
2732 
2733  /*
2734  * We must switch to CurTransactionContext before returning. This is
2735  * already done if we called StartTransaction, otherwise not.
2736  */
2739 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
MemoryContext CurTransactionContext
Definition: mcxt.c:49
TBlockState blockState
Definition: xact.c:176
#define ERROR
Definition: elog.h:43
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5001
static void StartTransaction(void)
Definition: xact.c:1800
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define elog
Definition: elog.h:219
bool SubTransactionIsActive ( SubTransactionId  subxid)

Definition at line 662 of file xact.c.

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

Referenced by fmgr_sql().

663 {
665 
666  for (s = CurrentTransactionState; s != NULL; s = s->parent)
667  {
668  if (s->state == TRANS_ABORT)
669  continue;
670  if (s->subTransactionId == subxid)
671  return true;
672  }
673  return false;
674 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
TransState state
Definition: xact.c:175
struct TransactionStateData * parent
Definition: xact.c:190
SubTransactionId subTransactionId
Definition: xact.c:172
#define NULL
Definition: c.h:226
char TransactionBlockStatusCode ( void  )

Definition at line 4334 of file xact.c.

References TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, FATAL, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, 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().

4335 {
4337 
4338  switch (s->blockState)
4339  {
4340  case TBLOCK_DEFAULT:
4341  case TBLOCK_STARTED:
4342  return 'I'; /* idle --- not in transaction */
4343  case TBLOCK_BEGIN:
4344  case TBLOCK_SUBBEGIN:
4345  case TBLOCK_INPROGRESS:
4347  case TBLOCK_SUBINPROGRESS:
4348  case TBLOCK_END:
4349  case TBLOCK_SUBRELEASE:
4350  case TBLOCK_SUBCOMMIT:
4351  case TBLOCK_PREPARE:
4352  return 'T'; /* in transaction */
4353  case TBLOCK_ABORT:
4354  case TBLOCK_SUBABORT:
4355  case TBLOCK_ABORT_END:
4356  case TBLOCK_SUBABORT_END:
4357  case TBLOCK_ABORT_PENDING:
4359  case TBLOCK_SUBRESTART:
4361  return 'E'; /* in failed transaction */
4362  }
4363 
4364  /* should never get here */
4365  elog(FATAL, "invalid transaction block state: %s",
4367  return 0; /* keep compiler quiet */
4368 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
TBlockState blockState
Definition: xact.c:176
#define FATAL
Definition: elog.h:52
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5001
#define elog
Definition: elog.h:219
bool TransactionIdIsCurrentTransactionId ( TransactionId  xid)

Definition at line 772 of file xact.c.

References TransactionStateData::childXids, TransactionStateData::nChildXids, nParallelCurrentXids, NULL, ParallelCurrentXids, TransactionStateData::parent, TransactionStateData::state, TRANS_ABORT, TransactionStateData::transactionId, TransactionIdEquals, TransactionIdIsNormal, TransactionIdIsValid, and TransactionIdPrecedes().

Referenced by acquire_sample_rows(), compute_new_xmax_infomask(), copy_heap_data(), Do_MultiXactIdWait(), DoesMultiXactIdConflict(), EvalPlanQualFetch(), ExecCheckHeapTupleVisible(), ExecOnConflictUpdate(), FreezeMultiXactId(), funny_dup17(), heap_delete(), heap_lock_tuple(), heap_update(), HeapTupleHeaderAdjustCmax(), HeapTupleHeaderGetCmax(), HeapTupleHeaderGetCmin(), HeapTupleHeaderIsOnlyLocked(), HeapTupleSatisfiesDirty(), HeapTupleSatisfiesMVCC(), HeapTupleSatisfiesSelf(), HeapTupleSatisfiesToast(), HeapTupleSatisfiesUpdate(), HeapTupleSatisfiesVacuum(), IndexBuildHeapRangeScan(), MultiXactIdIsRunning(), RI_FKey_fk_upd_check_required(), SnapBuildFindSnapshot(), test_lockmode_for_conflict(), and TransactionIdIsInProgress().

773 {
775 
776  /*
777  * We always say that BootstrapTransactionId is "not my transaction ID"
778  * even when it is (ie, during bootstrap). Along with the fact that
779  * transam.c always treats BootstrapTransactionId as already committed,
780  * this causes the tqual.c routines to see all tuples as committed, which
781  * is what we need during bootstrap. (Bootstrap mode only inserts tuples,
782  * it never updates or deletes them, so all tuples can be presumed good
783  * immediately.)
784  *
785  * Likewise, InvalidTransactionId and FrozenTransactionId are certainly
786  * not my transaction ID, so we can just return "false" immediately for
787  * any non-normal XID.
788  */
789  if (!TransactionIdIsNormal(xid))
790  return false;
791 
792  /*
793  * In parallel workers, the XIDs we must consider as current are stored in
794  * ParallelCurrentXids rather than the transaction-state stack. Note that
795  * the XIDs in this array are sorted numerically rather than according to
796  * transactionIdPrecedes order.
797  */
798  if (nParallelCurrentXids > 0)
799  {
800  int low,
801  high;
802 
803  low = 0;
804  high = nParallelCurrentXids - 1;
805  while (low <= high)
806  {
807  int middle;
808  TransactionId probe;
809 
810  middle = low + (high - low) / 2;
811  probe = ParallelCurrentXids[middle];
812  if (probe == xid)
813  return true;
814  else if (probe < xid)
815  low = middle + 1;
816  else
817  high = middle - 1;
818  }
819  return false;
820  }
821 
822  /*
823  * We will return true for the Xid of the current subtransaction, any of
824  * its subcommitted children, any of its parents, or any of their
825  * previously subcommitted children. However, a transaction being aborted
826  * is no longer "current", even though it may still have an entry on the
827  * state stack.
828  */
829  for (s = CurrentTransactionState; s != NULL; s = s->parent)
830  {
831  int low,
832  high;
833 
834  if (s->state == TRANS_ABORT)
835  continue;
837  continue; /* it can't have any child XIDs either */
838  if (TransactionIdEquals(xid, s->transactionId))
839  return true;
840  /* As the childXids array is ordered, we can use binary search */
841  low = 0;
842  high = s->nChildXids - 1;
843  while (low <= high)
844  {
845  int middle;
846  TransactionId probe;
847 
848  middle = low + (high - low) / 2;
849  probe = s->childXids[middle];
850  if (TransactionIdEquals(probe, xid))
851  return true;
852  else if (TransactionIdPrecedes(probe, xid))
853  low = middle + 1;
854  else
855  high = middle - 1;
856  }
857  }
858 
859  return false;
860 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
uint32 TransactionId
Definition: c.h:394
int nParallelCurrentXids
Definition: xact.c:108
TransactionId * childXids
Definition: xact.c:181
TransState state
Definition: xact.c:175
struct TransactionStateData * parent
Definition: xact.c:190
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
TransactionId transactionId
Definition: xact.c:171
TransactionId * ParallelCurrentXids
Definition: xact.c:109
#define NULL
Definition: c.h:226
#define TransactionIdIsValid(xid)
Definition: transam.h:41
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
void UnregisterSubXactCallback ( SubXactCallback  callback,
void *  arg 
)

Definition at line 3371 of file xact.c.

References SubXactCallbackItem::next, NULL, and pfree().

3372 {
3373  SubXactCallbackItem *item;
3374  SubXactCallbackItem *prev;
3375 
3376  prev = NULL;
3377  for (item = SubXact_callbacks; item; prev = item, item = item->next)
3378  {
3379  if (item->callback == callback && item->arg == arg)
3380  {
3381  if (prev)
3382  prev->next = item->next;
3383  else
3384  SubXact_callbacks = item->next;
3385  pfree(item);
3386  break;
3387  }
3388  }
3389 }
static SubXactCallbackItem * SubXact_callbacks
Definition: xact.c:292
void pfree(void *pointer)
Definition: mcxt.c:992
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:49
struct SubXactCallbackItem * next
Definition: xact.c:287
#define NULL
Definition: c.h:226
void * arg
void UnregisterXactCallback ( XactCallback  callback,
void *  arg 
)

Definition at line 3316 of file xact.c.

References XactCallbackItem::next, NULL, and pfree().

3317 {
3318  XactCallbackItem *item;
3319  XactCallbackItem *prev;
3320 
3321  prev = NULL;
3322  for (item = Xact_callbacks; item; prev = item, item = item->next)
3323  {
3324  if (item->callback == callback && item->arg == arg)
3325  {
3326  if (prev)
3327  prev->next = item->next;
3328  else
3329  Xact_callbacks = item->next;
3330  pfree(item);
3331  break;
3332  }
3333  }
3334 }
struct XactCallbackItem * next
Definition: xact.c:275
void pfree(void *pointer)
Definition: mcxt.c:992
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:49
#define NULL
Definition: c.h:226
static XactCallbackItem * Xact_callbacks
Definition: xact.c:280
void * arg
void UserAbortTransactionBlock ( void  )

Definition at line 3647 of file xact.c.

References TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg(), FATAL, NULL, TransactionStateData::parent, TBLOCK_ABORT, TBLOCK_ABORT_END, TBLOCK_ABORT_PENDING, TBLOCK_BEGIN, TBLOCK_DEFAULT, TBLOCK_END, 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().

3648 {
3650 
3651  switch (s->blockState)
3652  {
3653  /*
3654  * We are inside a transaction block and we got a ROLLBACK command
3655  * from the user, so tell CommitTransactionCommand to abort and
3656  * exit the transaction block.
3657  */
3658  case TBLOCK_INPROGRESS:
3660  break;
3661 
3662  /*
3663  * We are inside a failed transaction block and we got a ROLLBACK
3664  * command from the user. Abort processing is already done, so
3665  * CommitTransactionCommand just has to cleanup and go back to
3666  * idle state.
3667  */
3668  case TBLOCK_ABORT:
3670  break;
3671 
3672  /*
3673  * We are inside a subtransaction. Mark everything up to top
3674  * level as exitable.
3675  */
3676  case TBLOCK_SUBINPROGRESS:
3677  case TBLOCK_SUBABORT:
3678  while (s->parent != NULL)
3679  {
3680  if (s->blockState == TBLOCK_SUBINPROGRESS)
3682  else if (s->blockState == TBLOCK_SUBABORT)
3684  else
3685  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
3687  s = s->parent;
3688  }
3689  if (s->blockState == TBLOCK_INPROGRESS)
3691  else if (s->blockState == TBLOCK_ABORT)
3693  else
3694  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
3696  break;
3697 
3698  /*
3699  * The user issued ABORT when not inside a transaction. Issue a
3700  * WARNING and go to abort state. The upcoming call to
3701  * CommitTransactionCommand() will then put us back into the
3702  * default state.
3703  */
3704  case TBLOCK_STARTED:
3705  ereport(WARNING,
3706  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
3707  errmsg("there is no transaction in progress")));
3709  break;
3710 
3711  /*
3712  * The user issued an ABORT that somehow ran inside a parallel
3713  * worker. We can't cope with that.
3714  */
3716  ereport(FATAL,
3717  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
3718  errmsg("cannot abort during a parallel operation")));
3719  break;
3720 
3721  /* These cases are invalid. */
3722  case TBLOCK_DEFAULT:
3723  case TBLOCK_BEGIN:
3724  case TBLOCK_SUBBEGIN:
3725  case TBLOCK_END:
3726  case TBLOCK_SUBRELEASE:
3727  case TBLOCK_SUBCOMMIT:
3728  case TBLOCK_ABORT_END:
3729  case TBLOCK_SUBABORT_END:
3730  case TBLOCK_ABORT_PENDING:
3732  case TBLOCK_SUBRESTART:
3734  case TBLOCK_PREPARE:
3735  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
3737  break;
3738  }
3739 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
int errcode(int sqlerrcode)
Definition: elog.c:575
TBlockState blockState
Definition: xact.c:176
#define FATAL
Definition: elog.h:52
struct TransactionStateData * parent
Definition: xact.c:190
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5001
#define ereport(elevel, rest)
Definition: elog.h:122
#define WARNING
Definition: elog.h:40
#define NULL
Definition: c.h:226
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
void WarnNoTransactionChain ( bool  isTopLevel,
const char *  stmtType 
)

Definition at line 3200 of file xact.c.

References CheckTransactionChain().

Referenced by ExecSetVariableStmt(), and standard_ProcessUtility().

3201 {
3202  CheckTransactionChain(isTopLevel, false, stmtType);
3203 }
static void CheckTransactionChain(bool isTopLevel, bool throwError, const char *stmtType)
Definition: xact.c:3229
void xact_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 270 of file xactdesc.c.

References appendStringInfo(), xact_desc_abort(), xact_desc_assignment(), xact_desc_commit(), XLOG_XACT_ABORT, XLOG_XACT_ABORT_PREPARED, XLOG_XACT_ASSIGNMENT, XLOG_XACT_COMMIT, XLOG_XACT_COMMIT_PREPARED, XLOG_XACT_OPMASK, XLogRecGetData, XLogRecGetInfo, XLogRecGetOrigin, and xl_xact_assignment::xtop.

271 {
272  char *rec = XLogRecGetData(record);
273  uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
274 
275  if (info == XLOG_XACT_COMMIT || info == XLOG_XACT_COMMIT_PREPARED)
276  {
277  xl_xact_commit *xlrec = (xl_xact_commit *) rec;
278 
279  xact_desc_commit(buf, XLogRecGetInfo(record), xlrec,
280  XLogRecGetOrigin(record));
281  }
282  else if (info == XLOG_XACT_ABORT || info == XLOG_XACT_ABORT_PREPARED)
283  {
284  xl_xact_abort *xlrec = (xl_xact_abort *) rec;
285 
286  xact_desc_abort(buf, XLogRecGetInfo(record), xlrec);
287  }
288  else if (info == XLOG_XACT_ASSIGNMENT)
289  {
290  xl_xact_assignment *xlrec = (xl_xact_assignment *) rec;
291 
292  /*
293  * Note that we ignore the WAL record's xid, since we're more
294  * interested in the top-level xid that issued the record and which
295  * xids are being reported here.
296  */
297  appendStringInfo(buf, "xtop %u: ", xlrec->xtop);
298  xact_desc_assignment(buf, xlrec);
299  }
300 }
#define XLOG_XACT_COMMIT
Definition: xact.h:115
unsigned char uint8
Definition: c.h:263
TransactionId xtop
Definition: xact.h:163
#define XLogRecGetOrigin(decoder)
Definition: xlogreader.h:201
#define XLogRecGetData(decoder)
Definition: xlogreader.h:202
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:110
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:119
static void xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec)
Definition: xactdesc.c:226
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:198
#define XLOG_XACT_ASSIGNMENT
Definition: xact.h:120
#define XLOG_XACT_ABORT
Definition: xact.h:117
#define XLOG_XACT_OPMASK
Definition: xact.h:125
static void xact_desc_assignment(StringInfo buf, xl_xact_assignment *xlrec)
Definition: xactdesc.c:259
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:118
static void xact_desc_commit(StringInfo buf, uint8 info, xl_xact_commit *xlrec, RepOriginId origin_id)
Definition: xactdesc.c:175
const char* xact_identify ( uint8  info)

Definition at line 303 of file xactdesc.c.

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

304 {
305  const char *id = NULL;
306 
307  switch (info & XLOG_XACT_OPMASK)
308  {
309  case XLOG_XACT_COMMIT:
310  id = "COMMIT";
311  break;
312  case XLOG_XACT_PREPARE:
313  id = "PREPARE";
314  break;
315  case XLOG_XACT_ABORT:
316  id = "ABORT";
317  break;
319  id = "COMMIT_PREPARED";
320  break;
322  id = "ABORT_PREPARED";
323  break;
325  id = "ASSIGNMENT";
326  break;
327  }
328 
329  return id;
330 }
#define XLOG_XACT_COMMIT
Definition: xact.h:115
#define XLOG_XACT_PREPARE
Definition: xact.h:116
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:119
#define XLOG_XACT_ASSIGNMENT
Definition: xact.h:120
#define NULL
Definition: c.h:226
#define XLOG_XACT_ABORT
Definition: xact.h:117
#define XLOG_XACT_OPMASK
Definition: xact.h:125
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:118
void xact_redo ( XLogReaderState record)

Definition at line 5583 of file xact.c.

References Assert, elog, XLogReaderState::EndRecPtr, xl_xact_assignment::nsubxacts, PANIC, ParseAbortRecord(), ParseCommitRecord(), ProcArrayApplyXidAssignment(), RecreateTwoPhaseFile(), RemoveTwoPhaseFile(), STANDBY_INITIALIZED, standbyState, TransactionIdIsValid, xl_xact_parsed_commit::twophase_xid, xl_xact_parsed_abort::twophase_xid, xact_redo_abort(), xact_redo_commit(), XLOG_XACT_ABORT, XLOG_XACT_ABORT_PREPARED, XLOG_XACT_ASSIGNMENT, XLOG_XACT_COMMIT, XLOG_XACT_COMMIT_PREPARED, XLOG_XACT_OPMASK, XLOG_XACT_PREPARE, XLogRecGetData, XLogRecGetDataLen, XLogRecGetInfo, XLogRecGetOrigin, XLogRecGetXid, XLogRecHasAnyBlockRefs, xl_xact_assignment::xsub, and xl_xact_assignment::xtop.

5584 {
5585  uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
5586 
5587  /* Backup blocks are not used in xact records */
5588  Assert(!XLogRecHasAnyBlockRefs(record));
5589 
5590  if (info == XLOG_XACT_COMMIT || info == XLOG_XACT_COMMIT_PREPARED)
5591  {
5592  xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
5593  xl_xact_parsed_commit parsed;
5594 
5595  ParseCommitRecord(XLogRecGetInfo(record), xlrec,
5596  &parsed);
5597 
5598  if (info == XLOG_XACT_COMMIT)
5599  {
5601  xact_redo_commit(&parsed, XLogRecGetXid(record),
5602  record->EndRecPtr, XLogRecGetOrigin(record));
5603  }
5604  else
5605  {
5607  xact_redo_commit(&parsed, parsed.twophase_xid,
5608  record->EndRecPtr, XLogRecGetOrigin(record));
5609  RemoveTwoPhaseFile(parsed.twophase_xid, false);
5610  }
5611  }
5612  else if (info == XLOG_XACT_ABORT || info == XLOG_XACT_ABORT_PREPARED)
5613  {
5614  xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
5615  xl_xact_parsed_abort parsed;
5616 
5617  ParseAbortRecord(XLogRecGetInfo(record), xlrec,
5618  &parsed);
5619 
5620  if (info == XLOG_XACT_ABORT)
5621  {
5623  xact_redo_abort(&parsed, XLogRecGetXid(record));
5624  }
5625  else
5626  {
5628  xact_redo_abort(&parsed, parsed.twophase_xid);
5629  RemoveTwoPhaseFile(parsed.twophase_xid, false);
5630  }
5631  }
5632  else if (info == XLOG_XACT_PREPARE)
5633  {
5634  /* the record contents are exactly the 2PC file */
5636  XLogRecGetData(record), XLogRecGetDataLen(record));
5637  }
5638  else if (info == XLOG_XACT_ASSIGNMENT)
5639  {
5641 
5644  xlrec->nsubxacts, xlrec->xsub);
5645  }
5646  else
5647  elog(PANIC, "xact_redo: unknown op code %u", info);
5648 }
#define XLOG_XACT_COMMIT
Definition: xact.h:115
#define XLOG_XACT_PREPARE
Definition: xact.h:116
void RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
Definition: twophase.c:1523
static void xact_redo_commit(xl_xact_parsed_commit *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:5336
TransactionId twophase_xid
Definition: xact.h:285
unsigned char uint8
Definition: c.h:263
TransactionId xtop
Definition: xact.h:163
TransactionId xsub[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:165
#define PANIC
Definition: elog.h:53
#define XLogRecGetOrigin(decoder)
Definition: xlogreader.h:201
XLogRecPtr EndRecPtr
Definition: xlogreader.h:115
#define XLogRecGetData(decoder)
Definition: xlogreader.h:202
#define XLogRecGetDataLen(decoder)
Definition: xlogreader.h:203
void ParseCommitRecord(uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *parsed)
Definition: xactdesc.c:35
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:119
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:198
void RemoveTwoPhaseFile(TransactionId xid, bool giveWarning)
Definition: twophase.c:1503
#define XLogRecGetXid(decoder)
Definition: xlogreader.h:200
#define XLOG_XACT_ASSIGNMENT
Definition: xact.h:120
static void xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid)
Definition: xact.c:5506
TransactionId twophase_xid
Definition: xact.h:302
#define Assert(condition)
Definition: c.h:671
#define XLOG_XACT_ABORT
Definition: xact.h:117
#define XLOG_XACT_OPMASK
Definition: xact.h:125
void ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
Definition: xactdesc.c:122
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:204
void ProcArrayApplyXidAssignment(TransactionId topxid, int nsubxids, TransactionId *subxids)
Definition: procarray.c:911
#define elog
Definition: elog.h:219
#define TransactionIdIsValid(xid)
Definition: transam.h:41
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:118
HotStandbyState standbyState
Definition: xlog.c:194
int xactGetCommittedChildren ( TransactionId **  ptr)

Definition at line 5082 of file xact.c.

References TransactionStateData::childXids, CurrentTransactionState, TransactionStateData::nChildXids, and NULL.

Referenced by ExportSnapshot(), RecordTransactionAbort(), RecordTransactionCommit(), and StartPrepare().

5083 {
5085 
5086  if (s->nChildXids == 0)
5087  *ptr = NULL;
5088  else
5089  *ptr = s->childXids;
5090 
5091  return s->nChildXids;
5092 }
static TransactionState CurrentTransactionState
Definition: xact.c:231
TransactionId * childXids
Definition: xact.c:181
#define NULL
Definition: c.h:226
XLogRecPtr XactLogAbortRecord ( TimestampTz  abort_time,
int  nsubxacts,
TransactionId subxacts,
int  nrels,
RelFileNode rels,
TransactionId  twophase_xid 
)

Definition at line 5251 of file xact.c.

References Assert, CritSectionCount, MinSizeOfXactAbort, MinSizeOfXactRelfilenodes, MinSizeOfXactSubxacts, xl_xact_relfilenodes::nrels, xl_xact_subxacts::nsubxacts, TransactionIdIsValid, xl_xact_abort::xact_time, XACT_XINFO_HAS_RELFILENODES, XACT_XINFO_HAS_SUBXACTS, XACT_XINFO_HAS_TWOPHASE, xl_xact_twophase::xid, xl_xact_xinfo::xinfo, XLOG_XACT_ABORT, XLOG_XACT_ABORT_PREPARED, XLOG_XACT_HAS_INFO, XLogBeginInsert(), XLogInsert(), and XLogRegisterData().

Referenced by RecordTransactionAbort(), and RecordTransactionAbortPrepared().

5255 {
5256  xl_xact_abort xlrec;
5257  xl_xact_xinfo xl_xinfo;
5258  xl_xact_subxacts xl_subxacts;
5259  xl_xact_relfilenodes xl_relfilenodes;
5260  xl_xact_twophase xl_twophase;
5261 
5262  uint8 info;
5263 
5264  Assert(CritSectionCount > 0);
5265 
5266  xl_xinfo.xinfo = 0;
5267 
5268  /* decide between a plain and 2pc abort */
5269  if (!TransactionIdIsValid(twophase_xid))
5270  info = XLOG_XACT_ABORT;
5271  else
5272  info = XLOG_XACT_ABORT_PREPARED;
5273 
5274 
5275  /* First figure out and collect all the information needed */
5276 
5277  xlrec.xact_time = abort_time;
5278 
5279  if (nsubxacts > 0)
5280  {
5281  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5282  xl_subxacts.nsubxacts = nsubxacts;
5283  }
5284 
5285  if (nrels > 0)
5286  {
5287  xl_xinfo.xinfo |= XACT_XINFO_HAS_RELFILENODES;
5288  xl_relfilenodes.nrels = nrels;
5289  }
5290 
5291  if (TransactionIdIsValid(twophase_xid))
5292  {
5293  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5294  xl_twophase.xid = twophase_xid;
5295  }
5296 
5297  if (xl_xinfo.xinfo != 0)
5298  info |= XLOG_XACT_HAS_INFO;
5299 
5300  /* Then include all the collected data into the abort record. */
5301 
5302  XLogBeginInsert();
5303 
5304  XLogRegisterData((char *) (&xlrec), MinSizeOfXactAbort);
5305 
5306  if (xl_xinfo.xinfo != 0)
5307  XLogRegisterData((char *) (&xl_xinfo), sizeof(xl_xinfo));
5308 
5309  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5310  {
5311  XLogRegisterData((char *) (&xl_subxacts),
5313  XLogRegisterData((char *) subxacts,
5314  nsubxacts * sizeof(TransactionId));
5315  }
5316 
5317  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILENODES)
5318  {
5319  XLogRegisterData((char *) (&xl_relfilenodes),
5321  XLogRegisterData((char *) rels,
5322  nrels * sizeof(RelFileNode));
5323  }
5324 
5325  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5326  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5327 
5328  return XLogInsert(RM_XACT_ID, info);
5329 }
uint32 TransactionId
Definition: c.h:394
TransactionId xid
Definition: xact.h:226
unsigned char uint8
Definition: c.h:263
#define MinSizeOfXactAbort
Definition: xact.h:260
#define XLOG_XACT_HAS_INFO
Definition: xact.h:128
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:135
#define MinSizeOfXactRelfilenodes
Definition: xact.h:215
TimestampTz xact_time
Definition: xact.h:251
#define MinSizeOfXactSubxacts
Definition: xact.h:208
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:119
volatile uint32 CritSectionCount
Definition: globals.c:36
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:323
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:415
uint32 xinfo
Definition: xact.h:194
int nsubxacts
Definition: xact.h:205
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:138
#define Assert(condition)
Definition: c.h:671
#define XLOG_XACT_ABORT
Definition: xact.h:117
#define XACT_XINFO_HAS_RELFILENODES
Definition: xact.h:136
#define TransactionIdIsValid(xid)
Definition: transam.h:41
void XLogBeginInsert(void)
Definition: xloginsert.c:120
XLogRecPtr XactLogCommitRecord ( TimestampTz  commit_time,
int  nsubxacts,
TransactionId subxacts,
int  nrels,
RelFileNode rels,
int  nmsgs,
SharedInvalidationMessage msgs,
bool  relcacheInval,
bool  forceSync,
TransactionId  twophase_xid 
)

Definition at line 5106 of file xact.c.

References Assert, CritSectionCount, xl_xact_dbinfo::dbId, forceSyncCommit, InvalidRepOriginId, MinSizeOfXactInvals, MinSizeOfXactRelfilenodes, MinSizeOfXactSubxacts, MyDatabaseId, MyDatabaseTableSpace, xl_xact_invals::nmsgs, xl_xact_relfilenodes::nrels, xl_xact_subxacts::nsubxacts, xl_xact_origin::origin_lsn, xl_xact_origin::origin_timestamp, replorigin_session_origin, replorigin_session_origin_lsn, replorigin_session_origin_timestamp, synchronous_commit, SYNCHRONOUS_COMMIT_REMOTE_APPLY, TransactionIdIsValid, xl_xact_dbinfo::tsId, XACT_COMPLETION_APPLY_FEEDBACK, XACT_COMPLETION_FORCE_SYNC_COMMIT, XACT_COMPLETION_UPDATE_RELCACHE_FILE, xl_xact_commit::xact_time, XACT_XINFO_HAS_DBINFO, XACT_XINFO_HAS_INVALS, XACT_XINFO_HAS_ORIGIN, XACT_XINFO_HAS_RELFILENODES, XACT_XINFO_HAS_SUBXACTS, XACT_XINFO_HAS_TWOPHASE, xl_xact_twophase::xid, xl_xact_xinfo::xinfo, XLOG_INCLUDE_ORIGIN, XLOG_XACT_COMMIT, XLOG_XACT_COMMIT_PREPARED, XLOG_XACT_HAS_INFO, XLogBeginInsert(), XLogInsert(), XLogLogicalInfoActive, XLogRegisterData(), and XLogSetRecordFlags().

Referenced by RecordTransactionCommit(), and RecordTransactionCommitPrepared().

5112 {
5113  xl_xact_commit xlrec;
5114  xl_xact_xinfo xl_xinfo;
5115  xl_xact_dbinfo xl_dbinfo;
5116  xl_xact_subxacts xl_subxacts;
5117  xl_xact_relfilenodes xl_relfilenodes;
5118  xl_xact_invals xl_invals;
5119  xl_xact_twophase xl_twophase;
5120  xl_xact_origin xl_origin;
5121 
5122  uint8 info;
5123 
5124  Assert(CritSectionCount > 0);
5125 
5126  xl_xinfo.xinfo = 0;
5127 
5128  /* decide between a plain and 2pc commit */
5129  if (!TransactionIdIsValid(twophase_xid))
5130  info = XLOG_XACT_COMMIT;
5131  else
5133 
5134  /* First figure out and collect all the information needed */
5135 
5136  xlrec.xact_time = commit_time;
5137 
5138  if (relcacheInval)
5140  if (forceSyncCommit)
5142 
5143  /*
5144  * Check if the caller would like to ask standbys for immediate feedback
5145  * once this commit is applied.
5146  */
5149 
5150  /*
5151  * Relcache invalidations requires information about the current database
5152  * and so does logical decoding.
5153  */
5154  if (nmsgs > 0 || XLogLogicalInfoActive())
5155  {
5156  xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5157  xl_dbinfo.dbId = MyDatabaseId;
5158  xl_dbinfo.tsId = MyDatabaseTableSpace;
5159  }
5160 
5161  if (nsubxacts > 0)
5162  {
5163  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5164  xl_subxacts.nsubxacts = nsubxacts;
5165  }
5166 
5167  if (nrels > 0)
5168  {
5169  xl_xinfo.xinfo |= XACT_XINFO_HAS_RELFILENODES;
5170  xl_relfilenodes.nrels = nrels;
5171  }
5172 
5173  if (nmsgs > 0)
5174  {
5175  xl_xinfo.xinfo |= XACT_XINFO_HAS_INVALS;
5176  xl_invals.nmsgs = nmsgs;
5177  }
5178 
5179  if (TransactionIdIsValid(twophase_xid))
5180  {
5181  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5182  xl_twophase.xid = twophase_xid;
5183  }
5184 
5185  /* dump transaction origin information */
5187  {
5188  xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
5189 
5192  }
5193 
5194  if (xl_xinfo.xinfo != 0)
5195  info |= XLOG_XACT_HAS_INFO;
5196 
5197  /* Then include all the collected data into the commit record. */
5198 
5199  XLogBeginInsert();
5200 
5201  XLogRegisterData((char *) (&xlrec), sizeof(xl_xact_commit));
5202 
5203  if (xl_xinfo.xinfo != 0)
5204  XLogRegisterData((char *) (&xl_xinfo.xinfo), sizeof(xl_xinfo.xinfo));
5205 
5206  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5207  XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
5208 
5209  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5210  {
5211  XLogRegisterData((char *) (&xl_subxacts),
5213  XLogRegisterData((char *) subxacts,
5214  nsubxacts * sizeof(TransactionId));
5215  }
5216 
5217  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILENODES)
5218  {
5219  XLogRegisterData((char *) (&xl_relfilenodes),
5221  XLogRegisterData((char *) rels,
5222  nrels * sizeof(RelFileNode));
5223  }
5224 
5225  if (xl_xinfo.xinfo & XACT_XINFO_HAS_INVALS)
5226  {
5227  XLogRegisterData((char *) (&xl_invals), MinSizeOfXactInvals);
5228  XLogRegisterData((char *) msgs,
5229  nmsgs * sizeof(SharedInvalidationMessage));
5230  }
5231 
5232  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5233  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5234 
5235  if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5236  XLogRegisterData((char *) (&xl_origin), sizeof(xl_xact_origin));
5237 
5238  /* we allow filtering by xacts */
5240 
5241  return XLogInsert(RM_XACT_ID, info);
5242 }
#define XACT_COMPLETION_APPLY_FEEDBACK
Definition: xact.h:149
#define XACT_COMPLETION_UPDATE_RELCACHE_FILE
Definition: xact.h:150
#define XLOG_XACT_COMMIT
Definition: xact.h:115
#define XACT_XINFO_HAS_ORIGIN
Definition: xact.h:139
uint32 TransactionId
Definition: c.h:394
TransactionId xid
Definition: xact.h:226
unsigned char uint8
Definition: c.h:263
#define XLOG_XACT_HAS_INFO
Definition: xact.h:128
#define XLOG_INCLUDE_ORIGIN
Definition: xlog.h:192
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:135
#define MinSizeOfXactRelfilenodes
Definition: xact.h:215
Oid tsId
Definition: xact.h:200
Oid MyDatabaseTableSpace
Definition: globals.c:78
static bool forceSyncCommit
Definition: xact.c:261
#define MinSizeOfXactSubxacts
Definition: xact.h:208
#define XLogLogicalInfoActive()
Definition: xlog.h:162
XLogRecPtr replorigin_session_origin_lsn
Definition: origin.c:151
TimestampTz replorigin_session_origin_timestamp
Definition: origin.c:152
TimestampTz xact_time
Definition: xact.h:237
#define MinSizeOfXactInvals
Definition: xact.h:222
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:397
volatile uint32 CritSectionCount
Definition: globals.c:36
#define XACT_XINFO_HAS_DBINFO
Definition: xact.h:134
int synchronous_commit
Definition: xact.c:82
XLogRecPtr origin_lsn
Definition: xact.h:231
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:323
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:415
uint32 xinfo
Definition: xact.h:194
Oid MyDatabaseId
Definition: globals.c:76
int nsubxacts
Definition: xact.h:205
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:138
Oid dbId
Definition: xact.h:199
#define XACT_COMPLETION_FORCE_SYNC_COMMIT
Definition: xact.h:151
#define Assert(condition)
Definition: c.h:671
RepOriginId replorigin_session_origin
Definition: origin.c:150
#define InvalidRepOriginId
Definition: origin.h:34
TimestampTz origin_timestamp
Definition: xact.h:232
#define XACT_XINFO_HAS_INVALS
Definition: xact.h:137
#define XACT_XINFO_HAS_RELFILENODES
Definition: xact.h:136
#define TransactionIdIsValid(xid)
Definition: transam.h:41
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:118
void XLogBeginInsert(void)
Definition: xloginsert.c:120
int nmsgs
Definition: xact.h:219

Variable Documentation

bool DefaultXactDeferrable

Definition at line 79 of file xact.c.

Referenced by StartTransaction().

int DefaultXactIsoLevel

Definition at line 73 of file xact.c.

Referenced by check_XactIsoLevel(), and StartTransaction().

bool DefaultXactReadOnly

Definition at line 76 of file xact.c.

Referenced by StartTransaction().

bool MyXactAccessedTempRel
int synchronous_commit

Definition at line 82 of file xact.c.

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