xact.h 3.35 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * xact.h
4
 *	  postgres transaction system header
5 6
 *
 *
Bruce Momjian's avatar
Add:  
Bruce Momjian committed
7 8
 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
 * Portions Copyright (c) 1994, Regents of the University of California
9
 *
10
 * $Id: xact.h,v 1.25 2000/06/05 07:28:57 tgl Exp $
11 12 13 14 15 16
 *
 *-------------------------------------------------------------------------
 */
#ifndef XACT_H
#define XACT_H

17
#include "access/transam.h"
Bruce Momjian's avatar
Bruce Momjian committed
18
#include "utils/nabstime.h"
19 20

/* ----------------
21
 *		transaction state structure
22 23
 * ----------------
 */
24 25
typedef struct TransactionStateData
{
26 27 28 29 30 31
	TransactionId transactionIdData;
	CommandId	commandId;
	CommandId	scanCommandId;
	AbsoluteTime startTime;
	int			state;
	int			blockState;
32
} TransactionStateData;
33

34 35 36
/*
 * Xact isolation levels
 */
37 38 39
#define XACT_DIRTY_READ			0		/* not implemented */
#define XACT_READ_COMMITTED		1
#define XACT_REPEATABLE_READ	2		/* not implemented */
40
#define XACT_SERIALIZABLE		3
41

42
extern int	DefaultXactIsoLevel;
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
43 44
extern int	XactIsoLevel;

45
/* ----------------
46
 *		transaction states
47 48
 * ----------------
 */
49 50 51 52 53 54
#define TRANS_DEFAULT			0
#define TRANS_START				1
#define TRANS_INPROGRESS		2
#define TRANS_COMMIT			3
#define TRANS_ABORT				4
#define TRANS_DISABLED			5
55 56

/* ----------------
57
 *		transaction block states
58 59
 * ----------------
 */
60 61 62 63 64 65
#define TBLOCK_DEFAULT			0
#define TBLOCK_BEGIN			1
#define TBLOCK_INPROGRESS		2
#define TBLOCK_END				3
#define TBLOCK_ABORT			4
#define TBLOCK_ENDABORT			5
66 67 68

typedef TransactionStateData *TransactionState;

Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
69 70 71
#define TransactionIdIsValid(xid)		((bool) (xid != NullTransactionId))
#define TransactionIdStore(xid, dest)	\
	(*((TransactionId*)dest) = (TransactionId)xid)
72
#define StoreInvalidTransactionId(dest) \
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
73 74
	(*((TransactionId*)dest) = NullTransactionId)

75 76 77 78 79 80 81 82 83 84 85

/* ----------------------------------------------------------------
 *		TransactionIdEquals
 * ----------------------------------------------------------------
 */
#define TransactionIdEquals(id1, id2) \
( \
	((bool) ((id1) == (id2))) \
)


86
/* ----------------
87
 *		extern definitions
88 89
 * ----------------
 */
90 91
extern int	TransactionFlushEnabled(void);
extern void SetTransactionFlushEnabled(bool state);
92

93 94
extern bool IsAbortedTransactionBlockState(void);
extern void OverrideTransactionSystem(bool flag);
95 96
extern TransactionId GetCurrentTransactionId(void);
extern CommandId GetCurrentCommandId(void);
97
extern CommandId GetScanCommandId(void);
98
extern void SetScanCommandId(CommandId);
99
extern AbsoluteTime GetCurrentTransactionStartTime(void);
100 101 102 103 104 105 106 107 108 109 110 111 112
extern bool TransactionIdIsCurrentTransactionId(TransactionId xid);
extern bool CommandIdIsCurrentCommandId(CommandId cid);
extern bool CommandIdGEScanCommandId(CommandId cid);
extern void CommandCounterIncrement(void);
extern void InitializeTransactionSystem(void);
extern bool CurrentXactInProgress(void);
extern void StartTransactionCommand(void);
extern void CommitTransactionCommand(void);
extern void AbortCurrentTransaction(void);
extern void BeginTransactionBlock(void);
extern void EndTransactionBlock(void);
extern bool IsTransactionBlock(void);
extern void UserAbortTransactionBlock(void);
113
extern void AbortOutOfAnyTransaction(void);
114 115 116 117

extern TransactionId DisabledTransactionId;

/* defined in xid.c */
118 119 120
extern Datum xidin(PG_FUNCTION_ARGS);
extern Datum xidout(PG_FUNCTION_ARGS);
extern Datum xideq(PG_FUNCTION_ARGS);
121
extern void TransactionIdAdd(TransactionId *xid, int value);
122

123
#endif	 /* XACT_H */