transam.h 4.9 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)

62
/*
63 64 65 66
 * 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.
67 68 69 70
 *
 * Note: xidWrapLimit and limit_datname are not "active" values, but are
 * used just to generate useful messages when xidWarnLimit or xidStopLimit
 * are exceeded.
71 72 73
 */
typedef struct VariableCacheData
{
74 75 76
	/*
	 * These fields are protected by OidGenLock.
	 */
B
Bruce Momjian 已提交
77 78
	Oid			nextOid;		/* next OID to assign */
	uint32		oidCount;		/* OIDs available before must do XLOG work */
79 80 81 82

	/*
	 * These fields are protected by XidGenLock.
	 */
83
	TransactionId nextXid;		/* next XID to assign */
84 85 86

	TransactionId oldestXid;	/* cluster-wide minimum datfrozenxid */
	TransactionId xidVacLimit;	/* start forcing autovacuums here */
B
Bruce Momjian 已提交
87 88 89
	TransactionId xidWarnLimit; /* start complaining here */
	TransactionId xidStopLimit; /* refuse to advance nextXid beyond here */
	TransactionId xidWrapLimit; /* where the world ends */
90
	NameData	limit_datname;	/* database that needs vacuumed first */
91 92 93 94 95 96

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

99
typedef VariableCacheData *VariableCache;
100

101

102
/* ----------------
103
 *		extern declarations
104 105 106
 * ----------------
 */

107 108 109
/* in transam/varsup.c */
extern VariableCache ShmemVariableCache;

110 111 112
extern int xid_stop_limit;
extern int xid_warn_limit;

113

114 115 116
/*
 * prototypes for functions in transam/transam.c
 */
117 118 119
extern bool TransactionIdDidCommit(TransactionId transactionId);
extern bool TransactionIdDidAbort(TransactionId transactionId);
extern void TransactionIdCommit(TransactionId transactionId);
120
extern void TransactionIdAsyncCommit(TransactionId transactionId, XLogRecPtr lsn);
121
extern void TransactionIdAbort(TransactionId transactionId);
122 123
extern void TransactionIdSubCommit(TransactionId transactionId);
extern void TransactionIdCommitTree(int nxids, TransactionId *xids);
124
extern void TransactionIdAsyncCommitTree(int nxids, TransactionId *xids, XLogRecPtr lsn);
125
extern void TransactionIdAbortTree(int nxids, TransactionId *xids);
126 127 128 129
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);
130
extern TransactionId TransactionIdLatest(TransactionId mainxid,
B
Bruce Momjian 已提交
131
					int nxids, const TransactionId *xids);
132
extern XLogRecPtr TransactionIdGetCommitLSN(TransactionId xid);
133 134

/* in transam/varsup.c */
135
extern TransactionId GetNewTransactionId(bool isSubXact, bool setProcXid);
136
extern TransactionId ReadNewTransactionId(void);
137
extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid,
B
Bruce Momjian 已提交
138
					  Name oldest_datname);
139
extern Oid	GetNewObjectId(void);
140

141
#endif   /* TRAMSAM_H */