]> granicus.if.org Git - postgresql/blob - src/include/access/transam.h
Replace implementation of pg_log as a relation accessed through 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.39 2001/08/25 18:52:42 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef TRANSAM_H
15 #define TRANSAM_H
16
17 #include "storage/spin.h"
18
19
20 /* ----------------
21  *              Special transaction ID values
22  *
23  * BootstrapTransactionId is the XID for "bootstrap" operations, and
24  * FrozenTransactionId is used for very old tuples.  Both should
25  * always be considered valid.
26  *
27  * FirstNormalTransactionId is the first "normal" transaction id.
28  * ----------------
29  */
30 #define InvalidTransactionId            ((TransactionId) 0)
31 #define BootstrapTransactionId          ((TransactionId) 1)
32 #define FrozenTransactionId                     ((TransactionId) 2)
33 #define FirstNormalTransactionId        ((TransactionId) 3)
34
35 /* ----------------
36  *              transaction ID manipulation macros
37  * ----------------
38  */
39 #define TransactionIdIsValid(xid)               ((xid) != InvalidTransactionId)
40 #define TransactionIdIsNormal(xid)              ((xid) >= FirstNormalTransactionId)
41 #define TransactionIdEquals(id1, id2)                   ((id1) == (id2))
42 #define TransactionIdPrecedes(id1, id2)                 ((id1) < (id2))
43 #define TransactionIdPrecedesOrEquals(id1, id2) ((id1) <= (id2))
44 #define TransactionIdFollows(id1, id2)                  ((id1) > (id2))
45 #define TransactionIdFollowsOrEquals(id1, id2)  ((id1) >= (id2))
46 #define TransactionIdStore(xid, dest)   (*(dest) = (xid))
47 #define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId)
48 /* advance a transaction ID variable, handling wraparound correctly */
49 #define TransactionIdAdvance(dest)      \
50         do { \
51                 (dest)++; \
52                 if ((dest) < FirstNormalTransactionId) \
53                         (dest) = FirstNormalTransactionId; \
54         } while(0)
55
56
57 /* ----------
58  *              Object ID (OID) zero is InvalidOid.
59  *
60  *              OIDs 1-9999 are reserved for manual assignment (see the files
61  *              in src/include/catalog/).
62  *
63  *              OIDS 10000-16383 are reserved for assignment by genbki.sh.
64  *
65  *              OIDs beginning at 16384 are assigned at runtime from the OID
66  *              generator.  (The first few of these will be assigned during initdb,
67  *              to objects created after the initial BKI script processing.)
68  *
69  * The choices of 10000 and 16384 are completely arbitrary, and can be moved
70  * if we run low on OIDs in either category.  Changing the macros below
71  * should be sufficient to do this.
72  *
73  * NOTE: if the OID generator wraps around, we should skip over OIDs 0-16383
74  * and resume with 16384.  This minimizes the odds of OID conflict, by not
75  * reassigning OIDs that might have been assigned during initdb.
76  * ----------
77  */
78 #define FirstGenBKIObjectId   10000
79 #define BootstrapObjectIdData 16384
80
81 /*
82  * VariableCache is placed in shmem and used by
83  * backends to get next available XID & OID.
84  */
85 typedef struct VariableCacheData
86 {
87         TransactionId nextXid;          /* next XID to assign */
88         Oid                     nextOid;                /* next OID to assign */
89         uint32          oidCount;               /* OIDs available before must do XLOG work */
90 } VariableCacheData;
91
92 typedef VariableCacheData *VariableCache;
93
94
95 /* ----------------
96  *              extern declarations
97  * ----------------
98  */
99
100 /*
101  * prototypes for functions in transam/transam.c
102  */
103 extern void AmiTransactionOverride(bool flag);
104 extern bool TransactionIdDidCommit(TransactionId transactionId);
105 extern bool TransactionIdDidAbort(TransactionId transactionId);
106 extern void TransactionIdCommit(TransactionId transactionId);
107 extern void TransactionIdAbort(TransactionId transactionId);
108
109 /* in transam/varsup.c */
110 extern TransactionId GetNewTransactionId(void);
111 extern TransactionId ReadNewTransactionId(void);
112 extern Oid      GetNewObjectId(void);
113 extern void CheckMaxObjectId(Oid assigned_oid);
114
115 /* ----------------
116  *              global variable extern declarations
117  * ----------------
118  */
119
120 /* in xact.c */
121 extern bool AMI_OVERRIDE;
122
123 /* in varsup.c */
124 extern SPINLOCK OidGenLockId;
125 extern SPINLOCK XidGenLockId;
126 extern VariableCache ShmemVariableCache;
127
128 #endif   /* TRAMSAM_H */