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-2001, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
8
 * Portions Copyright (c) 1994, Regents of the University of California
9
 *
10
 * $Id: transam.h,v 1.38 2001/08/23 23:06:38 tgl Exp $
11 12 13 14 15 16
 *
 *-------------------------------------------------------------------------
 */
#ifndef TRANSAM_H
#define TRANSAM_H

17
#include "storage/bufmgr.h"
18

19

20
/* ----------------
21
 *		Special transaction ID values
22
 *
23 24 25
 * We do not use any transaction IDs less than 512 --- this leaves the first
 * 128 bytes of pg_log available for special purposes such as version number
 * storage.  (Currently, we do not actually use them for anything.)
26
 *
27 28
 * BootstrapTransactionId is the XID for "bootstrap" operations.  It should
 * always be considered valid.
29
 *
30
 * FirstNormalTransactionId is the first "normal" transaction id.
31 32
 * ----------------
 */
33 34 35 36
#define InvalidTransactionId		((TransactionId) 0)
#define DisabledTransactionId		((TransactionId) 1)
#define BootstrapTransactionId		((TransactionId) 512)
#define FirstNormalTransactionId	((TransactionId) 514)
37 38 39

/* ----------------
 *		transaction ID manipulation macros
40 41
 * ----------------
 */
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#define TransactionIdIsValid(xid)		((xid) != InvalidTransactionId)
#define TransactionIdIsNormal(xid)		((xid) >= FirstNormalTransactionId)
#define TransactionIdEquals(id1, id2)			((id1) == (id2))
#define TransactionIdPrecedes(id1, id2)			((id1) < (id2))
#define TransactionIdPrecedesOrEquals(id1, id2)	((id1) <= (id2))
#define TransactionIdFollows(id1, id2)			((id1) > (id2))
#define TransactionIdFollowsOrEquals(id1, id2)	((id1) >= (id2))
#define TransactionIdStore(xid, dest)	(*(dest) = (xid))
#define StoreInvalidTransactionId(dest)	(*(dest) = InvalidTransactionId)
/* advance a transaction ID variable, handling wraparound correctly */
#define TransactionIdAdvance(dest)	\
	do { \
		(dest)++; \
		if ((dest) < FirstNormalTransactionId) \
			(dest) = FirstNormalTransactionId; \
	} while(0)
58 59

/* ----------------
60
 *		transaction status values
61
 *
V
Vadim B. Mikheev 已提交
62 63
 *		someday we will use "11" = 3 = XID_COMMIT_CHILD to mean the
 *		commiting of child xactions.
64 65
 * ----------------
 */
66
#define XID_INPROGRESS		0	/* transaction in progress */
67 68
#define XID_ABORT			1	/* transaction aborted */
#define XID_COMMIT			2	/* transaction commited */
69
#define XID_COMMIT_CHILD	3	/* child xact commited */
70

71
typedef unsigned char XidStatus;	/* (2 bits) */
72 73

/* ----------
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
 *		Object ID (OID) zero is InvalidOid.
 *
 *		OIDs 1-9999 are reserved for manual assignment (see the files
 *		in src/include/catalog/).
 *
 *		OIDS 10000-16383 are reserved for assignment by genbki.sh.
 *
 *		OIDs beginning at 16384 are assigned at runtime from the OID
 *		generator.  (The first few of these will be assigned during initdb,
 *		to objects created after the initial BKI script processing.)
 *
 * 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.
 *
 * NOTE: if the OID generator wraps around, we should skip over OIDs 0-16383
 * and resume with 16384.  This minimizes the odds of OID conflict, by not
 * reassigning OIDs that might have been assigned during initdb.
92 93
 * ----------
 */
94
#define FirstGenBKIObjectId   10000
95 96
#define BootstrapObjectIdData 16384

97
/*
V
Vadim B. Mikheev 已提交
98 99
 * VariableCache is placed in shmem and used by
 * backends to get next available XID & OID.
100 101 102
 */
typedef struct VariableCacheData
{
B
Bruce Momjian 已提交
103 104 105
	TransactionId nextXid;		/* next XID to assign */
	Oid			nextOid;		/* next OID to assign */
	uint32		oidCount;		/* OIDs available before must do XLOG work */
106
} VariableCacheData;
107

108
typedef VariableCacheData *VariableCache;
109

110

111
/* ----------------
112
 *		extern declarations
113 114 115 116 117 118
 * ----------------
 */

/*
 * prototypes for functions in transam/transam.c
 */
119 120 121 122 123
extern void InitializeTransactionLog(void);
extern bool TransactionIdDidCommit(TransactionId transactionId);
extern bool TransactionIdDidAbort(TransactionId transactionId);
extern void TransactionIdCommit(TransactionId transactionId);
extern void TransactionIdAbort(TransactionId transactionId);
124 125

/* in transam/transsup.c */
126
extern void AmiTransactionOverride(bool flag);
127
extern void TransComputeBlockNumber(Relation relation,
B
Bruce Momjian 已提交
128
			  TransactionId transactionId, BlockNumber *blockNumberOutP);
129
extern XidStatus TransBlockNumberGetXidStatus(Relation relation,
130
				BlockNumber blockNumber, TransactionId xid, bool *failP);
131
extern void TransBlockNumberSetXidStatus(Relation relation,
132
		   BlockNumber blockNumber, TransactionId xid, XidStatus xstatus,
133
							 bool *failP);
134 135

/* in transam/varsup.c */
136
extern void GetNewTransactionId(TransactionId *xid);
137
extern void ReadNewTransactionId(TransactionId *xid);
138
extern Oid	GetNewObjectId(void);
139
extern void CheckMaxObjectId(Oid assigned_oid);
140 141

/* ----------------
142
 *		global variable extern declarations
143 144 145 146
 * ----------------
 */

/* in transam.c */
147
extern Relation LogRelation;
148

149
/* in xact.c */
150
extern bool AMI_OVERRIDE;
151 152

/* in varsup.c */
T
Tom Lane 已提交
153 154
extern SPINLOCK OidGenLockId;
extern SPINLOCK XidGenLockId;
155
extern VariableCache ShmemVariableCache;
156

157
#endif	 /* TRAMSAM_H */