transam.h 4.6 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * transam.h
4
 *	  postgres transaction access method support code
5 6
 *
 *
P
 
PostgreSQL Daemon 已提交
7
 * Portions Copyright (c) 1996-2005, 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.55 2005/08/12 01:36:03 tgl Exp $
11 12 13 14 15 16
 *
 *-------------------------------------------------------------------------
 */
#ifndef TRANSAM_H
#define TRANSAM_H

17

18
/* ----------------
19
 *		Special transaction ID values
20
 *
21 22
 * BootstrapTransactionId is the XID for "bootstrap" operations, and
 * FrozenTransactionId is used for very old tuples.  Both should
23
 * always be considered valid.
24
 *
25
 * FirstNormalTransactionId is the first "normal" transaction id.
26 27
 * ----------------
 */
28
#define InvalidTransactionId		((TransactionId) 0)
29 30 31
#define BootstrapTransactionId		((TransactionId) 1)
#define FrozenTransactionId			((TransactionId) 2)
#define FirstNormalTransactionId	((TransactionId) 3)
32
#define MaxTransactionId			((TransactionId) 0xFFFFFFFF)
33 34 35

/* ----------------
 *		transaction ID manipulation macros
36 37
 * ----------------
 */
38 39
#define TransactionIdIsValid(xid)		((xid) != InvalidTransactionId)
#define TransactionIdIsNormal(xid)		((xid) >= FirstNormalTransactionId)
40
#define TransactionIdEquals(id1, id2)	((id1) == (id2))
41
#define TransactionIdStore(xid, dest)	(*(dest) = (xid))
42
#define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId)
43 44 45 46 47 48 49
/* advance a transaction ID variable, handling wraparound correctly */
#define TransactionIdAdvance(dest)	\
	do { \
		(dest)++; \
		if ((dest) < FirstNormalTransactionId) \
			(dest) = FirstNormalTransactionId; \
	} while(0)
50 51 52


/* ----------
53 54 55 56 57
 *		Object ID (OID) zero is InvalidOid.
 *
 *		OIDs 1-9999 are reserved for manual assignment (see the files
 *		in src/include/catalog/).
 *
58 59
 *		OIDS 10000-16383 are reserved for assignment during initdb
 *		using the OID generator.  (We start the generator at 10000.)
60
 *
61 62 63
 *		OIDs beginning at 16384 are assigned from the OID generator
 *		during normal multiuser operation.  (We force the generator up to
 *		16384 as soon as we are in normal operation.)
64 65 66 67 68
 *
 * The choices of 10000 and 16384 are completely arbitrary, and can be moved
 * if we run low on OIDs in either category.  Changing the macros below
 * should be sufficient to do this.
 *
69
 * NOTE: if the OID generator wraps around, we skip over OIDs 0-16383
70 71
 * and resume with 16384.  This minimizes the odds of OID conflict, by not
 * reassigning OIDs that might have been assigned during initdb.
72 73
 * ----------
 */
74 75
#define FirstBootstrapObjectId	10000
#define FirstNormalObjectId		16384
76

77
/*
V
Vadim B. Mikheev 已提交
78
 * VariableCache is placed in shmem and used by
79 80 81 82 83
 * backends to get next available OID & XID.
 *
 * Note: xidWrapLimit and limit_datname are not "active" values, but are
 * used just to generate useful messages when xidWarnLimit or xidStopLimit
 * are exceeded.
84 85 86
 */
typedef struct VariableCacheData
{
B
Bruce Momjian 已提交
87 88
	Oid			nextOid;		/* next OID to assign */
	uint32		oidCount;		/* OIDs available before must do XLOG work */
89 90 91 92 93
	TransactionId nextXid;		/* next XID to assign */
	TransactionId xidWarnLimit;	/* start complaining here */
	TransactionId xidStopLimit;	/* refuse to advance nextXid beyond here */
	TransactionId xidWrapLimit;	/* where the world ends */
	NameData	limit_datname;	/* database that needs vacuumed first */
94
} VariableCacheData;
95

96
typedef VariableCacheData *VariableCache;
97

98

99
/* ----------------
100
 *		extern declarations
101 102 103
 * ----------------
 */

104 105 106 107
/* in transam/varsup.c */
extern VariableCache ShmemVariableCache;


108 109 110
/*
 * prototypes for functions in transam/transam.c
 */
111 112 113 114
extern bool TransactionIdDidCommit(TransactionId transactionId);
extern bool TransactionIdDidAbort(TransactionId transactionId);
extern void TransactionIdCommit(TransactionId transactionId);
extern void TransactionIdAbort(TransactionId transactionId);
115 116 117
extern void TransactionIdSubCommit(TransactionId transactionId);
extern void TransactionIdCommitTree(int nxids, TransactionId *xids);
extern void TransactionIdAbortTree(int nxids, TransactionId *xids);
118 119 120 121
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);
122 123

/* in transam/varsup.c */
124
extern TransactionId GetNewTransactionId(bool isSubXact);
125
extern TransactionId ReadNewTransactionId(void);
126 127
extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid,
								  Name oldest_datname);
128
extern Oid	GetNewObjectId(void);
129

130
#endif   /* TRAMSAM_H */