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-2013, 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 /* compare two XIDs already known to be normal; this is a macro for speed */
00062 #define NormalTransactionIdPrecedes(id1, id2) \
00063     (AssertMacro(TransactionIdIsNormal(id1) && TransactionIdIsNormal(id2)), \
00064     (int32) ((id1) - (id2)) < 0)
00065 
00066 /* ----------
00067  *      Object ID (OID) zero is InvalidOid.
00068  *
00069  *      OIDs 1-9999 are reserved for manual assignment (see the files
00070  *      in src/include/catalog/).
00071  *
00072  *      OIDS 10000-16383 are reserved for assignment during initdb
00073  *      using the OID generator.  (We start the generator at 10000.)
00074  *
00075  *      OIDs beginning at 16384 are assigned from the OID generator
00076  *      during normal multiuser operation.  (We force the generator up to
00077  *      16384 as soon as we are in normal operation.)
00078  *
00079  * The choices of 10000 and 16384 are completely arbitrary, and can be moved
00080  * if we run low on OIDs in either category.  Changing the macros below
00081  * should be sufficient to do this.
00082  *
00083  * NOTE: if the OID generator wraps around, we skip over OIDs 0-16383
00084  * and resume with 16384.  This minimizes the odds of OID conflict, by not
00085  * reassigning OIDs that might have been assigned during initdb.
00086  * ----------
00087  */
00088 #define FirstBootstrapObjectId  10000
00089 #define FirstNormalObjectId     16384
00090 
00091 /*
00092  * VariableCache is a data structure in shared memory that is used to track
00093  * OID and XID assignment state.  For largely historical reasons, there is
00094  * just one struct with different fields that are protected by different
00095  * LWLocks.
00096  *
00097  * Note: xidWrapLimit and oldestXidDB are not "active" values, but are
00098  * used just to generate useful messages when xidWarnLimit or xidStopLimit
00099  * are exceeded.
00100  */
00101 typedef struct VariableCacheData
00102 {
00103     /*
00104      * These fields are protected by OidGenLock.
00105      */
00106     Oid         nextOid;        /* next OID to assign */
00107     uint32      oidCount;       /* OIDs available before must do XLOG work */
00108 
00109     /*
00110      * These fields are protected by XidGenLock.
00111      */
00112     TransactionId nextXid;      /* next XID to assign */
00113 
00114     TransactionId oldestXid;    /* cluster-wide minimum datfrozenxid */
00115     TransactionId xidVacLimit;  /* start forcing autovacuums here */
00116     TransactionId xidWarnLimit; /* start complaining here */
00117     TransactionId xidStopLimit; /* refuse to advance nextXid beyond here */
00118     TransactionId xidWrapLimit; /* where the world ends */
00119     Oid         oldestXidDB;    /* database with minimum datfrozenxid */
00120 
00121     /*
00122      * These fields are protected by ProcArrayLock.
00123      */
00124     TransactionId latestCompletedXid;   /* newest XID that has committed or
00125                                          * aborted */
00126 } VariableCacheData;
00127 
00128 typedef VariableCacheData *VariableCache;
00129 
00130 
00131 /* ----------------
00132  *      extern declarations
00133  * ----------------
00134  */
00135 
00136 /* in transam/xact.c */
00137 extern bool TransactionStartedDuringRecovery(void);
00138 
00139 /* in transam/varsup.c */
00140 extern PGDLLIMPORT VariableCache ShmemVariableCache;
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 */