1996-08-27 23:50:29 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* xact.h
|
2000-07-28 03:04:40 +02:00
|
|
|
* postgres transaction system definitions
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*
|
2003-08-04 04:40:20 +02:00
|
|
|
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
2004-07-01 02:52:04 +02:00
|
|
|
* $PostgreSQL: pgsql/src/include/access/xact.h,v 1.64 2004/07/01 00:51:38 tgl Exp $
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef XACT_H
|
|
|
|
#define XACT_H
|
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "access/transam.h"
|
2000-11-21 22:16:06 +01:00
|
|
|
#include "access/xlog.h"
|
1999-07-16 19:07:40 +02:00
|
|
|
#include "utils/nabstime.h"
|
2001-09-28 10:09:14 +02:00
|
|
|
#include "utils/timestamp.h"
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2000-07-28 03:04:40 +02:00
|
|
|
/*
|
|
|
|
* Xact isolation levels
|
|
|
|
*/
|
2003-11-06 23:08:15 +01:00
|
|
|
#define XACT_READ_UNCOMMITTED 0
|
2000-07-28 03:04:40 +02:00
|
|
|
#define XACT_READ_COMMITTED 1
|
2003-11-06 23:08:15 +01:00
|
|
|
#define XACT_REPEATABLE_READ 2
|
2000-07-28 03:04:40 +02:00
|
|
|
#define XACT_SERIALIZABLE 3
|
|
|
|
|
|
|
|
extern int DefaultXactIsoLevel;
|
|
|
|
extern int XactIsoLevel;
|
2003-04-26 22:23:00 +02:00
|
|
|
|
2003-11-06 23:08:15 +01:00
|
|
|
/*
|
|
|
|
* We only implement two distinct levels, so this is a convenience to
|
|
|
|
* check which level we're really using internally.
|
|
|
|
*/
|
|
|
|
#define IsXactIsoLevelSerializable ((XactIsoLevel == XACT_REPEATABLE_READ || XactIsoLevel == XACT_SERIALIZABLE))
|
|
|
|
|
2003-04-26 22:23:00 +02:00
|
|
|
/* Xact read-only state */
|
2003-08-04 02:43:34 +02:00
|
|
|
extern bool DefaultXactReadOnly;
|
|
|
|
extern bool XactReadOnly;
|
2003-01-10 23:03:30 +01:00
|
|
|
|
2003-04-26 22:23:00 +02:00
|
|
|
/*
|
|
|
|
* transaction states - transaction state from server perspective
|
|
|
|
*/
|
|
|
|
typedef enum TransState
|
|
|
|
{
|
|
|
|
TRANS_DEFAULT,
|
|
|
|
TRANS_START,
|
|
|
|
TRANS_INPROGRESS,
|
|
|
|
TRANS_COMMIT,
|
|
|
|
TRANS_ABORT
|
2003-08-08 23:42:59 +02:00
|
|
|
} TransState;
|
2003-04-26 22:23:00 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* transaction block states - transaction state of client queries
|
|
|
|
*/
|
|
|
|
typedef enum TBlockState
|
|
|
|
{
|
|
|
|
TBLOCK_DEFAULT,
|
2004-04-05 05:11:39 +02:00
|
|
|
TBLOCK_STARTED,
|
2003-04-26 22:23:00 +02:00
|
|
|
TBLOCK_BEGIN,
|
|
|
|
TBLOCK_INPROGRESS,
|
|
|
|
TBLOCK_END,
|
|
|
|
TBLOCK_ABORT,
|
2004-07-01 02:52:04 +02:00
|
|
|
TBLOCK_ENDABORT,
|
|
|
|
|
|
|
|
TBLOCK_SUBBEGIN,
|
|
|
|
TBLOCK_SUBBEGINABORT,
|
|
|
|
TBLOCK_SUBINPROGRESS,
|
|
|
|
TBLOCK_SUBEND,
|
|
|
|
TBLOCK_SUBABORT,
|
|
|
|
TBLOCK_SUBENDABORT_OK,
|
|
|
|
TBLOCK_SUBENDABORT_ERROR
|
2003-08-08 23:42:59 +02:00
|
|
|
} TBlockState;
|
2000-07-28 03:04:40 +02:00
|
|
|
|
2003-09-29 01:26:20 +02:00
|
|
|
/*
|
|
|
|
* end-of-transaction cleanup callbacks for dynamically loaded modules
|
|
|
|
*/
|
|
|
|
typedef void (*EOXactCallback) (bool isCommit, void *arg);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* transaction state structure
|
1996-08-27 23:50:29 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct TransactionStateData
|
|
|
|
{
|
2004-07-01 02:52:04 +02:00
|
|
|
TransactionId transactionIdData; /* my XID */
|
|
|
|
CommandId commandId; /* current CID */
|
|
|
|
TransState state; /* low-level state */
|
|
|
|
TBlockState blockState; /* high-level state */
|
|
|
|
int nestingLevel; /* nest depth */
|
|
|
|
MemoryContext curTransactionContext; /* my xact-lifetime context */
|
|
|
|
List *childXids; /* subcommitted child XIDs */
|
|
|
|
AclId currentUser; /* subxact start current_user */
|
|
|
|
struct TransactionStateData *parent; /* back link to parent */
|
1997-09-08 23:56:23 +02:00
|
|
|
} TransactionStateData;
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2000-07-28 03:04:40 +02:00
|
|
|
typedef TransactionStateData *TransactionState;
|
1998-12-15 13:47:01 +01:00
|
|
|
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2003-04-26 22:23:00 +02:00
|
|
|
/* ----------------
|
|
|
|
* transaction-related XLOG entries
|
|
|
|
* ----------------
|
1996-08-27 23:50:29 +02:00
|
|
|
*/
|
|
|
|
|
2000-10-20 13:01:21 +02:00
|
|
|
/*
|
|
|
|
* XLOG allows to store some information in high 4 bits of log
|
|
|
|
* record xl_info field
|
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
#define XLOG_XACT_COMMIT 0x00
|
|
|
|
#define XLOG_XACT_ABORT 0x20
|
2000-10-20 13:01:21 +02:00
|
|
|
|
|
|
|
typedef struct xl_xact_commit
|
|
|
|
{
|
|
|
|
time_t xtime;
|
2004-07-01 02:52:04 +02:00
|
|
|
int nrels; /* number of RelFileNodes */
|
|
|
|
int nsubxacts; /* number of subtransaction XIDs */
|
2004-02-11 23:55:26 +01:00
|
|
|
/* Array of RelFileNode(s) to drop at commit */
|
|
|
|
RelFileNode xnodes[1]; /* VARIABLE LENGTH ARRAY */
|
2004-07-01 02:52:04 +02:00
|
|
|
/* ARRAY OF COMMITTED SUBTRANSACTION XIDs FOLLOWS */
|
2000-10-20 13:01:21 +02:00
|
|
|
} xl_xact_commit;
|
|
|
|
|
2004-02-11 23:55:26 +01:00
|
|
|
#define MinSizeOfXactCommit offsetof(xl_xact_commit, xnodes)
|
2000-10-20 13:01:21 +02:00
|
|
|
|
|
|
|
typedef struct xl_xact_abort
|
|
|
|
{
|
|
|
|
time_t xtime;
|
2004-07-01 02:52:04 +02:00
|
|
|
int nrels; /* number of RelFileNodes */
|
|
|
|
int nsubxacts; /* number of subtransaction XIDs */
|
2004-02-11 23:55:26 +01:00
|
|
|
/* Array of RelFileNode(s) to drop at abort */
|
|
|
|
RelFileNode xnodes[1]; /* VARIABLE LENGTH ARRAY */
|
2004-07-01 02:52:04 +02:00
|
|
|
/* ARRAY OF ABORTED SUBTRANSACTION XIDs FOLLOWS */
|
2000-10-20 13:01:21 +02:00
|
|
|
} xl_xact_abort;
|
|
|
|
|
2004-02-11 23:55:26 +01:00
|
|
|
#define MinSizeOfXactAbort offsetof(xl_xact_abort, xnodes)
|
|
|
|
|
2000-10-20 13:01:21 +02:00
|
|
|
|
1996-08-27 23:50:29 +02:00
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* extern definitions
|
1996-08-27 23:50:29 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
2002-04-01 05:34:27 +02:00
|
|
|
extern bool IsTransactionState(void);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern bool IsAbortedTransactionBlockState(void);
|
2004-07-01 02:52:04 +02:00
|
|
|
extern TransactionId GetTopTransactionId(void);
|
1996-08-27 23:50:29 +02:00
|
|
|
extern TransactionId GetCurrentTransactionId(void);
|
|
|
|
extern CommandId GetCurrentCommandId(void);
|
|
|
|
extern AbsoluteTime GetCurrentTransactionStartTime(void);
|
2001-09-28 10:09:14 +02:00
|
|
|
extern AbsoluteTime GetCurrentTransactionStartTimeUsec(int *usec);
|
2004-07-01 02:52:04 +02:00
|
|
|
extern int GetCurrentTransactionNestLevel(void);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern bool TransactionIdIsCurrentTransactionId(TransactionId xid);
|
|
|
|
extern void CommandCounterIncrement(void);
|
2003-05-14 05:26:03 +02:00
|
|
|
extern void StartTransactionCommand(void);
|
|
|
|
extern void CommitTransactionCommand(void);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void AbortCurrentTransaction(void);
|
|
|
|
extern void BeginTransactionBlock(void);
|
|
|
|
extern void EndTransactionBlock(void);
|
2004-07-01 02:52:04 +02:00
|
|
|
extern bool IsSubTransaction(void);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern bool IsTransactionBlock(void);
|
2003-10-16 18:50:41 +02:00
|
|
|
extern bool IsTransactionOrTransactionBlock(void);
|
2003-04-26 22:23:00 +02:00
|
|
|
extern char TransactionBlockStatusCode(void);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void UserAbortTransactionBlock(void);
|
1998-10-06 04:40:09 +02:00
|
|
|
extern void AbortOutOfAnyTransaction(void);
|
2002-10-22 00:06:20 +02:00
|
|
|
extern void PreventTransactionChain(void *stmtNode, const char *stmtType);
|
2002-11-18 02:17:39 +01:00
|
|
|
extern void RequireTransactionChain(void *stmtNode, const char *stmtType);
|
2004-05-23 01:14:38 +02:00
|
|
|
extern bool IsInTransactionChain(void *stmtNode);
|
2003-09-29 01:26:20 +02:00
|
|
|
extern void RegisterEOXactCallback(EOXactCallback callback, void *arg);
|
|
|
|
extern void UnregisterEOXactCallback(EOXactCallback callback, void *arg);
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2000-10-28 18:21:00 +02:00
|
|
|
extern void RecordTransactionCommit(void);
|
|
|
|
|
2004-07-01 02:52:04 +02:00
|
|
|
extern int xactGetCommittedChildren(TransactionId **ptr, bool metoo);
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
extern void XactPushRollback(void (*func) (void *), void *data);
|
2000-10-20 13:01:21 +02:00
|
|
|
extern void XactPopRollback(void);
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
extern void xact_redo(XLogRecPtr lsn, XLogRecord *record);
|
|
|
|
extern void xact_undo(XLogRecPtr lsn, XLogRecord *record);
|
|
|
|
extern void xact_desc(char *buf, uint8 xl_info, char *rec);
|
2000-11-21 22:16:06 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* XACT_H */
|