]> granicus.if.org Git - postgresql/blob - src/include/access/transam.h
Make OIDs optional, per discussions in pghackers. WITH OIDS is still the
[postgresql] / src / include / access / transam.h
1 /*-------------------------------------------------------------------------
2  *
3  * transam.h
4  *        postgres transaction access method support code
5  *
6  *
7  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: transam.h,v 1.37 2001/08/10 18:57:39 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef TRANSAM_H
15 #define TRANSAM_H
16
17 #include "storage/bufmgr.h"
18
19
20 /* ----------------
21  *              Special transaction ID values
22  *
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.)
26  *
27  * AmiTransactionId is the XID for "bootstrap" operations.  It should always
28  * be considered valid.
29  *
30  * FirstTransactionId is the first "normal" transaction id.
31  * ----------------
32  */
33 #define NullTransactionId               ((TransactionId) 0)
34 #define DisabledTransactionId   ((TransactionId) 1)
35 #define AmiTransactionId                ((TransactionId) 512)
36 #define FirstTransactionId              ((TransactionId) 514)
37
38 /* ----------------
39  *              transaction ID manipulation macros
40  * ----------------
41  */
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)
50
51 /* ----------------
52  *              transaction status values
53  *
54  *              someday we will use "11" = 3 = XID_COMMIT_CHILD to mean the
55  *              commiting of child xactions.
56  * ----------------
57  */
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 */
62
63 typedef unsigned char XidStatus;        /* (2 bits) */
64
65 /* ----------
66  *              Object ID (OID) zero is InvalidOid.
67  *
68  *              OIDs 1-9999 are reserved for manual assignment (see the files
69  *              in src/include/catalog/).
70  *
71  *              OIDS 10000-16383 are reserved for assignment by genbki.sh.
72  *
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.)
76  *
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.
80  *
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.
84  * ----------
85  */
86 #define FirstGenBKIObjectId   10000
87 #define BootstrapObjectIdData 16384
88
89 /*
90  * VariableCache is placed in shmem and used by
91  * backends to get next available XID & OID.
92  */
93 typedef struct VariableCacheData
94 {
95         TransactionId nextXid;          /* next XID to assign */
96         Oid                     nextOid;                /* next OID to assign */
97         uint32          oidCount;               /* OIDs available before must do XLOG work */
98 } VariableCacheData;
99
100 typedef VariableCacheData *VariableCache;
101
102
103 /* ----------------
104  *              extern declarations
105  * ----------------
106  */
107
108 /*
109  * prototypes for functions in transam/transam.c
110  */
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);
116
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,
125                                                          bool *failP);
126
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);
132
133 /* ----------------
134  *              global variable extern declarations
135  * ----------------
136  */
137
138 /* in transam.c */
139 extern Relation LogRelation;
140
141 /* in xact.c */
142 extern bool AMI_OVERRIDE;
143
144 /* in varsup.c */
145 extern SPINLOCK OidGenLockId;
146 extern SPINLOCK XidGenLockId;
147 extern VariableCache ShmemVariableCache;
148
149 #endif   /* TRAMSAM_H */