1 /*-------------------------------------------------------------------------
4 * postgres transaction access method support code
7 * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/access/transam.h
12 *-------------------------------------------------------------------------
17 #include "access/xlogdefs.h"
21 * Special transaction ID values
23 * BootstrapTransactionId is the XID for "bootstrap" operations, and
24 * FrozenTransactionId is used for very old tuples. Both should
25 * always be considered valid.
27 * FirstNormalTransactionId is the first "normal" transaction id.
28 * Note: if you need to change it, you must change pg_class.h as well.
31 #define InvalidTransactionId ((TransactionId) 0)
32 #define BootstrapTransactionId ((TransactionId) 1)
33 #define FrozenTransactionId ((TransactionId) 2)
34 #define FirstNormalTransactionId ((TransactionId) 3)
35 #define MaxTransactionId ((TransactionId) 0xFFFFFFFF)
38 * transaction ID manipulation macros
41 #define TransactionIdIsValid(xid) ((xid) != InvalidTransactionId)
42 #define TransactionIdIsNormal(xid) ((xid) >= FirstNormalTransactionId)
43 #define TransactionIdEquals(id1, id2) ((id1) == (id2))
44 #define TransactionIdStore(xid, dest) (*(dest) = (xid))
45 #define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId)
47 /* advance a transaction ID variable, handling wraparound correctly */
48 #define TransactionIdAdvance(dest) \
51 if ((dest) < FirstNormalTransactionId) \
52 (dest) = FirstNormalTransactionId; \
55 /* back up a transaction ID variable, handling wraparound correctly */
56 #define TransactionIdRetreat(dest) \
59 } while ((dest) < FirstNormalTransactionId)
61 /* compare two XIDs already known to be normal; this is a macro for speed */
62 #define NormalTransactionIdPrecedes(id1, id2) \
63 (AssertMacro(TransactionIdIsNormal(id1) && TransactionIdIsNormal(id2)), \
64 (int32) ((id1) - (id2)) < 0)
66 /* compare two XIDs already known to be normal; this is a macro for speed */
67 #define NormalTransactionIdFollows(id1, id2) \
68 (AssertMacro(TransactionIdIsNormal(id1) && TransactionIdIsNormal(id2)), \
69 (int32) ((id1) - (id2)) > 0)
72 * Object ID (OID) zero is InvalidOid.
74 * OIDs 1-9999 are reserved for manual assignment (see the files
75 * in src/include/catalog/).
77 * OIDS 10000-16383 are reserved for assignment during initdb
78 * using the OID generator. (We start the generator at 10000.)
80 * OIDs beginning at 16384 are assigned from the OID generator
81 * during normal multiuser operation. (We force the generator up to
82 * 16384 as soon as we are in normal operation.)
84 * The choices of 10000 and 16384 are completely arbitrary, and can be moved
85 * if we run low on OIDs in either category. Changing the macros below
86 * should be sufficient to do this.
88 * NOTE: if the OID generator wraps around, we skip over OIDs 0-16383
89 * and resume with 16384. This minimizes the odds of OID conflict, by not
90 * reassigning OIDs that might have been assigned during initdb.
93 #define FirstBootstrapObjectId 10000
94 #define FirstNormalObjectId 16384
97 * VariableCache is a data structure in shared memory that is used to track
98 * OID and XID assignment state. For largely historical reasons, there is
99 * just one struct with different fields that are protected by different
102 * Note: xidWrapLimit and oldestXidDB are not "active" values, but are
103 * used just to generate useful messages when xidWarnLimit or xidStopLimit
106 typedef struct VariableCacheData
109 * These fields are protected by OidGenLock.
111 Oid nextOid; /* next OID to assign */
112 uint32 oidCount; /* OIDs available before must do XLOG work */
115 * These fields are protected by XidGenLock.
117 TransactionId nextXid; /* next XID to assign */
119 TransactionId oldestXid; /* cluster-wide minimum datfrozenxid */
120 TransactionId xidVacLimit; /* start forcing autovacuums here */
121 TransactionId xidWarnLimit; /* start complaining here */
122 TransactionId xidStopLimit; /* refuse to advance nextXid beyond here */
123 TransactionId xidWrapLimit; /* where the world ends */
124 Oid oldestXidDB; /* database with minimum datfrozenxid */
127 * These fields are protected by ProcArrayLock.
129 TransactionId latestCompletedXid; /* newest XID that has committed or
133 typedef VariableCacheData *VariableCache;
137 * extern declarations
141 /* in transam/xact.c */
142 extern bool TransactionStartedDuringRecovery(void);
144 /* in transam/varsup.c */
145 extern PGDLLIMPORT VariableCache ShmemVariableCache;
148 * prototypes for functions in transam/transam.c
150 extern bool TransactionIdDidCommit(TransactionId transactionId);
151 extern bool TransactionIdDidAbort(TransactionId transactionId);
152 extern bool TransactionIdIsKnownCompleted(TransactionId transactionId);
153 extern void TransactionIdAbort(TransactionId transactionId);
154 extern void TransactionIdCommitTree(TransactionId xid, int nxids, TransactionId *xids);
155 extern void TransactionIdAsyncCommitTree(TransactionId xid, int nxids, TransactionId *xids, XLogRecPtr lsn);
156 extern void TransactionIdAbortTree(TransactionId xid, int nxids, TransactionId *xids);
157 extern bool TransactionIdPrecedes(TransactionId id1, TransactionId id2);
158 extern bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2);
159 extern bool TransactionIdFollows(TransactionId id1, TransactionId id2);
160 extern bool TransactionIdFollowsOrEquals(TransactionId id1, TransactionId id2);
161 extern TransactionId TransactionIdLatest(TransactionId mainxid,
162 int nxids, const TransactionId *xids);
163 extern XLogRecPtr TransactionIdGetCommitLSN(TransactionId xid);
165 /* in transam/varsup.c */
166 extern TransactionId GetNewTransactionId(bool isSubXact);
167 extern TransactionId ReadNewTransactionId(void);
168 extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid,
170 extern bool ForceTransactionIdLimitUpdate(void);
171 extern Oid GetNewObjectId(void);
173 #endif /* TRAMSAM_H */