Header And Logo

PostgreSQL
| The world's most advanced open source database.

transam.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * transam.h
00004  *    postgres transaction access method support code
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/access/transam.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef TRANSAM_H
00015 #define TRANSAM_H
00016 
00017 #include "access/xlogdefs.h"
00018 
00019 
00020 /* ----------------
00021  *      Special transaction ID values
00022  *
00023  * BootstrapTransactionId is the XID for "bootstrap" operations, and
00024  * FrozenTransactionId is used for very old tuples.  Both should
00025  * always be considered valid.
00026  *
00027  * FirstNormalTransactionId is the first "normal" transaction id.
00028  * Note: if you need to change it, you must change pg_class.h as well.
00029  * ----------------
00030  */
00031 #define InvalidTransactionId        ((TransactionId) 0)
00032 #define BootstrapTransactionId      ((TransactionId) 1)
00033 #define FrozenTransactionId         ((TransactionId) 2)
00034 #define FirstNormalTransactionId    ((TransactionId) 3)
00035 #define MaxTransactionId            ((TransactionId) 0xFFFFFFFF)
00036 
00037 /* ----------------
00038  *      transaction ID manipulation macros
00039  * ----------------
00040  */
00041 #define TransactionIdIsValid(xid)       ((xid) != InvalidTransactionId)
00042 #define TransactionIdIsNormal(xid)      ((xid) >= FirstNormalTransactionId)
00043 #define TransactionIdEquals(id1, id2)   ((id1) == (id2))
00044 #define TransactionIdStore(xid, dest)   (*(dest) = (xid))
00045 #define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId)
00046 
00047 /* advance a transaction ID variable, handling wraparound correctly */
00048 #define TransactionIdAdvance(dest)  \
00049     do { \
00050         (dest)++; \
00051         if ((dest) < FirstNormalTransactionId) \
00052             (dest) = FirstNormalTransactionId; \
00053     } while(0)
00054 
00055 /* back up a transaction ID variable, handling wraparound correctly */
00056 #define TransactionIdRetreat(dest)  \
00057     do { \
00058         (dest)--; \
00059     } while ((dest) < FirstNormalTransactionId)
00060 
00061 
00062 /* ----------
00063  *      Object ID (OID) zero is InvalidOid.
00064  *
00065  *      OIDs 1-9999 are reserved for manual assignment (see the files
00066  *      in src/include/catalog/).
00067  *
00068  *      OIDS 10000-16383 are reserved for assignment during initdb
00069  *      using the OID generator.  (We start the generator at 10000.)
00070  *
00071  *      OIDs beginning at 16384 are assigned from the OID generator
00072  *      during normal multiuser operation.  (We force the generator up to
00073  *      16384 as soon as we are in normal operation.)
00074  *
00075  * The choices of 10000 and 16384 are completely arbitrary, and can be moved
00076  * if we run low on OIDs in either category.  Changing the macros below
00077  * should be sufficient to do this.
00078  *
00079  * NOTE: if the OID generator wraps around, we skip over OIDs 0-16383
00080  * and resume with 16384.  This minimizes the odds of OID conflict, by not
00081  * reassigning OIDs that might have been assigned during initdb.
00082  * ----------
00083  */
00084 #define FirstBootstrapObjectId  10000
00085 #define FirstNormalObjectId     16384
00086 
00087 /*
00088  * VariableCache is a data structure in shared memory that is used to track
00089  * OID and XID assignment state.  For largely historical reasons, there is
00090  * just one struct with different fields that are protected by different
00091  * LWLocks.
00092  *
00093  * Note: xidWrapLimit and oldestXidDB are not "active" values, but are
00094  * used just to generate useful messages when xidWarnLimit or xidStopLimit
00095  * are exceeded.
00096  */
00097 typedef struct VariableCacheData
00098 {
00099     /*
00100      * These fields are protected by OidGenLock.
00101      */
00102     Oid         nextOid;        /* next OID to assign */
00103     uint32      oidCount;       /* OIDs available before must do XLOG work */
00104 
00105     /*
00106      * These fields are protected by XidGenLock.
00107      */
00108     TransactionId nextXid;      /* next XID to assign */
00109 
00110     TransactionId oldestXid;    /* cluster-wide minimum datfrozenxid */
00111     TransactionId xidVacLimit;  /* start forcing autovacuums here */
00112     TransactionId xidWarnLimit; /* start complaining here */
00113     TransactionId xidStopLimit; /* refuse to advance nextXid beyond here */
00114     TransactionId xidWrapLimit; /* where the world ends */
00115     Oid         oldestXidDB;    /* database with minimum datfrozenxid */
00116 
00117     /*
00118      * These fields are protected by ProcArrayLock.
00119      */
00120     TransactionId latestCompletedXid;   /* newest XID that has committed or
00121                                          * aborted */
00122 } VariableCacheData;
00123 
00124 typedef VariableCacheData *VariableCache;
00125 
00126 
00127 /* ----------------
00128  *      extern declarations
00129  * ----------------
00130  */
00131 
00132 /* in transam/xact.c */
00133 extern bool TransactionStartedDuringRecovery(void);
00134 
00135 /* in transam/varsup.c */
00136 extern PGDLLIMPORT VariableCache ShmemVariableCache;
00137 
00138 /* in transam/transam.c */
00139 extern const XLogRecPtr InvalidXLogRecPtr;
00140 
00141 
00142 /*
00143  * prototypes for functions in transam/transam.c
00144  */
00145 extern bool TransactionIdDidCommit(TransactionId transactionId);
00146 extern bool TransactionIdDidAbort(TransactionId transactionId);
00147 extern bool TransactionIdIsKnownCompleted(TransactionId transactionId);
00148 extern void TransactionIdAbort(TransactionId transactionId);
00149 extern void TransactionIdCommitTree(TransactionId xid, int nxids, TransactionId *xids);
00150 extern void TransactionIdAsyncCommitTree(TransactionId xid, int nxids, TransactionId *xids, XLogRecPtr lsn);
00151 extern void TransactionIdAbortTree(TransactionId xid, int nxids, TransactionId *xids);
00152 extern bool TransactionIdPrecedes(TransactionId id1, TransactionId id2);
00153 extern bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2);
00154 extern bool TransactionIdFollows(TransactionId id1, TransactionId id2);
00155 extern bool TransactionIdFollowsOrEquals(TransactionId id1, TransactionId id2);
00156 extern TransactionId TransactionIdLatest(TransactionId mainxid,
00157                     int nxids, const TransactionId *xids);
00158 extern XLogRecPtr TransactionIdGetCommitLSN(TransactionId xid);
00159 
00160 /* in transam/varsup.c */
00161 extern TransactionId GetNewTransactionId(bool isSubXact);
00162 extern TransactionId ReadNewTransactionId(void);
00163 extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid,
00164                       Oid oldest_datoid);
00165 extern bool ForceTransactionIdLimitUpdate(void);
00166 extern Oid  GetNewObjectId(void);
00167 
00168 #endif   /* TRAMSAM_H */