1 /*-------------------------------------------------------------------------
4 * postgres transaction access method support code
7 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: transam.h,v 1.37 2001/08/10 18:57:39 tgl Exp $
12 *-------------------------------------------------------------------------
17 #include "storage/bufmgr.h"
21 * Special transaction ID values
23 * We do not use any transaction IDs less than 512 --- this leaves the first
24 * 128 bytes of pg_log available for special purposes such as version number
25 * storage. (Currently, we do not actually use them for anything.)
27 * AmiTransactionId is the XID for "bootstrap" operations. It should always
28 * be considered valid.
30 * FirstTransactionId is the first "normal" transaction id.
33 #define NullTransactionId ((TransactionId) 0)
34 #define DisabledTransactionId ((TransactionId) 1)
35 #define AmiTransactionId ((TransactionId) 512)
36 #define FirstTransactionId ((TransactionId) 514)
39 * transaction ID manipulation macros
42 #define TransactionIdIsValid(xid) ((bool) ((xid) != NullTransactionId))
43 #define TransactionIdIsSpecial(xid) ((bool) ((xid) < FirstTransactionId))
44 #define TransactionIdEquals(id1, id2) ((bool) ((id1) == (id2)))
45 #define TransactionIdPrecedes(id1, id2) ((bool) ((id1) < (id2)))
46 #define TransactionIdStore(xid, dest) \
47 (*((TransactionId*) (dest)) = (TransactionId) (xid))
48 #define StoreInvalidTransactionId(dest) \
49 (*((TransactionId*) (dest)) = NullTransactionId)
52 * transaction status values
54 * someday we will use "11" = 3 = XID_COMMIT_CHILD to mean the
55 * commiting of child xactions.
58 #define XID_INPROGRESS 0 /* transaction in progress */
59 #define XID_ABORT 1 /* transaction aborted */
60 #define XID_COMMIT 2 /* transaction commited */
61 #define XID_COMMIT_CHILD 3 /* child xact commited */
63 typedef unsigned char XidStatus; /* (2 bits) */
66 * Object ID (OID) zero is InvalidOid.
68 * OIDs 1-9999 are reserved for manual assignment (see the files
69 * in src/include/catalog/).
71 * OIDS 10000-16383 are reserved for assignment by genbki.sh.
73 * OIDs beginning at 16384 are assigned at runtime from the OID
74 * generator. (The first few of these will be assigned during initdb,
75 * to objects created after the initial BKI script processing.)
77 * The choices of 10000 and 16384 are completely arbitrary, and can be moved
78 * if we run low on OIDs in either category. Changing the macros below
79 * should be sufficient to do this.
81 * NOTE: if the OID generator wraps around, we should skip over OIDs 0-16383
82 * and resume with 16384. This minimizes the odds of OID conflict, by not
83 * reassigning OIDs that might have been assigned during initdb.
86 #define FirstGenBKIObjectId 10000
87 #define BootstrapObjectIdData 16384
90 * VariableCache is placed in shmem and used by
91 * backends to get next available XID & OID.
93 typedef struct VariableCacheData
95 TransactionId nextXid; /* next XID to assign */
96 Oid nextOid; /* next OID to assign */
97 uint32 oidCount; /* OIDs available before must do XLOG work */
100 typedef VariableCacheData *VariableCache;
104 * extern declarations
109 * prototypes for functions in transam/transam.c
111 extern void InitializeTransactionLog(void);
112 extern bool TransactionIdDidCommit(TransactionId transactionId);
113 extern bool TransactionIdDidAbort(TransactionId transactionId);
114 extern void TransactionIdCommit(TransactionId transactionId);
115 extern void TransactionIdAbort(TransactionId transactionId);
117 /* in transam/transsup.c */
118 extern void AmiTransactionOverride(bool flag);
119 extern void TransComputeBlockNumber(Relation relation,
120 TransactionId transactionId, BlockNumber *blockNumberOutP);
121 extern XidStatus TransBlockNumberGetXidStatus(Relation relation,
122 BlockNumber blockNumber, TransactionId xid, bool *failP);
123 extern void TransBlockNumberSetXidStatus(Relation relation,
124 BlockNumber blockNumber, TransactionId xid, XidStatus xstatus,
127 /* in transam/varsup.c */
128 extern void GetNewTransactionId(TransactionId *xid);
129 extern void ReadNewTransactionId(TransactionId *xid);
130 extern Oid GetNewObjectId(void);
131 extern void CheckMaxObjectId(Oid assigned_oid);
134 * global variable extern declarations
139 extern Relation LogRelation;
142 extern bool AMI_OVERRIDE;
145 extern SPINLOCK OidGenLockId;
146 extern SPINLOCK XidGenLockId;
147 extern VariableCache ShmemVariableCache;
149 #endif /* TRAMSAM_H */