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 279 of file xact.h.

Referenced by ParseAbortRecord(), and XactLogAbortRecord().

#define MinSizeOfXactAssignment   offsetof(xl_xact_assignment, xsub)

Definition at line 187 of file xact.h.

Referenced by AssignTransactionId().

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

Definition at line 266 of file xact.h.

Referenced by ParseCommitRecord().

#define MinSizeOfXactInvals   offsetof(xl_xact_invals, msgs)

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

#define XACT_COMPLETION_APPLY_FEEDBACK   (1U << 29)

Definition at line 168 of file xact.h.

Referenced by XactLogCommitRecord().

#define XACT_COMPLETION_FORCE_SYNC_COMMIT   (1U << 31)

Definition at line 170 of file xact.h.

Referenced by XactLogCommitRecord().

#define XACT_COMPLETION_UPDATE_RELCACHE_FILE   (1U << 30)

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

Referenced by ParseCommitRecord(), and XactLogCommitRecord().

#define XACT_XINFO_HAS_INVALS   (1U << 3)

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

Referenced by xact_redo_commit().

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

Definition at line 177 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 175 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 138 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 134 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 120 of file xact.h.

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

Definition at line 110 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 112 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 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 98 of file xact.h.

Function Documentation

void AbortCurrentTransaction ( void  )

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

2990 {
2992 
2993  switch (s->blockState)
2994  {
2995  case TBLOCK_DEFAULT:
2996  if (s->state == TRANS_DEFAULT)
2997  {
2998  /* we are idle, so nothing to do */
2999  }
3000  else
3001  {
3002  /*
3003  * We can get here after an error during transaction start
3004  * (state will be TRANS_START). Need to clean up the
3005  * incompletely started transaction. First, adjust the
3006  * low-level state to suppress warning message from
3007  * AbortTransaction.
3008  */
3009  if (s->state == TRANS_START)
3010  s->state = TRANS_INPROGRESS;
3011  AbortTransaction();
3013  }
3014  break;
3015 
3016  /*
3017  * if we aren't in a transaction block, we just do the basic abort
3018  * & cleanup transaction.
3019  */
3020  case TBLOCK_STARTED:
3021  AbortTransaction();
3024  break;
3025 
3026  /*
3027  * If we are in TBLOCK_BEGIN it means something screwed up right
3028  * after reading "BEGIN TRANSACTION". We assume that the user
3029  * will interpret the error as meaning the BEGIN failed to get him
3030  * into a transaction block, so we should abort and return to idle
3031  * state.
3032  */
3033  case TBLOCK_BEGIN:
3034  AbortTransaction();
3037  break;
3038 
3039  /*
3040  * We are somewhere in a transaction block and we've gotten a
3041  * failure, so we abort the transaction and set up the persistent
3042  * ABORT state. We will stay in ABORT until we get a ROLLBACK.
3043  */
3044  case TBLOCK_INPROGRESS:
3046  AbortTransaction();
3047  s->blockState = TBLOCK_ABORT;
3048  /* CleanupTransaction happens when we exit TBLOCK_ABORT_END */
3049  break;
3050 
3051  /*
3052  * Here, we failed while trying to COMMIT. Clean up the
3053  * transaction and return to idle state (we do not want to stay in
3054  * the transaction).
3055  */
3056  case TBLOCK_END:
3057  AbortTransaction();
3060  break;
3061 
3062  /*
3063  * Here, we are already in an aborted transaction state and are
3064  * waiting for a ROLLBACK, but for some reason we failed again! So
3065  * we just remain in the abort state.
3066  */
3067  case TBLOCK_ABORT:
3068  case TBLOCK_SUBABORT:
3069  break;
3070 
3071  /*
3072  * We are in a failed transaction and we got the ROLLBACK command.
3073  * We have already aborted, we just need to cleanup and go to idle
3074  * state.
3075  */
3076  case TBLOCK_ABORT_END:
3079  break;
3080 
3081  /*
3082  * We are in a live transaction and we got a ROLLBACK command.
3083  * Abort, cleanup, go to idle state.
3084  */
3085  case TBLOCK_ABORT_PENDING:
3086  AbortTransaction();
3089  break;
3090 
3091  /*
3092  * Here, we failed while trying to PREPARE. Clean up the
3093  * transaction and return to idle state (we do not want to stay in
3094  * the transaction).
3095  */
3096  case TBLOCK_PREPARE:
3097  AbortTransaction();
3100  break;
3101 
3102  /*
3103  * We got an error inside a subtransaction. Abort just the
3104  * subtransaction, and go to the persistent SUBABORT state until
3105  * we get ROLLBACK.
3106  */
3107  case TBLOCK_SUBINPROGRESS:
3110  break;
3111 
3112  /*
3113  * If we failed while trying to create a subtransaction, clean up
3114  * the broken subtransaction and abort the parent. The same
3115  * applies if we get a failure while ending a subtransaction.
3116  */
3117  case TBLOCK_SUBBEGIN:
3118  case TBLOCK_SUBRELEASE:
3119  case TBLOCK_SUBCOMMIT:
3121  case TBLOCK_SUBRESTART:
3125  break;
3126 
3127  /*
3128  * Same as above, except the Abort() was already done.
3129  */
3130  case TBLOCK_SUBABORT_END:
3134  break;
3135  }
3136 }
void AbortCurrentTransaction(void)
Definition: xact.c:2989
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:2631
static void AbortSubTransaction(void)
Definition: xact.c:4569
static void AbortTransaction(void)
Definition: xact.c:2451
static void CleanupSubTransaction(void)
Definition: xact.c:4714
void AbortOutOfAnyTransaction ( void  )

Definition at line 4225 of file xact.c.

References AbortSubTransaction(), AbortTransaction(), Assert, AtAbort_Memory(), AtAbort_Portals(), AtCleanup_Memory(), AtSubAbort_Portals(), TransactionStateData::blockState, CleanupSubTransaction(), CleanupTransaction(), CurrentTransactionState, TransactionStateData::curTransactionOwner, NULL, TransactionStateData::parent, TransactionStateData::state, TransactionStateData::subTransactionId, 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().

4226 {
4228 
4229  /* Ensure we're not running in a doomed memory context */
4230  AtAbort_Memory();
4231 
4232  /*
4233  * Get out of any transaction or nested transaction
4234  */
4235  do
4236  {
4237  switch (s->blockState)
4238  {
4239  case TBLOCK_DEFAULT:
4240  if (s->state == TRANS_DEFAULT)
4241  {
4242  /* Not in a transaction, do nothing */
4243  }
4244  else
4245  {
4246  /*
4247  * We can get here after an error during transaction start
4248  * (state will be TRANS_START). Need to clean up the
4249  * incompletely started transaction. First, adjust the
4250  * low-level state to suppress warning message from
4251  * AbortTransaction.
4252  */
4253  if (s->state == TRANS_START)
4254  s->state = TRANS_INPROGRESS;
4255  AbortTransaction();
4257  }
4258  break;
4259  case TBLOCK_STARTED:
4260  case TBLOCK_BEGIN:
4261  case TBLOCK_INPROGRESS:
4263  case TBLOCK_END:
4264  case TBLOCK_ABORT_PENDING:
4265  case TBLOCK_PREPARE:
4266  /* In a transaction, so clean up */
4267  AbortTransaction();
4270  break;
4271  case TBLOCK_ABORT:
4272  case TBLOCK_ABORT_END:
4273 
4274  /*
4275  * AbortTransaction is already done, still need Cleanup.
4276  * However, if we failed partway through running ROLLBACK,
4277  * there will be an active portal running that command, which
4278  * we need to shut down before doing CleanupTransaction.
4279  */
4280  AtAbort_Portals();
4283  break;
4284 
4285  /*
4286  * In a subtransaction, so clean it up and abort parent too
4287  */
4288  case TBLOCK_SUBBEGIN:
4289  case TBLOCK_SUBINPROGRESS:
4290  case TBLOCK_SUBRELEASE:
4291  case TBLOCK_SUBCOMMIT:
4293  case TBLOCK_SUBRESTART:
4296  s = CurrentTransactionState; /* changed by pop */
4297  break;
4298 
4299  case TBLOCK_SUBABORT:
4300  case TBLOCK_SUBABORT_END:
4302  /* As above, but AbortSubTransaction already done */
4303  if (s->curTransactionOwner)
4304  {
4305  /* As in TBLOCK_ABORT, might have a live portal to zap */
4310  }
4312  s = CurrentTransactionState; /* changed by pop */
4313  break;
4314  }
4315  } while (s->blockState != TBLOCK_DEFAULT);
4316 
4317  /* Should be out of all subxacts now */
4318  Assert(s->parent == NULL);
4319 
4320  /* If we didn't actually have anything to do, revert to TopMemoryContext */
4321  AtCleanup_Memory();
4322 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
static void AtCleanup_Memory(void)
Definition: xact.c:1731
void AtAbort_Portals(void)
Definition: portalmem.c:746
TBlockState blockState
Definition: xact.c:177
TransState state
Definition: xact.c:176
ResourceOwner curTransactionOwner
Definition: xact.c:181
static void CleanupTransaction(void)
Definition: xact.c:2631
struct TransactionStateData * parent
Definition: xact.c:191
SubTransactionId subTransactionId
Definition: xact.c:173
static void AbortSubTransaction(void)
Definition: xact.c:4569
static void AtAbort_Memory(void)
Definition: xact.c:1641
static void AbortTransaction(void)
Definition: xact.c:2451
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
void AtSubAbort_Portals(SubTransactionId mySubid, SubTransactionId parentSubid, ResourceOwner myXactOwner, ResourceOwner parentXactOwner)
Definition: portalmem.c:901
static void CleanupSubTransaction(void)
Definition: xact.c:4714
void BeginInternalSubTransaction ( char *  name)

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

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

3419 {
3421 
3422  switch (s->blockState)
3423  {
3424  /*
3425  * We are not inside a transaction block, so allow one to begin.
3426  */
3427  case TBLOCK_STARTED:
3428  s->blockState = TBLOCK_BEGIN;
3429  break;
3430 
3431  /*
3432  * Already a transaction block in progress.
3433  */
3434  case TBLOCK_INPROGRESS:
3436  case TBLOCK_SUBINPROGRESS:
3437  case TBLOCK_ABORT:
3438  case TBLOCK_SUBABORT:
3439  ereport(WARNING,
3440  (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
3441  errmsg("there is already a transaction in progress")));
3442  break;
3443 
3444  /* These cases are invalid. */
3445  case TBLOCK_DEFAULT:
3446  case TBLOCK_BEGIN:
3447  case TBLOCK_SUBBEGIN:
3448  case TBLOCK_END:
3449  case TBLOCK_SUBRELEASE:
3450  case TBLOCK_SUBCOMMIT:
3451  case TBLOCK_ABORT_END:
3452  case TBLOCK_SUBABORT_END:
3453  case TBLOCK_ABORT_PENDING:
3455  case TBLOCK_SUBRESTART:
3457  case TBLOCK_PREPARE:
3458  elog(FATAL, "BeginTransactionBlock: unexpected state %s",
3460  break;
3461  }
3462 }
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:5027
#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:544
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 2750 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(), maybe_reread_subscription(), movedb(), ParallelWorkerMain(), pg_attribute_noreturn(), process_syncing_tables_for_apply(), ProcessCatchupInterrupt(), ProcessCompletedNotifies(), ProcessIncomingNotify(), ReindexMultipleTables(), RemoveTempRelationsCallback(), vacuum(), and vacuum_rel().

2751 {
2753 
2754  switch (s->blockState)
2755  {
2756  /*
2757  * These shouldn't happen. TBLOCK_DEFAULT means the previous
2758  * StartTransactionCommand didn't set the STARTED state
2759  * appropriately, while TBLOCK_PARALLEL_INPROGRESS should be ended
2760  * by EndParallelWorkerTransaction(), not this function.
2761  */
2762  case TBLOCK_DEFAULT:
2764  elog(FATAL, "CommitTransactionCommand: unexpected state %s",
2766  break;
2767 
2768  /*
2769  * If we aren't in a transaction block, just do our usual
2770  * transaction commit, and return to the idle state.
2771  */
2772  case TBLOCK_STARTED:
2775  break;
2776 
2777  /*
2778  * We are completing a "BEGIN TRANSACTION" command, so we change
2779  * to the "transaction block in progress" state and return. (We
2780  * assume the BEGIN did nothing to the database, so we need no
2781  * CommandCounterIncrement.)
2782  */
2783  case TBLOCK_BEGIN:
2785  break;
2786 
2787  /*
2788  * This is the case when we have finished executing a command
2789  * someplace within a transaction block. We increment the command
2790  * counter and return.
2791  */
2792  case TBLOCK_INPROGRESS:
2793  case TBLOCK_SUBINPROGRESS:
2795  break;
2796 
2797  /*
2798  * We are completing a "COMMIT" command. Do it and return to the
2799  * idle state.
2800  */
2801  case TBLOCK_END:
2804  break;
2805 
2806  /*
2807  * Here we are in the middle of a transaction block but one of the
2808  * commands caused an abort so we do nothing but remain in the
2809  * abort state. Eventually we will get a ROLLBACK command.
2810  */
2811  case TBLOCK_ABORT:
2812  case TBLOCK_SUBABORT:
2813  break;
2814 
2815  /*
2816  * Here we were in an aborted transaction block and we just got
2817  * the ROLLBACK command from the user, so clean up the
2818  * already-aborted transaction and return to the idle state.
2819  */
2820  case TBLOCK_ABORT_END:
2823  break;
2824 
2825  /*
2826  * Here we were in a perfectly good transaction block but the user
2827  * told us to ROLLBACK anyway. We have to abort the transaction
2828  * and then clean up.
2829  */
2830  case TBLOCK_ABORT_PENDING:
2831  AbortTransaction();
2834  break;
2835 
2836  /*
2837  * We are completing a "PREPARE TRANSACTION" command. Do it and
2838  * return to the idle state.
2839  */
2840  case TBLOCK_PREPARE:
2843  break;
2844 
2845  /*
2846  * We were just issued a SAVEPOINT inside a transaction block.
2847  * Start a subtransaction. (DefineSavepoint already did
2848  * PushTransaction, so as to have someplace to put the SUBBEGIN
2849  * state.)
2850  */
2851  case TBLOCK_SUBBEGIN:
2854  break;
2855 
2856  /*
2857  * We were issued a RELEASE command, so we end the current
2858  * subtransaction and return to the parent transaction. The parent
2859  * might be ended too, so repeat till we find an INPROGRESS
2860  * transaction or subtransaction.
2861  */
2862  case TBLOCK_SUBRELEASE:
2863  do
2864  {
2866  s = CurrentTransactionState; /* changed by pop */
2867  } while (s->blockState == TBLOCK_SUBRELEASE);
2868 
2871  break;
2872 
2873  /*
2874  * We were issued a COMMIT, so we end the current subtransaction
2875  * hierarchy and perform final commit. We do this by rolling up
2876  * any subtransactions into their parent, which leads to O(N^2)
2877  * operations with respect to resource owners - this isn't that
2878  * bad until we approach a thousands of savepoints but is
2879  * necessary for correctness should after triggers create new
2880  * resource owners.
2881  */
2882  case TBLOCK_SUBCOMMIT:
2883  do
2884  {
2886  s = CurrentTransactionState; /* changed by pop */
2887  } while (s->blockState == TBLOCK_SUBCOMMIT);
2888  /* If we had a COMMIT command, finish off the main xact too */
2889  if (s->blockState == TBLOCK_END)
2890  {
2891  Assert(s->parent == NULL);
2894  }
2895  else if (s->blockState == TBLOCK_PREPARE)
2896  {
2897  Assert(s->parent == NULL);
2900  }
2901  else
2902  elog(ERROR, "CommitTransactionCommand: unexpected state %s",
2904  break;
2905 
2906  /*
2907  * The current already-failed subtransaction is ending due to a
2908  * ROLLBACK or ROLLBACK TO command, so pop it and recursively
2909  * examine the parent (which could be in any of several states).
2910  */
2911  case TBLOCK_SUBABORT_END:
2914  break;
2915 
2916  /*
2917  * As above, but it's not dead yet, so abort first.
2918  */
2923  break;
2924 
2925  /*
2926  * The current subtransaction is the target of a ROLLBACK TO
2927  * command. Abort and pop it, then start a new subtransaction
2928  * with the same name.
2929  */
2930  case TBLOCK_SUBRESTART:
2931  {
2932  char *name;
2933  int savepointLevel;
2934 
2935  /* save name and keep Cleanup from freeing it */
2936  name = s->name;
2937  s->name = NULL;
2938  savepointLevel = s->savepointLevel;
2939 
2942 
2944  s = CurrentTransactionState; /* changed by push */
2945  s->name = name;
2946  s->savepointLevel = savepointLevel;
2947 
2948  /* This is the same as TBLOCK_SUBBEGIN case */
2952  }
2953  break;
2954 
2955  /*
2956  * Same as above, but the subtransaction had already failed, so we
2957  * don't need AbortSubTransaction.
2958  */
2960  {
2961  char *name;
2962  int savepointLevel;
2963 
2964  /* save name and keep Cleanup from freeing it */
2965  name = s->name;
2966  s->name = NULL;
2967  savepointLevel = s->savepointLevel;
2968 
2970 
2972  s = CurrentTransactionState; /* changed by push */
2973  s->name = name;
2974  s->savepointLevel = savepointLevel;
2975 
2976  /* This is the same as TBLOCK_SUBBEGIN case */
2980  }
2981  break;
2982  }
2983 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
#define AssertState(condition)
Definition: c.h:679
void CommitTransactionCommand(void)
Definition: xact.c:2750
TBlockState blockState
Definition: xact.c:177
static void PrepareTransaction(void)
Definition: xact.c:2176
#define ERROR
Definition: elog.h:43
static void CommitSubTransaction(void)
Definition: xact.c:4461
#define FATAL
Definition: elog.h:52
static void CleanupTransaction(void)
Definition: xact.c:2631
struct TransactionStateData * parent
Definition: xact.c:191
static const char * BlockStateAsString(TBlockState blockState)
Definition: xact.c:5027
static void AbortSubTransaction(void)
Definition: xact.c:4569
void DefineSavepoint(char *name)
Definition: xact.c:3751
void CommandCounterIncrement(void)
Definition: xact.c:922
static void AbortTransaction(void)
Definition: xact.c:2451
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
static void CleanupSubTransaction(void)
Definition: xact.c:4714
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:4423
void DefineSavepoint ( char *  name)

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

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

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

Referenced by ParallelWorkerMain().

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

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

3529 {
3531  bool result = false;
3532 
3533  switch (s->blockState)
3534  {
3535  /*
3536  * We are in a transaction block, so tell CommitTransactionCommand
3537  * to COMMIT.
3538  */
3539  case TBLOCK_INPROGRESS:
3540  s->blockState = TBLOCK_END;
3541  result = true;
3542  break;
3543 
3544  /*
3545  * We are in a failed transaction block. Tell
3546  * CommitTransactionCommand it's time to exit the block.
3547  */
3548  case TBLOCK_ABORT:
3550  break;
3551 
3552  /*
3553  * We are in a live subtransaction block. Set up to subcommit all
3554  * open subtransactions and then commit the main transaction.
3555  */
3556  case TBLOCK_SUBINPROGRESS:
3557  while (s->parent != NULL)
3558  {
3559  if (s->blockState == TBLOCK_SUBINPROGRESS)
3561  else
3562  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3564  s = s->parent;
3565  }
3566  if (s->blockState == TBLOCK_INPROGRESS)
3567  s->blockState = TBLOCK_END;
3568  else
3569  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3571  result = true;
3572  break;
3573 
3574  /*
3575  * Here we are inside an aborted subtransaction. Treat the COMMIT
3576  * as ROLLBACK: set up to abort everything and exit the main
3577  * transaction.
3578  */
3579  case TBLOCK_SUBABORT:
3580  while (s->parent != NULL)
3581  {
3582  if (s->blockState == TBLOCK_SUBINPROGRESS)
3584  else if (s->blockState == TBLOCK_SUBABORT)
3586  else
3587  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3589  s = s->parent;
3590  }
3591  if (s->blockState == TBLOCK_INPROGRESS)
3593  else if (s->blockState == TBLOCK_ABORT)
3595  else
3596  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3598  break;
3599 
3600  /*
3601  * The user issued COMMIT when not inside a transaction. Issue a
3602  * WARNING, staying in TBLOCK_STARTED state. The upcoming call to
3603  * CommitTransactionCommand() will then close the transaction and
3604  * put us back into the default state.
3605  */
3606  case TBLOCK_STARTED:
3607  ereport(WARNING,
3608  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
3609  errmsg("there is no transaction in progress")));
3610  result = true;
3611  break;
3612 
3613  /*
3614  * The user issued a COMMIT that somehow ran inside a parallel
3615  * worker. We can't cope with that.
3616  */
3618  ereport(FATAL,
3619  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
3620  errmsg("cannot commit during a parallel operation")));
3621  break;
3622 
3623  /* These cases are invalid. */
3624  case TBLOCK_DEFAULT:
3625  case TBLOCK_BEGIN:
3626  case TBLOCK_SUBBEGIN:
3627  case TBLOCK_END:
3628  case TBLOCK_SUBRELEASE:
3629  case TBLOCK_SUBCOMMIT:
3630  case TBLOCK_ABORT_END:
3631  case TBLOCK_SUBABORT_END:
3632  case TBLOCK_ABORT_PENDING:
3634  case TBLOCK_SUBRESTART:
3636  case TBLOCK_PREPARE:
3637  elog(FATAL, "EndTransactionBlock: unexpected state %s",
3639  break;
3640  }
3641 
3642  return result;
3643 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1633
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:5027
#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:676
Size EstimateTransactionStateSpace ( void  )

Definition at line 4840 of file xact.c.

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

Referenced by InitializeParallelDSM().

4841 {
4842  TransactionState s;
4843  Size nxids = 6; /* iso level, deferrable, top & current XID,
4844  * command counter, XID count */
4845 
4846  for (s = CurrentTransactionState; s != NULL; s = s->parent)
4847  {
4849  nxids = add_size(nxids, 1);
4850  nxids = add_size(nxids, s->nChildXids);
4851  }
4852 
4853  nxids = add_size(nxids, nParallelCurrentXids);
4854  return mul_size(nxids, sizeof(TransactionId));
4855 }
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:676
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:676
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:676
#define InvalidLocalTransactionId
Definition: lock.h:69
#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(), do_setval(), fill_seq_with_data(), log_heap_new_cid(), nextval_internal(), 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 3273 of file xact.c.

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

Referenced by vacuum().

3274 {
3275  /*
3276  * Return true on same conditions that would make PreventTransactionChain
3277  * error out
3278  */
3279  if (IsTransactionBlock())
3280  return true;
3281 
3282  if (IsSubTransaction())
3283  return true;
3284 
3285  if (!isTopLevel)
3286  return true;
3287 
3290  return true;
3291 
3292  return false;
3293 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
TBlockState blockState
Definition: xact.c:177
bool IsTransactionBlock(void)
Definition: xact.c:4328
bool IsSubTransaction(void)
Definition: xact.c:4400
bool IsTransactionBlock ( void  )

Definition at line 4328 of file xact.c.

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

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

4329 {
4331 
4333  return false;
4334 
4335  return true;
4336 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
TBlockState blockState
Definition: xact.c:177
bool IsTransactionOrTransactionBlock ( void  )

Definition at line 4346 of file xact.c.

References TransactionStateData::blockState, CurrentTransactionState, and TBLOCK_DEFAULT.

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

4347 {
4349 
4350  if (s->blockState == TBLOCK_DEFAULT)
4351  return false;
4352 
4353  return true;
4354 }
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(), maybe_reread_subscription(), 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(), 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:245
#define MinSizeOfXactAbort
Definition: xact.h:279
#define XLOG_XACT_HAS_INFO
Definition: xact.h:146
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:153
#define MinSizeOfXactRelfilenodes
Definition: xact.h:234
TimestampTz xact_time
Definition: xact.h:270
RelFileNode xnodes[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:232
#define MinSizeOfXactSubxacts
Definition: xact.h:227
struct RelFileNode RelFileNode
struct xl_xact_twophase xl_xact_twophase
TransactionId * subxacts
Definition: xact.h:316
uint32 xinfo
Definition: xact.h:213
RelFileNode * xnodes
Definition: xact.h:319
int nsubxacts
Definition: xact.h:224
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:156
TransactionId twophase_xid
Definition: xact.h:321
TimestampTz xact_time
Definition: xact.h:312
#define XACT_XINFO_HAS_RELFILENODES
Definition: xact.h:154
TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:225
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:299
#define XACT_XINFO_HAS_ORIGIN
Definition: xact.h:157
struct xl_xact_xinfo xl_xact_xinfo
uint32 TransactionId
Definition: c.h:397
TimestampTz origin_timestamp
Definition: xact.h:307
TransactionId xid
Definition: xact.h:245
TransactionId twophase_xid
Definition: xact.h:304
TransactionId * subxacts
Definition: xact.h:296
#define XLOG_XACT_HAS_INFO
Definition: xact.h:146
SharedInvalidationMessage * msgs
Definition: xact.h:302
XLogRecPtr origin_lsn
Definition: xact.h:306
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:153
struct xl_xact_dbinfo xl_xact_dbinfo
#define MinSizeOfXactRelfilenodes
Definition: xact.h:234
Oid tsId
Definition: xact.h:219
struct xl_xact_origin xl_xact_origin
RelFileNode xnodes[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:232
#define MinSizeOfXactSubxacts
Definition: xact.h:227
#define MinSizeOfXactCommit
Definition: xact.h:266
SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:239
struct RelFileNode RelFileNode
TimestampTz xact_time
Definition: xact.h:256
struct xl_xact_twophase xl_xact_twophase
#define MinSizeOfXactInvals
Definition: xact.h:241
#define XACT_XINFO_HAS_DBINFO
Definition: xact.h:152
XLogRecPtr origin_lsn
Definition: xact.h:250
uint32 xinfo
Definition: xact.h:213
int nsubxacts
Definition: xact.h:224
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:156
Oid dbId
Definition: xact.h:218
TimestampTz origin_timestamp
Definition: xact.h:251
#define XACT_XINFO_HAS_INVALS
Definition: xact.h:155
#define XACT_XINFO_HAS_RELFILENODES
Definition: xact.h:154
int nmsgs
Definition: xact.h:238
TransactionId subxacts[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:225
TimestampTz xact_time
Definition: xact.h:288
bool PrepareTransactionBlock ( char *  gid)

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

3478 {
3479  TransactionState s;
3480  bool result;
3481 
3482  /* Set up to commit the current transaction */
3483  result = EndTransactionBlock();
3484 
3485  /* If successful, change outer tblock state to PREPARE */
3486  if (result)
3487  {
3489 
3490  while (s->parent != NULL)
3491  s = s->parent;
3492 
3493  if (s->blockState == TBLOCK_END)
3494  {
3495  /* Save GID where PrepareTransaction can find it again */
3497 
3499  }
3500  else
3501  {
3502  /*
3503  * ignore case where we are not in a transaction;
3504  * EndTransactionBlock already issued a warning.
3505  */
3507  /* Don't send back a PREPARE result tag... */
3508  result = false;
3509  }
3510  }
3511 
3512  return result;
3513 }
static TransactionState CurrentTransactionState
Definition: xact.c:232
MemoryContext TopTransactionContext
Definition: mcxt.c:48
return result
Definition: formatting.c:1633
bool EndTransactionBlock(void)
Definition: xact.c:3528
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:676
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 3157 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().

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

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

3364 {
3365  SubXactCallbackItem *item;
3366 
3367  item = (SubXactCallbackItem *)
3369  item->callback = callback;
3370  item->arg = arg;
3371  item->next = SubXact_callbacks;
3372  SubXact_callbacks = item;
3373 }
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 3308 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().

3309 {
3310  XactCallbackItem *item;
3311 
3312  item = (XactCallbackItem *)
3314  item->callback = callback;
3315  item->arg = arg;
3316  item->next = Xact_callbacks;
3317  Xact_callbacks = item;
3318 }
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 4126 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().

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

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

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

References CheckTransactionChain().

Referenced by PerformCursorOpen(), and standard_ProcessUtility().

3212 {
3213  CheckTransactionChain(isTopLevel, true, stmtType);
3214 }
static void CheckTransactionChain(bool isTopLevel, bool throwError, const char *stmtType)
Definition: xact.c:3234
void RollbackAndReleaseCurrentSubTransaction ( void  )

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

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

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

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

4874 {
4875  TransactionState s;
4876  Size nxids = 0;
4877  Size i = 0;
4878  Size c = 0;
4879  TransactionId *workspace;
4880  TransactionId *result = (TransactionId *) start_address;
4881 
4882  result[c++] = (TransactionId) XactIsoLevel;
4883  result[c++] = (TransactionId) XactDeferrable;
4884  result[c++] = XactTopTransactionId;
4885  result[c++] = CurrentTransactionState->transactionId;
4886  result[c++] = (TransactionId) currentCommandId;
4887  Assert(maxsize >= c * sizeof(TransactionId));
4888 
4889  /*
4890  * If we're running in a parallel worker and launching a parallel worker
4891  * of our own, we can just pass along the information that was passed to
4892  * us.
4893  */
4894  if (nParallelCurrentXids > 0)
4895  {
4896  result[c++] = nParallelCurrentXids;
4897  Assert(maxsize >= (nParallelCurrentXids + c) * sizeof(TransactionId));
4898  memcpy(&result[c], ParallelCurrentXids,
4900  return;
4901  }
4902 
4903  /*
4904  * OK, we need to generate a sorted list of XIDs that our workers should
4905  * view as current. First, figure out how many there are.
4906  */
4907  for (s = CurrentTransactionState; s != NULL; s = s->parent)
4908  {
4910  nxids = add_size(nxids, 1);
4911  nxids = add_size(nxids, s->nChildXids);
4912  }
4913  Assert((c + 1 + nxids) * sizeof(TransactionId) <= maxsize);
4914 
4915  /* Copy them to our scratch space. */
4916  workspace = palloc(nxids * sizeof(TransactionId));
4917  for (s = CurrentTransactionState; s != NULL; s = s->parent)
4918  {
4920  workspace[i++] = s->transactionId;
4921  memcpy(&workspace[i], s->childXids,
4922  s->nChildXids * sizeof(TransactionId));
4923  i += s->nChildXids;
4924  }
4925  Assert(i == nxids);
4926 
4927  /* Sort them. */
4928  qsort(workspace, nxids, sizeof(TransactionId), xidComparator);
4929 
4930  /* Copy data into output area. */
4931  result[c++] = (TransactionId) nxids;
4932  memcpy(&result[c], workspace, nxids * sizeof(TransactionId));
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
return result
Definition: formatting.c:1633
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:676
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:443
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(), ensure_transaction(), 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 4941 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().

4942 {
4943  TransactionId *tstate = (TransactionId *) tstatespace;
4944 
4946  StartTransaction();
4947 
4948  XactIsoLevel = (int) tstate[0];
4949  XactDeferrable = (bool) tstate[1];
4950  XactTopTransactionId = tstate[2];
4952  currentCommandId = tstate[4];
4953  nParallelCurrentXids = (int) tstate[5];
4954  ParallelCurrentXids = &tstate[6];
4955 
4957 }
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:676
int XactIsoLevel
Definition: xact.c:74
static CommandId currentCommandId
Definition: xact.c:239
void StartTransactionCommand ( void  )

Definition at line 2680 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(), maybe_reread_subscription(), movedb(), ParallelWorkerMain(), perform_work_item(), pg_attribute_noreturn(), process_syncing_tables_for_apply(), ProcessCatchupInterrupt(), ProcessCompletedNotifies(), ProcessIncomingNotify(), ReindexMultipleTables(), RemoveTempRelationsCallback(), ReorderBufferCommit(), SnapBuildExportSnapshot(), start_xact_command(), vacuum(), and vacuum_rel().

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

4361 {
4363 
4364  switch (s->blockState)
4365  {
4366  case TBLOCK_DEFAULT:
4367  case TBLOCK_STARTED:
4368  return 'I'; /* idle --- not in transaction */
4369  case TBLOCK_BEGIN:
4370  case TBLOCK_SUBBEGIN:
4371  case TBLOCK_INPROGRESS:
4373  case TBLOCK_SUBINPROGRESS:
4374  case TBLOCK_END:
4375  case TBLOCK_SUBRELEASE:
4376  case TBLOCK_SUBCOMMIT:
4377  case TBLOCK_PREPARE:
4378  return 'T'; /* in transaction */
4379  case TBLOCK_ABORT:
4380  case TBLOCK_SUBABORT:
4381  case TBLOCK_ABORT_END:
4382  case TBLOCK_SUBABORT_END:
4383  case TBLOCK_ABORT_PENDING:
4385  case TBLOCK_SUBRESTART:
4387  return 'E'; /* in failed transaction */
4388  }
4389 
4390  /* should never get here */
4391  elog(FATAL, "invalid transaction block state: %s",
4393  return 0; /* keep compiler quiet */
4394 }
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:5027
#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(), SnapBuildWaitSnapshot(), 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 3376 of file xact.c.

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

3377 {
3378  SubXactCallbackItem *item;
3379  SubXactCallbackItem *prev;
3380 
3381  prev = NULL;
3382  for (item = SubXact_callbacks; item; prev = item, item = item->next)
3383  {
3384  if (item->callback == callback && item->arg == arg)
3385  {
3386  if (prev)
3387  prev->next = item->next;
3388  else
3389  SubXact_callbacks = item->next;
3390  pfree(item);
3391  break;
3392  }
3393  }
3394 }
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 3321 of file xact.c.

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

3322 {
3323  XactCallbackItem *item;
3324  XactCallbackItem *prev;
3325 
3326  prev = NULL;
3327  for (item = Xact_callbacks; item; prev = item, item = item->next)
3328  {
3329  if (item->callback == callback && item->arg == arg)
3330  {
3331  if (prev)
3332  prev->next = item->next;
3333  else
3334  Xact_callbacks = item->next;
3335  pfree(item);
3336  break;
3337  }
3338  }
3339 }
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 3652 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().

3653 {
3655 
3656  switch (s->blockState)
3657  {
3658  /*
3659  * We are inside a transaction block and we got a ROLLBACK command
3660  * from the user, so tell CommitTransactionCommand to abort and
3661  * exit the transaction block.
3662  */
3663  case TBLOCK_INPROGRESS:
3665  break;
3666 
3667  /*
3668  * We are inside a failed transaction block and we got a ROLLBACK
3669  * command from the user. Abort processing is already done, so
3670  * CommitTransactionCommand just has to cleanup and go back to
3671  * idle state.
3672  */
3673  case TBLOCK_ABORT:
3675  break;
3676 
3677  /*
3678  * We are inside a subtransaction. Mark everything up to top
3679  * level as exitable.
3680  */
3681  case TBLOCK_SUBINPROGRESS:
3682  case TBLOCK_SUBABORT:
3683  while (s->parent != NULL)
3684  {
3685  if (s->blockState == TBLOCK_SUBINPROGRESS)
3687  else if (s->blockState == TBLOCK_SUBABORT)
3689  else
3690  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
3692  s = s->parent;
3693  }
3694  if (s->blockState == TBLOCK_INPROGRESS)
3696  else if (s->blockState == TBLOCK_ABORT)
3698  else
3699  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
3701  break;
3702 
3703  /*
3704  * The user issued ABORT when not inside a transaction. Issue a
3705  * WARNING and go to abort state. The upcoming call to
3706  * CommitTransactionCommand() will then put us back into the
3707  * default state.
3708  */
3709  case TBLOCK_STARTED:
3710  ereport(WARNING,
3711  (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION),
3712  errmsg("there is no transaction in progress")));
3714  break;
3715 
3716  /*
3717  * The user issued an ABORT that somehow ran inside a parallel
3718  * worker. We can't cope with that.
3719  */
3721  ereport(FATAL,
3722  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
3723  errmsg("cannot abort during a parallel operation")));
3724  break;
3725 
3726  /* These cases are invalid. */
3727  case TBLOCK_DEFAULT:
3728  case TBLOCK_BEGIN:
3729  case TBLOCK_SUBBEGIN:
3730  case TBLOCK_END:
3731  case TBLOCK_SUBRELEASE:
3732  case TBLOCK_SUBCOMMIT:
3733  case TBLOCK_ABORT_END:
3734  case TBLOCK_SUBABORT_END:
3735  case TBLOCK_ABORT_PENDING:
3737  case TBLOCK_SUBRESTART:
3739  case TBLOCK_PREPARE:
3740  elog(FATAL, "UserAbortTransactionBlock: unexpected state %s",
3742  break;
3743  }
3744 }
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:5027
#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 3205 of file xact.c.

References CheckTransactionChain().

Referenced by ExecSetVariableStmt(), and standard_ProcessUtility().

3206 {
3207  CheckTransactionChain(isTopLevel, false, stmtType);
3208 }
static void CheckTransactionChain(bool isTopLevel, bool throwError, const char *stmtType)
Definition: xact.c:3234
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:133
unsigned char uint8
Definition: c.h:266
TransactionId xtop
Definition: xact.h:182
#define XLogRecGetOrigin(decoder)
Definition: xlogreader.h:219
#define XLogRecGetData(decoder)
Definition: xlogreader.h:220
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:137
static void xact_desc_abort(StringInfo buf, uint8 info, xl_xact_abort *xlrec)
Definition: xactdesc.c:226
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:216
#define XLOG_XACT_ASSIGNMENT
Definition: xact.h:138
#define XLOG_XACT_ABORT
Definition: xact.h:135
#define XLOG_XACT_OPMASK
Definition: xact.h:143
static void xact_desc_assignment(StringInfo buf, xl_xact_assignment *xlrec)
Definition: xactdesc.c:259
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:136
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:133
#define XLOG_XACT_PREPARE
Definition: xact.h:134
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:137
#define XLOG_XACT_ASSIGNMENT
Definition: xact.h:138
#define NULL
Definition: c.h:229
#define XLOG_XACT_ABORT
Definition: xact.h:135
#define XLOG_XACT_OPMASK
Definition: xact.h:143
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:136
void xact_redo ( XLogReaderState record)

Definition at line 5620 of file xact.c.

References Assert, elog, XLogReaderState::EndRecPtr, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), xl_xact_assignment::nsubxacts, PANIC, ParseAbortRecord(), ParseCommitRecord(), PrepareRedoAdd(), PrepareRedoRemove(), ProcArrayApplyXidAssignment(), XLogReaderState::ReadRecPtr, STANDBY_INITIALIZED, standbyState, 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.

5621 {
5622  uint8 info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
5623 
5624  /* Backup blocks are not used in xact records */
5625  Assert(!XLogRecHasAnyBlockRefs(record));
5626 
5627  if (info == XLOG_XACT_COMMIT)
5628  {
5629  xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
5630  xl_xact_parsed_commit parsed;
5631 
5632  ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
5633  xact_redo_commit(&parsed, XLogRecGetXid(record),
5634  record->EndRecPtr, XLogRecGetOrigin(record));
5635  }
5636  else if (info == XLOG_XACT_COMMIT_PREPARED)
5637  {
5638  xl_xact_commit *xlrec = (xl_xact_commit *) XLogRecGetData(record);
5639  xl_xact_parsed_commit parsed;
5640 
5641  ParseCommitRecord(XLogRecGetInfo(record), xlrec, &parsed);
5642  xact_redo_commit(&parsed, parsed.twophase_xid,
5643  record->EndRecPtr, XLogRecGetOrigin(record));
5644 
5645  /* Delete TwoPhaseState gxact entry and/or 2PC file. */
5646  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
5647  PrepareRedoRemove(parsed.twophase_xid, false);
5648  LWLockRelease(TwoPhaseStateLock);
5649  }
5650  else if (info == XLOG_XACT_ABORT)
5651  {
5652  xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
5653  xl_xact_parsed_abort parsed;
5654 
5655  ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
5656  xact_redo_abort(&parsed, XLogRecGetXid(record));
5657  }
5658  else if (info == XLOG_XACT_ABORT_PREPARED)
5659  {
5660  xl_xact_abort *xlrec = (xl_xact_abort *) XLogRecGetData(record);
5661  xl_xact_parsed_abort parsed;
5662 
5663  ParseAbortRecord(XLogRecGetInfo(record), xlrec, &parsed);
5664  xact_redo_abort(&parsed, parsed.twophase_xid);
5665 
5666  /* Delete TwoPhaseState gxact entry and/or 2PC file. */
5667  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
5668  PrepareRedoRemove(parsed.twophase_xid, false);
5669  LWLockRelease(TwoPhaseStateLock);
5670  }
5671  else if (info == XLOG_XACT_PREPARE)
5672  {
5673  /*
5674  * Store xid and start/end pointers of the WAL record in TwoPhaseState
5675  * gxact entry.
5676  */
5677  LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
5679  record->ReadRecPtr,
5680  record->EndRecPtr);
5681  LWLockRelease(TwoPhaseStateLock);
5682  }
5683  else if (info == XLOG_XACT_ASSIGNMENT)
5684  {
5686 
5689  xlrec->nsubxacts, xlrec->xsub);
5690  }
5691  else
5692  elog(PANIC, "xact_redo: unknown op code %u", info);
5693 }
#define XLOG_XACT_COMMIT
Definition: xact.h:133
void PrepareRedoRemove(TransactionId xid, bool giveWarning)
Definition: twophase.c:2374
#define XLOG_XACT_PREPARE
Definition: xact.h:134
static void xact_redo_commit(xl_xact_parsed_commit *parsed, TransactionId xid, XLogRecPtr lsn, RepOriginId origin_id)
Definition: xact.c:5367
TransactionId twophase_xid
Definition: xact.h:304
unsigned char uint8
Definition: c.h:266
TransactionId xtop
Definition: xact.h:182
TransactionId xsub[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:184
#define PANIC
Definition: elog.h:53
#define XLogRecGetOrigin(decoder)
Definition: xlogreader.h:219
XLogRecPtr EndRecPtr
Definition: xlogreader.h:115
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
#define XLogRecGetData(decoder)
Definition: xlogreader.h:220
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:137
XLogRecPtr ReadRecPtr
Definition: xlogreader.h:114
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:216
void PrepareRedoAdd(char *buf, XLogRecPtr start_lsn, XLogRecPtr end_lsn)
Definition: twophase.c:2312
#define XLogRecGetXid(decoder)
Definition: xlogreader.h:218
#define XLOG_XACT_ASSIGNMENT
Definition: xact.h:138
static void xact_redo_abort(xl_xact_parsed_abort *parsed, TransactionId xid)
Definition: xact.c:5540
TransactionId twophase_xid
Definition: xact.h:321
#define Assert(condition)
Definition: c.h:676
#define XLOG_XACT_ABORT
Definition: xact.h:135
#define XLOG_XACT_OPMASK
Definition: xact.h:143
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
void ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
Definition: xactdesc.c:122
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:222
void ProcArrayApplyXidAssignment(TransactionId topxid, int nsubxids, TransactionId *subxids)
Definition: procarray.c:915
#define elog
Definition: elog.h:219
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:136
HotStandbyState standbyState
Definition: xlog.c:195
int xactGetCommittedChildren ( TransactionId **  ptr)

Definition at line 5108 of file xact.c.

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

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

5109 {
5111 
5112  if (s->nChildXids == 0)
5113  *ptr = NULL;
5114  else
5115  *ptr = s->childXids;
5116 
5117  return s->nChildXids;
5118 }
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 5279 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().

5283 {
5284  xl_xact_abort xlrec;
5285  xl_xact_xinfo xl_xinfo;
5286  xl_xact_subxacts xl_subxacts;
5287  xl_xact_relfilenodes xl_relfilenodes;
5288  xl_xact_twophase xl_twophase;
5289 
5290  uint8 info;
5291 
5292  Assert(CritSectionCount > 0);
5293 
5294  xl_xinfo.xinfo = 0;
5295 
5296  /* decide between a plain and 2pc abort */
5297  if (!TransactionIdIsValid(twophase_xid))
5298  info = XLOG_XACT_ABORT;
5299  else
5300  info = XLOG_XACT_ABORT_PREPARED;
5301 
5302 
5303  /* First figure out and collect all the information needed */
5304 
5305  xlrec.xact_time = abort_time;
5306 
5307  if ((xactflags & XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK))
5308  xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5309 
5310  if (nsubxacts > 0)
5311  {
5312  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5313  xl_subxacts.nsubxacts = nsubxacts;
5314  }
5315 
5316  if (nrels > 0)
5317  {
5318  xl_xinfo.xinfo |= XACT_XINFO_HAS_RELFILENODES;
5319  xl_relfilenodes.nrels = nrels;
5320  }
5321 
5322  if (TransactionIdIsValid(twophase_xid))
5323  {
5324  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5325  xl_twophase.xid = twophase_xid;
5326  }
5327 
5328  if (xl_xinfo.xinfo != 0)
5329  info |= XLOG_XACT_HAS_INFO;
5330 
5331  /* Then include all the collected data into the abort record. */
5332 
5333  XLogBeginInsert();
5334 
5335  XLogRegisterData((char *) (&xlrec), MinSizeOfXactAbort);
5336 
5337  if (xl_xinfo.xinfo != 0)
5338  XLogRegisterData((char *) (&xl_xinfo), sizeof(xl_xinfo));
5339 
5340  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5341  {
5342  XLogRegisterData((char *) (&xl_subxacts),
5344  XLogRegisterData((char *) subxacts,
5345  nsubxacts * sizeof(TransactionId));
5346  }
5347 
5348  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILENODES)
5349  {
5350  XLogRegisterData((char *) (&xl_relfilenodes),
5352  XLogRegisterData((char *) rels,
5353  nrels * sizeof(RelFileNode));
5354  }
5355 
5356  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5357  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5358 
5359  return XLogInsert(RM_XACT_ID, info);
5360 }
uint32 TransactionId
Definition: c.h:397
TransactionId xid
Definition: xact.h:245
unsigned char uint8
Definition: c.h:266
#define MinSizeOfXactAbort
Definition: xact.h:279
#define XLOG_XACT_HAS_INFO
Definition: xact.h:146
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:153
#define MinSizeOfXactRelfilenodes
Definition: xact.h:234
TimestampTz xact_time
Definition: xact.h:270
#define XACT_XINFO_HAS_AE_LOCKS
Definition: xact.h:158
#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK
Definition: xact.h:92
#define MinSizeOfXactSubxacts
Definition: xact.h:227
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:137
volatile uint32 CritSectionCount
Definition: globals.c:37
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:213
int nsubxacts
Definition: xact.h:224
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:156
#define Assert(condition)
Definition: c.h:676
#define XLOG_XACT_ABORT
Definition: xact.h:135
#define XACT_XINFO_HAS_RELFILENODES
Definition: xact.h:154
#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 5132 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().

5138 {
5139  xl_xact_commit xlrec;
5140  xl_xact_xinfo xl_xinfo;
5141  xl_xact_dbinfo xl_dbinfo;
5142  xl_xact_subxacts xl_subxacts;
5143  xl_xact_relfilenodes xl_relfilenodes;
5144  xl_xact_invals xl_invals;
5145  xl_xact_twophase xl_twophase;
5146  xl_xact_origin xl_origin;
5147 
5148  uint8 info;
5149 
5150  Assert(CritSectionCount > 0);
5151 
5152  xl_xinfo.xinfo = 0;
5153 
5154  /* decide between a plain and 2pc commit */
5155  if (!TransactionIdIsValid(twophase_xid))
5156  info = XLOG_XACT_COMMIT;
5157  else
5159 
5160  /* First figure out and collect all the information needed */
5161 
5162  xlrec.xact_time = commit_time;
5163 
5164  if (relcacheInval)
5166  if (forceSyncCommit)
5168  if ((xactflags & XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK))
5169  xl_xinfo.xinfo |= XACT_XINFO_HAS_AE_LOCKS;
5170 
5171  /*
5172  * Check if the caller would like to ask standbys for immediate feedback
5173  * once this commit is applied.
5174  */
5177 
5178  /*
5179  * Relcache invalidations requires information about the current database
5180  * and so does logical decoding.
5181  */
5182  if (nmsgs > 0 || XLogLogicalInfoActive())
5183  {
5184  xl_xinfo.xinfo |= XACT_XINFO_HAS_DBINFO;
5185  xl_dbinfo.dbId = MyDatabaseId;
5186  xl_dbinfo.tsId = MyDatabaseTableSpace;
5187  }
5188 
5189  if (nsubxacts > 0)
5190  {
5191  xl_xinfo.xinfo |= XACT_XINFO_HAS_SUBXACTS;
5192  xl_subxacts.nsubxacts = nsubxacts;
5193  }
5194 
5195  if (nrels > 0)
5196  {
5197  xl_xinfo.xinfo |= XACT_XINFO_HAS_RELFILENODES;
5198  xl_relfilenodes.nrels = nrels;
5199  }
5200 
5201  if (nmsgs > 0)
5202  {
5203  xl_xinfo.xinfo |= XACT_XINFO_HAS_INVALS;
5204  xl_invals.nmsgs = nmsgs;
5205  }
5206 
5207  if (TransactionIdIsValid(twophase_xid))
5208  {
5209  xl_xinfo.xinfo |= XACT_XINFO_HAS_TWOPHASE;
5210  xl_twophase.xid = twophase_xid;
5211  }
5212 
5213  /* dump transaction origin information */
5215  {
5216  xl_xinfo.xinfo |= XACT_XINFO_HAS_ORIGIN;
5217 
5220  }
5221 
5222  if (xl_xinfo.xinfo != 0)
5223  info |= XLOG_XACT_HAS_INFO;
5224 
5225  /* Then include all the collected data into the commit record. */
5226 
5227  XLogBeginInsert();
5228 
5229  XLogRegisterData((char *) (&xlrec), sizeof(xl_xact_commit));
5230 
5231  if (xl_xinfo.xinfo != 0)
5232  XLogRegisterData((char *) (&xl_xinfo.xinfo), sizeof(xl_xinfo.xinfo));
5233 
5234  if (xl_xinfo.xinfo & XACT_XINFO_HAS_DBINFO)
5235  XLogRegisterData((char *) (&xl_dbinfo), sizeof(xl_dbinfo));
5236 
5237  if (xl_xinfo.xinfo & XACT_XINFO_HAS_SUBXACTS)
5238  {
5239  XLogRegisterData((char *) (&xl_subxacts),
5241  XLogRegisterData((char *) subxacts,
5242  nsubxacts * sizeof(TransactionId));
5243  }
5244 
5245  if (xl_xinfo.xinfo & XACT_XINFO_HAS_RELFILENODES)
5246  {
5247  XLogRegisterData((char *) (&xl_relfilenodes),
5249  XLogRegisterData((char *) rels,
5250  nrels * sizeof(RelFileNode));
5251  }
5252 
5253  if (xl_xinfo.xinfo & XACT_XINFO_HAS_INVALS)
5254  {
5255  XLogRegisterData((char *) (&xl_invals), MinSizeOfXactInvals);
5256  XLogRegisterData((char *) msgs,
5257  nmsgs * sizeof(SharedInvalidationMessage));
5258  }
5259 
5260  if (xl_xinfo.xinfo & XACT_XINFO_HAS_TWOPHASE)
5261  XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
5262 
5263  if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
5264  XLogRegisterData((char *) (&xl_origin), sizeof(xl_xact_origin));
5265 
5266  /* we allow filtering by xacts */
5268 
5269  return XLogInsert(RM_XACT_ID, info);
5270 }
#define XACT_COMPLETION_APPLY_FEEDBACK
Definition: xact.h:168
#define XACT_COMPLETION_UPDATE_RELCACHE_FILE
Definition: xact.h:169
#define XLOG_XACT_COMMIT
Definition: xact.h:133
#define XACT_XINFO_HAS_ORIGIN
Definition: xact.h:157
uint32 TransactionId
Definition: c.h:397
TransactionId xid
Definition: xact.h:245
unsigned char uint8
Definition: c.h:266
#define XLOG_XACT_HAS_INFO
Definition: xact.h:146
#define XLOG_INCLUDE_ORIGIN
Definition: xlog.h:191
#define XACT_XINFO_HAS_SUBXACTS
Definition: xact.h:153
#define MinSizeOfXactRelfilenodes
Definition: xact.h:234
Oid tsId
Definition: xact.h:219
Oid MyDatabaseTableSpace
Definition: globals.c:79
static bool forceSyncCommit
Definition: xact.c:262
#define XACT_XINFO_HAS_AE_LOCKS
Definition: xact.h:158
#define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK
Definition: xact.h:92
#define MinSizeOfXactSubxacts
Definition: xact.h:227
#define XLogLogicalInfoActive()
Definition: xlog.h:162
XLogRecPtr replorigin_session_origin_lsn
Definition: origin.c:156
TimestampTz replorigin_session_origin_timestamp
Definition: origin.c:157
TimestampTz xact_time
Definition: xact.h:256
#define MinSizeOfXactInvals
Definition: xact.h:241
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:397
volatile uint32 CritSectionCount
Definition: globals.c:37
#define XACT_XINFO_HAS_DBINFO
Definition: xact.h:152
int synchronous_commit
Definition: xact.c:82
XLogRecPtr origin_lsn
Definition: xact.h:250
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:213
Oid MyDatabaseId
Definition: globals.c:77
int nsubxacts
Definition: xact.h:224
#define XACT_XINFO_HAS_TWOPHASE
Definition: xact.h:156
Oid dbId
Definition: xact.h:218
#define XACT_COMPLETION_FORCE_SYNC_COMMIT
Definition: xact.h:170
#define Assert(condition)
Definition: c.h:676
RepOriginId replorigin_session_origin
Definition: origin.c:155
#define InvalidRepOriginId
Definition: origin.h:34
TimestampTz origin_timestamp
Definition: xact.h:251
#define XACT_XINFO_HAS_INVALS
Definition: xact.h:155
#define XACT_XINFO_HAS_RELFILENODES
Definition: xact.h:154
#define TransactionIdIsValid(xid)
Definition: transam.h:41
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:136
void XLogBeginInsert(void)
Definition: xloginsert.c:120
int nmsgs
Definition: xact.h:238

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