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 XACT_FLAGS_ACCESSEDTEMPREL   (1U << 0)
 
#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK   (1U << 1)
 
#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_XINFO_HAS_AE_LOCKS   (1U << 6)
 
#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, int xactflags, TransactionId twophase_xid)
 
XLogRecPtr XactLogAbortRecord (TimestampTz abort_time, int nsubxacts, TransactionId *subxacts, int nrels, RelFileNode *rels, int xactflags, 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
 
int MyXactFlags
 

Macro Definition Documentation

#define MinSizeOfXactAbort   sizeof(xl_xact_abort)

Definition at line 280 of file xact.h.

Referenced by ParseAbortRecord(), and XactLogAbortRecord().

#define MinSizeOfXactAssignment   offsetof(xl_xact_assignment, xsub)

Definition at line 188 of file xact.h.

Referenced by AssignTransactionId().

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

Definition at line 267 of file xact.h.

Referenced by ParseCommitRecord().

#define MinSizeOfXactInvals   offsetof(xl_xact_invals, msgs)

Definition at line 242 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 169 of file xact.h.

Referenced by XactLogCommitRecord().

#define XACT_COMPLETION_FORCE_SYNC_COMMIT   (1U << 31)

Definition at line 171 of file xact.h.

Referenced by XactLogCommitRecord().

#define XACT_COMPLETION_UPDATE_RELCACHE_FILE   (1U << 30)

Definition at line 170 of file xact.h.

Referenced by XactLogCommitRecord().

#define XACT_FLAGS_ACCESSEDTEMPREL   (1U << 0)
#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK   (1U << 1)
#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
#define XACT_SERIALIZABLE   3

Definition at line 31 of file xact.h.

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

#define XACT_XINFO_HAS_AE_LOCKS   (1U << 6)

Definition at line 159 of file xact.h.

Referenced by xact_redo_abort(), xact_redo_commit(), XactLogAbortRecord(), and XactLogCommitRecord().

#define XACT_XINFO_HAS_DBINFO   (1U << 0)

Definition at line 153 of file xact.h.

Referenced by ParseCommitRecord(), and XactLogCommitRecord().

#define XACT_XINFO_HAS_INVALS   (1U << 3)

Definition at line 156 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 174 of file xact.h.

Referenced by xact_redo_commit().

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

Definition at line 178 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 176 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 139 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 135 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 121 of file xact.h.

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

Definition at line 111 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 113 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 99 of file xact.h.

Function Documentation

void AbortCurrentTransaction ( void  )

Definition at line 2986 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().

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

Definition at line 4222 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(), perform_work_item(), RemoveTempRelationsCallback(), and ShutdownPostgres().

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

Definition at line 4053 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(), pltcl_subtransaction(), PLy_spi_subtransaction_begin(), PLy_subtransaction_enter(), ReorderBufferCommit(), and ReorderBufferImmediateInvalidation().

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

Definition at line 3415 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().

3416 {
3418 
3419  switch (s->blockState)
3420  {
3421  /*
3422  * We are not inside a transaction block, so allow one to begin.
3423  */
3424  case TBLOCK_STARTED:
3425  s->blockState = TBLOCK_BEGIN;
3426  break;
3427 
3428  /*
3429  * Already a transaction block in progress.
3430  */
3431  case TBLOCK_INPROGRESS:
3433  case TBLOCK_SUBINPROGRESS:
3434  case TBLOCK_ABORT:
3435  case TBLOCK_SUBABORT:
3436  ereport(WARNING,
3437  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3438  errmsg("there is already a transaction in progress")));
3439  break;
3440 
3441  /* These cases are invalid. */
3442  case TBLOCK_DEFAULT:
3443  case TBLOCK_BEGIN:
3444  case TBLOCK_SUBBEGIN:
3445  case TBLOCK_END:
3446  case TBLOCK_SUBRELEASE:
3447  case TBLOCK_SUBCOMMIT:
3448  case TBLOCK_ABORT_END:
3449  case TBLOCK_SUBABORT_END:
3450  case TBLOCK_ABORT_PENDING:
3452  case TBLOCK_SUBRESTART:
3454  case TBLOCK_PREPARE:
3455  elog(FATAL, "BeginTransactionBlock: unexpected state %s",
3457  break;
3458  }
3459 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
int errcode(int sqlerrcode)
Definition: elog.c:575
TBlockState blockState
Definition: xact.c:177
#define FATAL
Definition: elog.h:52
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5003
#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 922 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(), ATExecDropIdentity(), 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(), LogicalRepSyncTableStart(), 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().

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

Definition at line 2747 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(), ApplyWorkerMain(), BeginInternalSubTransaction(), BootstrapModeMain(), cluster(), CommitTransactionCommand(), DefineIndex(), do_autovacuum(), finish_xact_command(), get_database_list(), get_subscription_list(), IdentifySystem(), index_drop(), initialize_worker_spi(), InitPostgres(), LogicalRepSyncTableStart(), movedb(), ParallelWorkerMain(), pg_attribute_noreturn(), process_syncing_tables_for_apply(), ProcessCatchupInterrupt(), ProcessCompletedNotifies(), ProcessIncomingNotify(), ReindexMultipleTables(), RemoveTempRelationsCallback(), reread_subscription(), vacuum(), and vacuum_rel().

2748 {
2750 
2751  switch (s->blockState)
2752  {
2753  /*
2754  * These shouldn't happen. TBLOCK_DEFAULT means the previous
2755  * StartTransactionCommand didn't set the STARTED state
2756  * appropriately, while TBLOCK_PARALLEL_INPROGRESS should be ended
2757  * by EndParallelWorkerTransaction(), not this function.
2758  */
2759  case TBLOCK_DEFAULT:
2761  elog(FATAL, "CommitTransactionCommand: unexpected state %s",
2763  break;
2764 
2765  /*
2766  * If we aren't in a transaction block, just do our usual
2767  * transaction commit, and return to the idle state.
2768  */
2769  case TBLOCK_STARTED:
2772  break;
2773 
2774  /*
2775  * We are completing a "BEGIN TRANSACTION" command, so we change
2776  * to the "transaction block in progress" state and return. (We
2777  * assume the BEGIN did nothing to the database, so we need no
2778  * CommandCounterIncrement.)
2779  */
2780  case TBLOCK_BEGIN:
2782  break;
2783 
2784  /*
2785  * This is the case when we have finished executing a command
2786  * someplace within a transaction block. We increment the command
2787  * counter and return.
2788  */
2789  case TBLOCK_INPROGRESS:
2790  case TBLOCK_SUBINPROGRESS:
2792  break;
2793 
2794  /*
2795  * We are completing a "COMMIT" command. Do it and return to the
2796  * idle state.
2797  */
2798  case TBLOCK_END:
2801  break;
2802 
2803  /*
2804  * Here we are in the middle of a transaction block but one of the
2805  * commands caused an abort so we do nothing but remain in the
2806  * abort state. Eventually we will get a ROLLBACK command.
2807  */
2808  case TBLOCK_ABORT:
2809  case TBLOCK_SUBABORT:
2810  break;
2811 
2812  /*
2813  * Here we were in an aborted transaction block and we just got
2814  * the ROLLBACK command from the user, so clean up the
2815  * already-aborted transaction and return to the idle state.
2816  */
2817  case TBLOCK_ABORT_END:
2820  break;
2821 
2822  /*
2823  * Here we were in a perfectly good transaction block but the user
2824  * told us to ROLLBACK anyway. We have to abort the transaction
2825  * and then clean up.
2826  */
2827  case TBLOCK_ABORT_PENDING:
2828  AbortTransaction();
2831  break;
2832 
2833  /*
2834  * We are completing a "PREPARE TRANSACTION" command. Do it and
2835  * return to the idle state.
2836  */
2837  case TBLOCK_PREPARE:
2840  break;
2841 
2842  /*
2843  * We were just issued a SAVEPOINT inside a transaction block.
2844  * Start a subtransaction. (DefineSavepoint already did
2845  * PushTransaction, so as to have someplace to put the SUBBEGIN
2846  * state.)
2847  */
2848  case TBLOCK_SUBBEGIN:
2851  break;
2852 
2853  /*
2854  * We were issued a RELEASE command, so we end the current
2855  * subtransaction and return to the parent transaction. The parent
2856  * might be ended too, so repeat till we find an INPROGRESS
2857  * transaction or subtransaction.
2858  */
2859  case TBLOCK_SUBRELEASE:
2860  do
2861  {
2863  s = CurrentTransactionState; /* changed by pop */
2864  } while (s->blockState == TBLOCK_SUBRELEASE);
2865 
2868  break;
2869 
2870  /*
2871  * We were issued a COMMIT, so we end the current subtransaction
2872  * hierarchy and perform final commit. We do this by rolling up
2873  * any subtransactions into their parent, which leads to O(N^2)
2874  * operations with respect to resource owners - this isn't that
2875  * bad until we approach a thousands of savepoints but is
2876  * necessary for correctness should after triggers create new
2877  * resource owners.
2878  */
2879  case TBLOCK_SUBCOMMIT:
2880  do
2881  {
2883  s = CurrentTransactionState; /* changed by pop */
2884  } while (s->blockState == TBLOCK_SUBCOMMIT);
2885  /* If we had a COMMIT command, finish off the main xact too */
2886  if (s->blockState == TBLOCK_END)
2887  {
2888  Assert(s->parent == NULL);
2891  }
2892  else if (s->blockState == TBLOCK_PREPARE)
2893  {
2894  Assert(s->parent == NULL);
2897  }
2898  else
2899  elog(ERROR, "CommitTransactionCommand: unexpected state %s",
2901  break;
2902 
2903  /*
2904  * The current already-failed subtransaction is ending due to a
2905  * ROLLBACK or ROLLBACK TO command, so pop it and recursively
2906  * examine the parent (which could be in any of several states).
2907  */
2908  case TBLOCK_SUBABORT_END:
2911  break;
2912 
2913  /*
2914  * As above, but it's not dead yet, so abort first.
2915  */
2920  break;
2921 
2922  /*
2923  * The current subtransaction is the target of a ROLLBACK TO
2924  * command. Abort and pop it, then start a new subtransaction
2925  * with the same name.
2926  */
2927  case TBLOCK_SUBRESTART:
2928  {
2929  char *name;
2930  int savepointLevel;
2931 
2932  /* save name and keep Cleanup from freeing it */
2933  name = s->name;
2934  s->name = NULL;
2935  savepointLevel = s->savepointLevel;
2936 
2939 
2941  s = CurrentTransactionState; /* changed by push */
2942  s->name = name;
2943  s->savepointLevel = savepointLevel;
2944 
2945  /* This is the same as TBLOCK_SUBBEGIN case */
2949  }
2950  break;
2951 
2952  /*
2953  * Same as above, but the subtransaction had already failed, so we
2954  * don't need AbortSubTransaction.
2955  */
2957  {
2958  char *name;
2959  int savepointLevel;
2960 
2961  /* save name and keep Cleanup from freeing it */
2962  name = s->name;
2963  s->name = NULL;
2964  savepointLevel = s->savepointLevel;
2965 
2967 
2969  s = CurrentTransactionState; /* changed by push */
2970  s->name = name;
2971  s->savepointLevel = savepointLevel;
2972 
2973  /* This is the same as TBLOCK_SUBBEGIN case */
2977  }
2978  break;
2979  }
2980 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
#define AssertState(condition)
Definition: c.h:678
void CommitTransactionCommand(void)
Definition: xact.c:2747
TBlockState blockState
Definition: xact.c:177
static void PrepareTransaction(void)
Definition: xact.c:2179
#define ERROR
Definition: elog.h:43
static void CommitSubTransaction(void)
Definition: xact.c:4437
#define FATAL
Definition: elog.h:52
static void CleanupTransaction(void)
Definition: xact.c:2628
struct TransactionStateData * parent
Definition: xact.c:191
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5003
static void AbortSubTransaction(void)
Definition: xact.c:4545
void DefineSavepoint(char *name)
Definition: xact.c:3748
void CommandCounterIncrement(void)
Definition: xact.c:922
static void AbortTransaction(void)
Definition: xact.c:2448
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
static void CleanupSubTransaction(void)
Definition: xact.c:4690
const char * name
Definition: encode.c:521
static void CommitTransaction(void)
Definition: xact.c:1940
#define elog
Definition: elog.h:219
static void StartSubTransaction(void)
Definition: xact.c:4399
void DefineSavepoint ( char *  name)

Definition at line 3748 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().

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

Definition at line 4940 of file xact.c.

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

Referenced by ParallelWorkerMain().

4941 {
4945 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
TBlockState blockState
Definition: xact.c:177
#define Assert(condition)
Definition: c.h:675
static void CommitTransaction(void)
Definition: xact.c:1940
bool EndTransactionBlock ( void  )

Definition at line 3525 of file xact.c.

References TransactionStateData::blockState, BlockStateAsString(), CurrentTransactionState, elog, ereport, errcode(), errmsg(), FATAL, NULL, TransactionStateData::parent, result, 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().

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

Definition at line 880 of file xact.c.

References Assert, CurrentTransactionState, and TransactionStateData::parallelModeLevel.

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

881 {
883 
884  Assert(s->parallelModeLevel >= 0);
885 
886  ++s->parallelModeLevel;
887 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
int parallelModeLevel
Definition: xact.c:190
#define Assert(condition)
Definition: c.h:675
Size EstimateTransactionStateSpace ( void  )

Definition at line 4816 of file xact.c.

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

Referenced by InitializeParallelDSM().

4817 {
4818  TransactionState s;
4819  Size nxids = 6; /* iso level, deferrable, top & current XID,
4820  * command counter, XID count */
4821 
4822  for (s = CurrentTransactionState; s != NULL; s = s->parent)
4823  {
4825  nxids = add_size(nxids, 1);
4826  nxids = add_size(nxids, s->nChildXids);
4827  }
4828 
4829  nxids = add_size(nxids, nParallelCurrentXids);
4830  return mul_size(nxids, sizeof(TransactionId));
4831 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
uint32 TransactionId
Definition: c.h:397
int nParallelCurrentXids
Definition: xact.c:108
struct TransactionStateData * parent
Definition: xact.c:191
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:172
#define NULL
Definition: c.h:229
size_t Size
Definition: c.h:356
#define TransactionIdIsValid(xid)
Definition: transam.h:41
void ExitParallelMode ( void  )

Definition at line 893 of file xact.c.

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

Referenced by ExecutePlan(), and ParallelWorkerMain().

894 {
896 
897  Assert(s->parallelModeLevel > 0);
899 
900  --s->parallelModeLevel;
901 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
bool ParallelContextActive(void)
Definition: parallel.c:668
int parallelModeLevel
Definition: xact.c:190
#define Assert(condition)
Definition: c.h:675
void ForceSyncCommit ( void  )

Definition at line 970 of file xact.c.

References forceSyncCommit.

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

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

Definition at line 687 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().

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

Definition at line 717 of file xact.c.

References stmtStartTimestamp.

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

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

Definition at line 434 of file xact.c.

References TransactionStateData::transactionId.

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

435 {
437 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
TransactionId transactionId
Definition: xact.c:172
TimestampTz GetCurrentTransactionStartTimestamp ( void  )
TimestampTz GetCurrentTransactionStopTimestamp ( void  )

Definition at line 729 of file xact.c.

References GetCurrentTimestamp(), and xactStopTimestamp.

Referenced by pgstat_report_stat().

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

Definition at line 461 of file xact.c.

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

Referenced by xid_age().

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

Definition at line 389 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(), nextval_internal(), SnapBuildInitialSnapshot(), and txid_current().

390 {
393  return XactTopTransactionId;
394 }
TransactionId XactTopTransactionId
Definition: xact.c:107
static TransactionStateData TopTransactionStateData
Definition: xact.c:201
#define TransactionIdIsValid(xid)
Definition: transam.h:41
static void AssignTransactionId(TransactionState s)
Definition: xact.c:489
bool IsInTransactionChain ( bool  isTopLevel)

Definition at line 3270 of file xact.c.

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

Referenced by vacuum().

3271 {
3272  /*
3273  * Return true on same conditions that would make PreventTransactionChain
3274  * error out
3275  */
3276  if (IsTransactionBlock())
3277  return true;
3278 
3279  if (IsSubTransaction())
3280  return true;
3281 
3282  if (!isTopLevel)
3283  return true;
3284 
3287  return true;
3288 
3289  return false;
3290 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
TBlockState blockState
Definition: xact.c:177
bool IsTransactionBlock(void)
Definition: xact.c:4304
bool IsSubTransaction(void)
Definition: xact.c:4376
bool IsTransactionBlock ( void  )

Definition at line 4304 of file xact.c.

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

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

4305 {
4307 
4309  return false;
4310 
4311  return true;
4312 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
TBlockState blockState
Definition: xact.c:177
bool IsTransactionOrTransactionBlock ( void  )

Definition at line 4322 of file xact.c.

References TransactionStateData::blockState, CurrentTransactionState, and TBLOCK_DEFAULT.

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

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

Definition at line 350 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_attribute_noreturn(), pg_do_encoding_conversion(), PrepareClientEncoding(), PrepareTempTablespaces(), process_syncing_tables_for_apply(), process_syncing_tables_for_sync(), RelationClearRelation(), RelationIdGetRelation(), RelationInitPhysicalAddr(), replorigin_create(), replorigin_drop(), reread_subscription(), SearchCatCache(), SetMultiXactIdLimit(), SetTransactionIdLimit(), SnapBuildClearExportedSnapshot(), and SocketBackend().

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

Definition at line 445 of file xact.c.

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

Referenced by XLogInsertRecord().

446 {
449 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
TransactionId transactionId
Definition: xact.c:172
#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:397
TransactionId xid
Definition: xact.h:246
#define MinSizeOfXactAbort
Definition: xact.h:280
#define XLOG_XACT_HAS_INFO
Definition: xact.h:147
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:154
#define MinSizeOfXactRelfilenodes
Definition: xact.h:235
TimestampTz xact_time
Definition: xact.h:271
RelFileNode xnodes[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:233
#define MinSizeOfXactSubxacts
Definition: xact.h:228
struct RelFileNode RelFileNode
struct xl_xact_twophase xl_xact_twophase
TransactionId * subxacts
Definition: xact.h:317
uint32 xinfo
Definition: xact.h:214
RelFileNode * xnodes
Definition: xact.h:320
int nsubxacts
Definition: xact.h:225
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:157
TransactionId twophase_xid
Definition: xact.h:322
TimestampTz xact_time
Definition: xact.h:313
#define XACT_XINFO_HAS_RELFILENODES
Definition: xact.h:155
TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:226
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:300
#define XACT_XINFO_HAS_ORIGIN
Definition: xact.h:158
struct xl_xact_xinfo xl_xact_xinfo
uint32 TransactionId
Definition: c.h:397
TimestampTz origin_timestamp
Definition: xact.h:308
TransactionId xid
Definition: xact.h:246
TransactionId twophase_xid
Definition: xact.h:305
TransactionId * subxacts
Definition: xact.h:297
#define XLOG_XACT_HAS_INFO
Definition: xact.h:147
SharedInvalidationMessage * msgs
Definition: xact.h:303
XLogRecPtr origin_lsn
Definition: xact.h:307
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:154
struct xl_xact_dbinfo xl_xact_dbinfo
#define MinSizeOfXactRelfilenodes
Definition: xact.h:235
Oid tsId
Definition: xact.h:220
struct xl_xact_origin xl_xact_origin
RelFileNode xnodes[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:233
#define MinSizeOfXactSubxacts
Definition: xact.h:228
#define MinSizeOfXactCommit
Definition: xact.h:267
SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:240
struct RelFileNode RelFileNode
TimestampTz xact_time
Definition: xact.h:257
struct xl_xact_twophase xl_xact_twophase
#define MinSizeOfXactInvals
Definition: xact.h:242
#define XACT_XINFO_HAS_DBINFO
Definition: xact.h:153
XLogRecPtr origin_lsn
Definition: xact.h:251
uint32 xinfo
Definition: xact.h:214
int nsubxacts
Definition: xact.h:225
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:157
Oid dbId
Definition: xact.h:219
TimestampTz origin_timestamp
Definition: xact.h:252
#define XACT_XINFO_HAS_INVALS
Definition: xact.h:156
#define XACT_XINFO_HAS_RELFILENODES
Definition: xact.h:155
int nmsgs
Definition: xact.h:239
TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:226
TimestampTz xact_time
Definition: xact.h:289
bool PrepareTransactionBlock ( char *  gid)

Definition at line 3474 of file xact.c.

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

Referenced by standard_ProcessUtility().

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

Definition at line 3154 of file xact.c.

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

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

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

Definition at line 3360 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().

3361 {
3362  SubXactCallbackItem *item;
3363 
3364  item = (SubXactCallbackItem *)
3366  item->callback = callback;
3367  item->arg = arg;
3368  item->next = SubXact_callbacks;
3369  SubXact_callbacks = item;
3370 }
static SubXactCallbackItem * SubXact_callbacks
Definition: xact.c:293
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
struct SubXactCallbackItem * next
Definition: xact.c:288
SubXactCallback callback
Definition: xact.c:289
MemoryContext TopMemoryContext
Definition: mcxt.c:43
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:707
void * arg
void RegisterXactCallback ( XactCallback  callback,
void *  arg 
)

Definition at line 3305 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().

3306 {
3307  XactCallbackItem *item;
3308 
3309  item = (XactCallbackItem *)
3311  item->callback = callback;
3312  item->arg = arg;
3313  item->next = Xact_callbacks;
3314  Xact_callbacks = item;
3315 }
struct XactCallbackItem * next
Definition: xact.c:276
void * arg
Definition: xact.c:278
XactCallback callback
Definition: xact.c:277
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
MemoryContext TopMemoryContext
Definition: mcxt.c:43
static XactCallbackItem * Xact_callbacks
Definition: xact.c:281
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:707
void * arg
void ReleaseCurrentSubTransaction ( void  )

Definition at line 4123 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(), pltcl_subtransaction(), PLy_spi_subtransaction_commit(), and PLy_subtransaction_exit().

4124 {
4126 
4127  /*
4128  * Workers synchronize transaction state at the beginning of each parallel
4129  * operation, so we can't account for commit of subtransactions after that
4130  * point. This should not happen anyway. Code calling this would
4131  * typically have called BeginInternalSubTransaction() first, failing
4132  * there.
4133  */
4134  if (IsInParallelMode())
4135  ereport(ERROR,
4136  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
4137  errmsg("cannot commit subtransactions during a parallel operation")));
4138 
4139  if (s->blockState != TBLOCK_SUBINPROGRESS)
4140  elog(ERROR, "ReleaseCurrentSubTransaction: unexpected state %s",
4142  Assert(s->state == TRANS_INPROGRESS);
4145  s = CurrentTransactionState; /* changed by pop */
4146  Assert(s->state == TRANS_INPROGRESS);
4147 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
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:177
TransState state
Definition: xact.c:176
bool IsInParallelMode(void)
Definition: xact.c:913
#define ERROR
Definition: elog.h:43
static void CommitSubTransaction(void)
Definition: xact.c:4437
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5003
#define ereport(elevel, rest)
Definition: elog.h:122
#define Assert(condition)
Definition: c.h:675
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
void ReleaseSavepoint ( List options)

Definition at line 3811 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().

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

Definition at line 3208 of file xact.c.

References CheckTransactionChain().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

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

Definition at line 4157 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(), pltcl_subtransaction(), PLy_abort_open_subtransactions(), PLy_spi_subtransaction_abort(), PLy_subtransaction_exit(), ReorderBufferCommit(), and ReorderBufferImmediateInvalidation().

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

Definition at line 3924 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().

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

Definition at line 4849 of file xact.c.

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

Referenced by InitializeParallelDSM().

4850 {
4851  TransactionState s;
4852  Size nxids = 0;
4853  Size i = 0;
4854  Size c = 0;
4855  TransactionId *workspace;
4856  TransactionId *result = (TransactionId *) start_address;
4857 
4858  result[c++] = (TransactionId) XactIsoLevel;
4859  result[c++] = (TransactionId) XactDeferrable;
4860  result[c++] = XactTopTransactionId;
4861  result[c++] = CurrentTransactionState->transactionId;
4862  result[c++] = (TransactionId) currentCommandId;
4863  Assert(maxsize >= c * sizeof(TransactionId));
4864 
4865  /*
4866  * If we're running in a parallel worker and launching a parallel worker
4867  * of our own, we can just pass along the information that was passed to
4868  * us.
4869  */
4870  if (nParallelCurrentXids > 0)
4871  {
4872  result[c++] = nParallelCurrentXids;
4873  Assert(maxsize >= (nParallelCurrentXids + c) * sizeof(TransactionId));
4874  memcpy(&result[c], ParallelCurrentXids,
4876  return;
4877  }
4878 
4879  /*
4880  * OK, we need to generate a sorted list of XIDs that our workers should
4881  * view as current. First, figure out how many there are.
4882  */
4883  for (s = CurrentTransactionState; s != NULL; s = s->parent)
4884  {
4886  nxids = add_size(nxids, 1);
4887  nxids = add_size(nxids, s->nChildXids);
4888  }
4889  Assert((c + 1 + nxids) * sizeof(TransactionId) <= maxsize);
4890 
4891  /* Copy them to our scratch space. */
4892  workspace = palloc(nxids * sizeof(TransactionId));
4893  for (s = CurrentTransactionState; s != NULL; s = s->parent)
4894  {
4896  workspace[i++] = s->transactionId;
4897  memcpy(&workspace[i], s->childXids,
4898  s->nChildXids * sizeof(TransactionId));
4899  i += s->nChildXids;
4900  }
4901  Assert(i == nxids);
4902 
4903  /* Sort them. */
4904  qsort(workspace, nxids, sizeof(TransactionId), xidComparator);
4905 
4906  /* Copy data into output area. */
4907  result[c++] = (TransactionId) nxids;
4908  memcpy(&result[c], workspace, nxids * sizeof(TransactionId));
4909 }
TransactionId XactTopTransactionId
Definition: xact.c:107
bool XactDeferrable
Definition: xact.c:80
static TransactionState CurrentTransactionState
Definition: xact.c:232
uint32 TransactionId
Definition: c.h:397
return result
Definition: formatting.c:1618
int nParallelCurrentXids
Definition: xact.c:108
TransactionId * childXids
Definition: xact.c:182
struct TransactionStateData * parent
Definition: xact.c:191
char * c
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
TransactionId transactionId
Definition: xact.c:172
TransactionId * ParallelCurrentXids
Definition: xact.c:109
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
size_t Size
Definition: c.h:356
int XactIsoLevel
Definition: xact.c:74
void * palloc(Size size)
Definition: mcxt.c:849
int i
#define qsort(a, b, c, d)
Definition: port.h:440
static CommandId currentCommandId
Definition: xact.c:239
#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 740 of file xact.c.

References GetCurrentTimestamp(), and stmtStartTimestamp.

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

741 {
743 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1570
static TimestampTz stmtStartTimestamp
Definition: xact.c:250
void StartParallelWorkerTransaction ( char *  tstatespace)

Definition at line 4917 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().

4918 {
4919  TransactionId *tstate = (TransactionId *) tstatespace;
4920 
4922  StartTransaction();
4923 
4924  XactIsoLevel = (int) tstate[0];
4925  XactDeferrable = (bool) tstate[1];
4926  XactTopTransactionId = tstate[2];
4928  currentCommandId = tstate[4];
4929  nParallelCurrentXids = (int) tstate[5];
4930  ParallelCurrentXids = &tstate[6];
4931 
4933 }
TransactionId XactTopTransactionId
Definition: xact.c:107
bool XactDeferrable
Definition: xact.c:80
static TransactionState CurrentTransactionState
Definition: xact.c:232
uint32 TransactionId
Definition: c.h:397
int nParallelCurrentXids
Definition: xact.c:108
char bool
Definition: c.h:202
TBlockState blockState
Definition: xact.c:177
TransactionId transactionId
Definition: xact.c:172
static void StartTransaction(void)
Definition: xact.c:1802
TransactionId * ParallelCurrentXids
Definition: xact.c:109
#define Assert(condition)
Definition: c.h:675
int XactIsoLevel
Definition: xact.c:74
static CommandId currentCommandId
Definition: xact.c:239
void StartTransactionCommand ( void  )

Definition at line 2677 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 ApplyWorkerMain(), BeginInternalSubTransaction(), BootstrapModeMain(), cluster(), DefineIndex(), do_autovacuum(), ensure_transaction(), get_database_list(), get_subscription_list(), IdentifySystem(), index_drop(), initialize_worker_spi(), InitPostgres(), LogicalRepSyncTableStart(), movedb(), ParallelWorkerMain(), perform_work_item(), process_syncing_tables_for_apply(), ProcessCatchupInterrupt(), ProcessCompletedNotifies(), ProcessIncomingNotify(), ReindexMultipleTables(), RemoveTempRelationsCallback(), ReorderBufferCommit(), reread_subscription(), SnapBuildExportSnapshot(), start_xact_command(), vacuum(), and vacuum_rel().

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

Definition at line 663 of file xact.c.

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

Referenced by fmgr_sql().

664 {
666 
667  for (s = CurrentTransactionState; s != NULL; s = s->parent)
668  {
669  if (s->state == TRANS_ABORT)
670  continue;
671  if (s->subTransactionId == subxid)
672  return true;
673  }
674  return false;
675 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
TransState state
Definition: xact.c:176
struct TransactionStateData * parent
Definition: xact.c:191
SubTransactionId subTransactionId
Definition: xact.c:173
#define NULL
Definition: c.h:229
char TransactionBlockStatusCode ( void  )

Definition at line 4336 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().

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

Definition at line 773 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(), TransactionIdIsInProgress(), and txid_status().

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

Definition at line 3373 of file xact.c.

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

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

Definition at line 3318 of file xact.c.

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

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

Definition at line 3649 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().

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

References CheckTransactionChain().

Referenced by ExecSetVariableStmt(), and standard_ProcessUtility().

3203 {
3204  CheckTransactionChain(isTopLevel, false, stmtType);
3205 }
static void CheckTransactionChain(bool isTopLevel, bool throwError, const char *stmtType)
Definition: xact.c:3231
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:134
unsigned char uint8
Definition: c.h:266
TransactionId xtop
Definition: xact.h:183
#define XLogRecGetOrigin(decoder)
Definition: xlogreader.h:217
#define XLogRecGetData(decoder)
Definition: xlogreader.h:218
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:110
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:138
static void xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec)
Definition: xactdesc.c:226
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:214
#define XLOG_XACT_ASSIGNMENT
Definition: xact.h:139
#define XLOG_XACT_ABORT
Definition: xact.h:136
#define XLOG_XACT_OPMASK
Definition: xact.h:144
static void xact_desc_assignment(StringInfo buf, xl_xact_assignment *xlrec)
Definition: xactdesc.c:259
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:137
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:134
#define XLOG_XACT_PREPARE
Definition: xact.h:135
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:138
#define XLOG_XACT_ASSIGNMENT
Definition: xact.h:139
#define NULL
Definition: c.h:229
#define XLOG_XACT_ABORT
Definition: xact.h:136
#define XLOG_XACT_OPMASK
Definition: xact.h:144
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:137
void xact_redo ( XLogReaderState record)

Definition at line 5592 of file xact.c.

References Assert, elog, XLogReaderState::EndRecPtr, xl_xact_assignment::nsubxacts, PANIC, ParseAbortRecord(), ParseCommitRecord(), PrepareRedoAdd(), PrepareRedoRemove(), ProcArrayApplyXidAssignment(), XLogReaderState::ReadRecPtr, 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, XLogRecGetInfo, XLogRecGetOrigin, XLogRecGetXid, XLogRecHasAnyBlockRefs, xl_xact_assignment::xsub, and xl_xact_assignment::xtop.

5593 {
5594  uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
5595 
5596  /* Backup blocks are not used in xact records */
5597  Assert(!XLogRecHasAnyBlockRefs(record));
5598 
5599  if (info == XLOG_XACT_COMMIT || info == XLOG_XACT_COMMIT_PREPARED)
5600  {
5601  xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
5602  xl_xact_parsed_commit parsed;
5603 
5604  ParseCommitRecord(XLogRecGetInfo(record), xlrec,
5605  &parsed);
5606 
5607  if (info == XLOG_XACT_COMMIT)
5608  {
5610  xact_redo_commit(&parsed, XLogRecGetXid(record),
5611  record->EndRecPtr, XLogRecGetOrigin(record));
5612  }
5613  else
5614  {
5616  xact_redo_commit(&parsed, parsed.twophase_xid,
5617  record->EndRecPtr, XLogRecGetOrigin(record));
5618 
5619  /* Delete TwoPhaseState gxact entry and/or 2PC file. */
5620  PrepareRedoRemove(parsed.twophase_xid, false);
5621  }
5622  }
5623  else if (info == XLOG_XACT_ABORT || info == XLOG_XACT_ABORT_PREPARED)
5624  {
5625  xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
5626  xl_xact_parsed_abort parsed;
5627 
5628  ParseAbortRecord(XLogRecGetInfo(record), xlrec,
5629  &parsed);
5630 
5631  if (info == XLOG_XACT_ABORT)
5632  {
5634  xact_redo_abort(&parsed, XLogRecGetXid(record));
5635  }
5636  else
5637  {
5639  xact_redo_abort(&parsed, parsed.twophase_xid);
5640 
5641  /* Delete TwoPhaseState gxact entry and/or 2PC file. */
5642  PrepareRedoRemove(parsed.twophase_xid, false);
5643  }
5644  }
5645  else if (info == XLOG_XACT_PREPARE)
5646  {
5647  /*
5648  * Store xid and start/end pointers of the WAL record in
5649  * TwoPhaseState gxact entry.
5650  */
5652  record->ReadRecPtr,
5653  record->EndRecPtr);
5654  }
5655  else if (info == XLOG_XACT_ASSIGNMENT)
5656  {
5658 
5661  xlrec->nsubxacts, xlrec->xsub);
5662  }
5663  else
5664  elog(PANIC, "xact_redo: unknown op code %u", info);
5665 }
#define XLOG_XACT_COMMIT
Definition: xact.h:134
void PrepareRedoRemove(TransactionId xid, bool giveWarning)
Definition: twophase.c:2374
#define XLOG_XACT_PREPARE
Definition: xact.h:135
static void xact_redo_commit(xl_xact_parsed_commit *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:5343
TransactionId twophase_xid
Definition: xact.h:305
unsigned char uint8
Definition: c.h:266
TransactionId xtop
Definition: xact.h:183
TransactionId xsub[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:185
#define PANIC
Definition: elog.h:53
#define XLogRecGetOrigin(decoder)
Definition: xlogreader.h:217
XLogRecPtr EndRecPtr
Definition: xlogreader.h:115
#define XLogRecGetData(decoder)
Definition: xlogreader.h:218
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:138
XLogRecPtr ReadRecPtr
Definition: xlogreader.h:114
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:214
void PrepareRedoAdd(char *buf, XLogRecPtr start_lsn, XLogRecPtr end_lsn)
Definition: twophase.c:2312
#define XLogRecGetXid(decoder)
Definition: xlogreader.h:216
#define XLOG_XACT_ASSIGNMENT
Definition: xact.h:139
static void xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid)
Definition: xact.c:5514
TransactionId twophase_xid
Definition: xact.h:322
#define Assert(condition)
Definition: c.h:675
#define XLOG_XACT_ABORT
Definition: xact.h:136
#define XLOG_XACT_OPMASK
Definition: xact.h:144
void ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
Definition: xactdesc.c:122
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:220
void ProcArrayApplyXidAssignment(TransactionId topxid, int nsubxids, TransactionId *subxids)
Definition: procarray.c:914
#define elog
Definition: elog.h:219
#define TransactionIdIsValid(xid)
Definition: transam.h:41
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:137
HotStandbyState standbyState
Definition: xlog.c:195
int xactGetCommittedChildren ( TransactionId **  ptr)

Definition at line 5084 of file xact.c.

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

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

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

Definition at line 5255 of file xact.c.

References Assert, CritSectionCount, MinSizeOfXactAbort, MinSizeOfXactRelfilenodes, MinSizeOfXactSubxacts, xl_xact_relfilenodes::nrels, xl_xact_subxacts::nsubxacts, TransactionIdIsValid, XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK, xl_xact_abort::xact_time, XACT_XINFO_HAS_AE_LOCKS, 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().

5259 {
5260  xl_xact_abort xlrec;
5261  xl_xact_xinfo xl_xinfo;
5262  xl_xact_subxacts xl_subxacts;
5263  xl_xact_relfilenodes xl_relfilenodes;
5264  xl_xact_twophase xl_twophase;
5265 
5266  uint8 info;
5267 
5268  Assert(CritSectionCount > 0);
5269 
5270  xl_xinfo.xinfo = 0;
5271 
5272  /* decide between a plain and 2pc abort */
5273  if (!TransactionIdIsValid(twophase_xid))
5274  info = XLOG_XACT_ABORT;
5275  else
5276  info = XLOG_XACT_ABORT_PREPARED;
5277 
5278 
5279  /* First figure out and collect all the information needed */
5280 
5281  xlrec.xact_time = abort_time;
5282 
5283  if ((xactflags & XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK))
5284  xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5285 
5286  if (nsubxacts > 0)
5287  {
5288  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5289  xl_subxacts.nsubxacts = nsubxacts;
5290  }
5291 
5292  if (nrels > 0)
5293  {
5294  xl_xinfo.xinfo |= XACT_XINFO_HAS_RELFILENODES;
5295  xl_relfilenodes.nrels = nrels;
5296  }
5297 
5298  if (TransactionIdIsValid(twophase_xid))
5299  {
5300  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5301  xl_twophase.xid = twophase_xid;
5302  }
5303 
5304  if (xl_xinfo.xinfo != 0)
5305  info |= XLOG_XACT_HAS_INFO;
5306 
5307  /* Then include all the collected data into the abort record. */
5308 
5309  XLogBeginInsert();
5310 
5311  XLogRegisterData((char *) (&xlrec), MinSizeOfXactAbort);
5312 
5313  if (xl_xinfo.xinfo != 0)
5314  XLogRegisterData((char *) (&xl_xinfo), sizeof(xl_xinfo));
5315 
5316  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5317  {
5318  XLogRegisterData((char *) (&xl_subxacts),
5320  XLogRegisterData((char *) subxacts,
5321  nsubxacts * sizeof(TransactionId));
5322  }
5323 
5324  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILENODES)
5325  {
5326  XLogRegisterData((char *) (&xl_relfilenodes),
5328  XLogRegisterData((char *) rels,
5329  nrels * sizeof(RelFileNode));
5330  }
5331 
5332  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5333  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5334 
5335  return XLogInsert(RM_XACT_ID, info);
5336 }
uint32 TransactionId
Definition: c.h:397
TransactionId xid
Definition: xact.h:246
unsigned char uint8
Definition: c.h:266
#define MinSizeOfXactAbort
Definition: xact.h:280
#define XLOG_XACT_HAS_INFO
Definition: xact.h:147
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:154
#define MinSizeOfXactRelfilenodes
Definition: xact.h:235
TimestampTz xact_time
Definition: xact.h:271
#define XACT_XINFO_HAS_AE_LOCKS
Definition: xact.h:159
#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK
Definition: xact.h:93
#define MinSizeOfXactSubxacts
Definition: xact.h:228
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:138
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:214
int nsubxacts
Definition: xact.h:225
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:157
#define Assert(condition)
Definition: c.h:675
#define XLOG_XACT_ABORT
Definition: xact.h:136
#define XACT_XINFO_HAS_RELFILENODES
Definition: xact.h:155
#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,
int  xactflags,
TransactionId  twophase_xid 
)

Definition at line 5108 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, XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK, xl_xact_commit::xact_time, XACT_XINFO_HAS_AE_LOCKS, 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().

5114 {
5115  xl_xact_commit xlrec;
5116  xl_xact_xinfo xl_xinfo;
5117  xl_xact_dbinfo xl_dbinfo;
5118  xl_xact_subxacts xl_subxacts;
5119  xl_xact_relfilenodes xl_relfilenodes;
5120  xl_xact_invals xl_invals;
5121  xl_xact_twophase xl_twophase;
5122  xl_xact_origin xl_origin;
5123 
5124  uint8 info;
5125 
5126  Assert(CritSectionCount > 0);
5127 
5128  xl_xinfo.xinfo = 0;
5129 
5130  /* decide between a plain and 2pc commit */
5131  if (!TransactionIdIsValid(twophase_xid))
5132  info = XLOG_XACT_COMMIT;
5133  else
5135 
5136  /* First figure out and collect all the information needed */
5137 
5138  xlrec.xact_time = commit_time;
5139 
5140  if (relcacheInval)
5142  if (forceSyncCommit)
5144  if ((xactflags & XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK))
5145  xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5146 
5147  /*
5148  * Check if the caller would like to ask standbys for immediate feedback
5149  * once this commit is applied.
5150  */
5153 
5154  /*
5155  * Relcache invalidations requires information about the current database
5156  * and so does logical decoding.
5157  */
5158  if (nmsgs > 0 || XLogLogicalInfoActive())
5159  {
5160  xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5161  xl_dbinfo.dbId = MyDatabaseId;
5162  xl_dbinfo.tsId = MyDatabaseTableSpace;
5163  }
5164 
5165  if (nsubxacts > 0)
5166  {
5167  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5168  xl_subxacts.nsubxacts = nsubxacts;
5169  }
5170 
5171  if (nrels > 0)
5172  {
5173  xl_xinfo.xinfo |= XACT_XINFO_HAS_RELFILENODES;
5174  xl_relfilenodes.nrels = nrels;
5175  }
5176 
5177  if (nmsgs > 0)
5178  {
5179  xl_xinfo.xinfo |= XACT_XINFO_HAS_INVALS;
5180  xl_invals.nmsgs = nmsgs;
5181  }
5182 
5183  if (TransactionIdIsValid(twophase_xid))
5184  {
5185  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5186  xl_twophase.xid = twophase_xid;
5187  }
5188 
5189  /* dump transaction origin information */
5191  {
5192  xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
5193 
5196  }
5197 
5198  if (xl_xinfo.xinfo != 0)
5199  info |= XLOG_XACT_HAS_INFO;
5200 
5201  /* Then include all the collected data into the commit record. */
5202 
5203  XLogBeginInsert();
5204 
5205  XLogRegisterData((char *) (&xlrec), sizeof(xl_xact_commit));
5206 
5207  if (xl_xinfo.xinfo != 0)
5208  XLogRegisterData((char *) (&xl_xinfo.xinfo), sizeof(xl_xinfo.xinfo));
5209 
5210  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5211  XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
5212 
5213  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5214  {
5215  XLogRegisterData((char *) (&xl_subxacts),
5217  XLogRegisterData((char *) subxacts,
5218  nsubxacts * sizeof(TransactionId));
5219  }
5220 
5221  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILENODES)
5222  {
5223  XLogRegisterData((char *) (&xl_relfilenodes),
5225  XLogRegisterData((char *) rels,
5226  nrels * sizeof(RelFileNode));
5227  }
5228 
5229  if (xl_xinfo.xinfo & XACT_XINFO_HAS_INVALS)
5230  {
5231  XLogRegisterData((char *) (&xl_invals), MinSizeOfXactInvals);
5232  XLogRegisterData((char *) msgs,
5233  nmsgs * sizeof(SharedInvalidationMessage));
5234  }
5235 
5236  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5237  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5238 
5239  if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5240  XLogRegisterData((char *) (&xl_origin), sizeof(xl_xact_origin));
5241 
5242  /* we allow filtering by xacts */
5244 
5245  return XLogInsert(RM_XACT_ID, info);
5246 }
#define XACT_COMPLETION_APPLY_FEEDBACK
Definition: xact.h:169
#define XACT_COMPLETION_UPDATE_RELCACHE_FILE
Definition: xact.h:170
#define XLOG_XACT_COMMIT
Definition: xact.h:134
#define XACT_XINFO_HAS_ORIGIN
Definition: xact.h:158
uint32 TransactionId
Definition: c.h:397
TransactionId xid
Definition: xact.h:246
unsigned char uint8
Definition: c.h:266
#define XLOG_XACT_HAS_INFO
Definition: xact.h:147
#define XLOG_INCLUDE_ORIGIN
Definition: xlog.h:192
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:154
#define MinSizeOfXactRelfilenodes
Definition: xact.h:235
Oid tsId
Definition: xact.h:220
Oid MyDatabaseTableSpace
Definition: globals.c:78
static bool forceSyncCommit
Definition: xact.c:262
#define XACT_XINFO_HAS_AE_LOCKS
Definition: xact.h:159
#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK
Definition: xact.h:93
#define MinSizeOfXactSubxacts
Definition: xact.h:228
#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:257
#define MinSizeOfXactInvals
Definition: xact.h:242
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:397
volatile uint32 CritSectionCount
Definition: globals.c:36
#define XACT_XINFO_HAS_DBINFO
Definition: xact.h:153
int synchronous_commit
Definition: xact.c:82
XLogRecPtr origin_lsn
Definition: xact.h:251
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:214
Oid MyDatabaseId
Definition: globals.c:76
int nsubxacts
Definition: xact.h:225
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:157
Oid dbId
Definition: xact.h:219
#define XACT_COMPLETION_FORCE_SYNC_COMMIT
Definition: xact.h:171
#define Assert(condition)
Definition: c.h:675
RepOriginId replorigin_session_origin
Definition: origin.c:150
#define InvalidRepOriginId
Definition: origin.h:34
TimestampTz origin_timestamp
Definition: xact.h:252
#define XACT_XINFO_HAS_INVALS
Definition: xact.h:156
#define XACT_XINFO_HAS_RELFILENODES
Definition: xact.h:155
#define TransactionIdIsValid(xid)
Definition: transam.h:41
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:137
void XLogBeginInsert(void)
Definition: xloginsert.c:120
int nmsgs
Definition: xact.h:239

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().

int synchronous_commit