transam.h 5.1 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * transam.h
4
 *	  postgres transaction access method support code
5 6
 *
 *
7
 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
8
 * Portions Copyright (c) 1994, Regents of the University of California
9
 *
10
 * $PostgreSQL: pgsql/src/include/access/transam.h,v 1.64 2008/01/01 19:45:56 momjian Exp $
11 12 13 14 15 16
 *
 *-------------------------------------------------------------------------
 */
#ifndef TRANSAM_H
#define TRANSAM_H

17
#include "catalog/pg_magic_oid.h"
18 19
#include "access/xlogdefs.h"

20

21
/* ----------------
22
 *		Special transaction ID values
23
 *
24 25
 * BootstrapTransactionId is the XID for "bootstrap" operations, and
 * FrozenTransactionId is used for very old tuples.  Both should
26
 * always be considered valid.
27
 *
28
 * FirstNormalTransactionId is the first "normal" transaction id.
29
 * Note: if you need to change it, you must change pg_class.h as well.
30 31
 * ----------------
 */
32
#define InvalidTransactionId		((TransactionId) 0)
33 34 35
#define BootstrapTransactionId		((TransactionId) 1)
#define FrozenTransactionId			((TransactionId) 2)
#define FirstNormalTransactionId	((TransactionId) 3)
36
#define MaxTransactionId			((TransactionId) 0xFFFFFFFF)
37 38 39

/* ----------------
 *		transaction ID manipulation macros
40 41
 * ----------------
 */
42 43
#define TransactionIdIsValid(xid)		((xid) != InvalidTransactionId)
#define TransactionIdIsNormal(xid)		((xid) >= FirstNormalTransactionId)
44
#define TransactionIdEquals(id1, id2)	((id1) == (id2))
45
#define TransactionIdStore(xid, dest)	(*(dest) = (xid))
46
#define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId)
47

48 49 50 51 52 53 54
/* advance a transaction ID variable, handling wraparound correctly */
#define TransactionIdAdvance(dest)	\
	do { \
		(dest)++; \
		if ((dest) < FirstNormalTransactionId) \
			(dest) = FirstNormalTransactionId; \
	} while(0)
55

56 57 58 59 60 61
/* back up a transaction ID variable, handling wraparound correctly */
#define TransactionIdRetreat(dest)	\
	do { \
		(dest)--; \
	} while ((dest) < FirstNormalTransactionId)

H
Heikki Linnakangas 已提交
62 63
#define NUM_RECENT_RELFILENODES		100

64
/*
65 66 67 68
 * VariableCache is a data structure in shared memory that is used to track
 * OID and XID assignment state.  For largely historical reasons, there is
 * just one struct with different fields that are protected by different
 * LWLocks.
69 70 71 72
 *
 * Note: xidWrapLimit and limit_datname are not "active" values, but are
 * used just to generate useful messages when xidWarnLimit or xidStopLimit
 * are exceeded.
73 74 75
 */
typedef struct VariableCacheData
{
76 77 78
	/*
	 * These fields are protected by OidGenLock.
	 */
B
Bruce Momjian 已提交
79 80
	Oid			nextOid;		/* next OID to assign */
	uint32		oidCount;		/* OIDs available before must do XLOG work */
81

H
Heikki Linnakangas 已提交
82 83 84 85
	/* cache of recently used relfilenodes, for UseOidForRelFileNode() */
	Oid			recentRelfilenodes[NUM_RECENT_RELFILENODES];
	int			nextRecentRelfilenode;

86 87 88
	/*
	 * These fields are protected by XidGenLock.
	 */
89
	TransactionId nextXid;		/* next XID to assign */
90 91 92

	TransactionId oldestXid;	/* cluster-wide minimum datfrozenxid */
	TransactionId xidVacLimit;	/* start forcing autovacuums here */
B
Bruce Momjian 已提交
93 94 95
	TransactionId xidWarnLimit; /* start complaining here */
	TransactionId xidStopLimit; /* refuse to advance nextXid beyond here */
	TransactionId xidWrapLimit; /* where the world ends */
96
	NameData	limit_datname;	/* database that needs vacuumed first */
97 98 99 100 101 102

	/*
	 * These fields are protected by ProcArrayLock.
	 */
	TransactionId latestCompletedXid;	/* newest XID that has committed or
										 * aborted */
103
} VariableCacheData;
104

105
typedef VariableCacheData *VariableCache;
106

107

108
/* ----------------
109
 *		extern declarations
110 111 112
 * ----------------
 */

113 114 115
/* in transam/varsup.c */
extern VariableCache ShmemVariableCache;

116 117 118
extern int xid_stop_limit;
extern int xid_warn_limit;

119

120 121 122
/*
 * prototypes for functions in transam/transam.c
 */
123 124 125
extern bool TransactionIdDidCommit(TransactionId transactionId);
extern bool TransactionIdDidAbort(TransactionId transactionId);
extern void TransactionIdCommit(TransactionId transactionId);
126
extern void TransactionIdAsyncCommit(TransactionId transactionId, XLogRecPtr lsn);
127
extern void TransactionIdAbort(TransactionId transactionId);
128 129
extern void TransactionIdSubCommit(TransactionId transactionId);
extern void TransactionIdCommitTree(int nxids, TransactionId *xids);
130
extern void TransactionIdAsyncCommitTree(int nxids, TransactionId *xids, XLogRecPtr lsn);
131
extern void TransactionIdAbortTree(int nxids, TransactionId *xids);
132 133 134 135
extern bool TransactionIdPrecedes(TransactionId id1, TransactionId id2);
extern bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2);
extern bool TransactionIdFollows(TransactionId id1, TransactionId id2);
extern bool TransactionIdFollowsOrEquals(TransactionId id1, TransactionId id2);
136
extern TransactionId TransactionIdLatest(TransactionId mainxid,
B
Bruce Momjian 已提交
137
					int nxids, const TransactionId *xids);
138
extern XLogRecPtr TransactionIdGetCommitLSN(TransactionId xid);
139 140

/* in transam/varsup.c */
141
extern TransactionId GetNewTransactionId(bool isSubXact, bool setProcXid);
142
extern TransactionId ReadNewTransactionId(void);
143
extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid,
B
Bruce Momjian 已提交
144
					  Name oldest_datname);
145
extern Oid	GetNewObjectId(void);
H
Heikki Linnakangas 已提交
146
extern bool UseOidForRelFileNode(Oid oid);
147

148
#endif   /* TRAMSAM_H */