/*-------------------------------------------------------------------------
*
* transam.h
- * postgres transaction access method support code header
+ * postgres transaction access method support code
*
*
- * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
+ * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: transam.h,v 1.27 2000/11/21 21:16:05 petere Exp $
- *
- * NOTES
- * Transaction System Version 101 now support proper oid
- * generation and recording in the variable relation.
+ * $PostgreSQL: pgsql/src/include/access/transam.h,v 1.50 2004/08/29 04:13:03 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef TRANSAM_H
#define TRANSAM_H
-#include "storage/bufmgr.h"
/* ----------------
- * transaction system version id
+ * Special transaction ID values
*
- * this is stored on the first page of the log, time and variable
- * relations on the first 4 bytes. This is so that if we improve
- * the format of the transaction log after postgres version 2, then
- * people won't have to rebuild their databases.
+ * BootstrapTransactionId is the XID for "bootstrap" operations, and
+ * FrozenTransactionId is used for very old tuples. Both should
+ * always be considered valid.
*
- * TRANS_SYSTEM_VERSION 100 means major version 1 minor version 0.
- * Two databases with the same major version should be compatible,
- * even if their minor versions differ.
+ * FirstNormalTransactionId is the first "normal" transaction id.
* ----------------
*/
-#define TRANS_SYSTEM_VERSION 200
+#define InvalidTransactionId ((TransactionId) 0)
+#define BootstrapTransactionId ((TransactionId) 1)
+#define FrozenTransactionId ((TransactionId) 2)
+#define FirstNormalTransactionId ((TransactionId) 3)
+#define MaxTransactionId ((TransactionId) 0xFFFFFFFF)
/* ----------------
- * transaction id status values
- *
- * someday we will use "11" = 3 = XID_COMMIT_CHILD to mean the
- * commiting of child xactions.
+ * transaction ID manipulation macros
* ----------------
*/
-#define XID_COMMIT 2 /* transaction commited */
-#define XID_ABORT 1 /* transaction aborted */
-#define XID_INPROGRESS 0 /* transaction in progress */
-#define XID_COMMIT_CHILD 3 /* child xact commited */
+#define TransactionIdIsValid(xid) ((xid) != InvalidTransactionId)
+#define TransactionIdIsNormal(xid) ((xid) >= FirstNormalTransactionId)
+#define TransactionIdEquals(id1, id2) ((id1) == (id2))
+#define TransactionIdStore(xid, dest) (*(dest) = (xid))
+#define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId)
+/* advance a transaction ID variable, handling wraparound correctly */
+#define TransactionIdAdvance(dest) \
+ do { \
+ (dest)++; \
+ if ((dest) < FirstNormalTransactionId) \
+ (dest) = FirstNormalTransactionId; \
+ } while(0)
-typedef unsigned char XidStatus;/* (2 bits) */
/* ----------
- * note: we reserve the first 16384 object ids for internal use.
- * oid's less than this appear in the .bki files. the choice of
- * 16384 is completely arbitrary.
- * ----------
- */
-#define BootstrapObjectIdData 16384
-
-/* ----------------
- * BitIndexOf computes the index of the Nth xid on a given block
- * ----------------
- */
-#define BitIndexOf(N) ((N) * 2)
-
-/* ----------------
- * transaction page definitions
- * ----------------
- */
-#ifdef XLOG
-#define TP_DataSize (BLCKSZ - sizeof(XLogRecPtr))
-#else
-#define TP_DataSize BLCKSZ
-#endif
-#define TP_NumXidStatusPerBlock (TP_DataSize * 4)
-
-/* ----------------
- * LogRelationContents structure
+ * Object ID (OID) zero is InvalidOid.
*
- * This structure describes the storage of the data in the
- * first 128 bytes of the log relation. This storage is never
- * used for transaction status because transaction id's begin
- * their numbering at 512.
+ * OIDs 1-9999 are reserved for manual assignment (see the files
+ * in src/include/catalog/).
*
- * The first 4 bytes of this relation store the version
- * number of the transction system.
- * ----------------
- */
-typedef struct LogRelationContentsData
-{
-#ifdef XLOG
- XLogRecPtr LSN; /* temp hack: LSN is member of any block */
- /* so should be described in bufmgr */
-#endif
- int TransSystemVersion;
-} LogRelationContentsData;
-
-typedef LogRelationContentsData *LogRelationContents;
-
-/* ----------------
- * VariableRelationContents structure
+ * OIDS 10000-16383 are reserved for assignment by genbki.sh.
*
- * The variable relation is a special "relation" which
- * is used to store various system "variables" persistantly.
- * Unlike other relations in the system, this relation
- * is updated in place whenever the variables change.
+ * OIDs beginning at 16384 are assigned at runtime from the OID
+ * generator. (The first few of these will be assigned during initdb,
+ * to objects created after the initial BKI script processing.)
*
- * The first 4 bytes of this relation store the version
- * number of the transction system.
+ * The choices of 10000 and 16384 are completely arbitrary, and can be moved
+ * if we run low on OIDs in either category. Changing the macros below
+ * should be sufficient to do this.
*
- * Currently, the relation has only one page and the next
- * available xid, the last committed xid and the next
- * available oid are stored there.
- * ----------------
+ * NOTE: if the OID generator wraps around, we should skip over OIDs 0-16383
+ * and resume with 16384. This minimizes the odds of OID conflict, by not
+ * reassigning OIDs that might have been assigned during initdb.
+ * ----------
*/
-typedef struct VariableRelationContentsData
-{
-#ifdef XLOG
- XLogRecPtr LSN;
-#endif
- int TransSystemVersion;
- TransactionId nextXidData;
- TransactionId lastXidData; /* unused */
- Oid nextOid;
-} VariableRelationContentsData;
-
-typedef VariableRelationContentsData *VariableRelationContents;
+#define FirstGenBKIObjectId 10000
+#define BootstrapObjectIdData 16384
/*
- * VariableCache is placed in shmem and used by backends to
- * get next available XID & OID without access to
- * variable relation. Actually, I would like to have two
- * different on-disk storages for next XID and OID...
- * But hoping that someday we will use per database OID
- * generator I leaved this as is. - vadim 07/21/98
+ * VariableCache is placed in shmem and used by
+ * backends to get next available XID & OID.
*/
typedef struct VariableCacheData
{
-#ifndef XLOG
- uint32 xid_count;
-#endif
- TransactionId nextXid;
- Oid nextOid;
- uint32 oidCount;
+ TransactionId nextXid; /* next XID to assign */
+ Oid nextOid; /* next OID to assign */
+ uint32 oidCount; /* OIDs available before must do XLOG work */
} VariableCacheData;
typedef VariableCacheData *VariableCache;
+
/* ----------------
* extern declarations
* ----------------
*/
+/* in transam/transam.c */
+extern bool AMI_OVERRIDE;
+
+/* in transam/varsup.c */
+extern VariableCache ShmemVariableCache;
+
+
/*
* prototypes for functions in transam/transam.c
*/
-extern void InitializeTransactionLog(void);
+extern void AmiTransactionOverride(bool flag);
extern bool TransactionIdDidCommit(TransactionId transactionId);
extern bool TransactionIdDidAbort(TransactionId transactionId);
extern void TransactionIdCommit(TransactionId transactionId);
extern void TransactionIdAbort(TransactionId transactionId);
-
-/* in transam/transsup.c */
-extern void AmiTransactionOverride(bool flag);
-extern void TransComputeBlockNumber(Relation relation,
- TransactionId transactionId, BlockNumber *blockNumberOutP);
-extern XidStatus TransBlockNumberGetXidStatus(Relation relation,
- BlockNumber blockNumber, TransactionId xid, bool *failP);
-extern void TransBlockNumberSetXidStatus(Relation relation,
- BlockNumber blockNumber, TransactionId xid, XidStatus xstatus,
- bool *failP);
+extern void TransactionIdSubCommit(TransactionId transactionId);
+extern void TransactionIdCommitTree(int nxids, TransactionId *xids);
+extern void TransactionIdAbortTree(int nxids, TransactionId *xids);
+extern bool TransactionIdPrecedes(TransactionId id1, TransactionId id2);
+extern bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2);
+extern bool TransactionIdFollows(TransactionId id1, TransactionId id2);
+extern bool TransactionIdFollowsOrEquals(TransactionId id1, TransactionId id2);
/* in transam/varsup.c */
-extern void VariableRelationPutNextXid(TransactionId xid);
-extern void GetNewTransactionId(TransactionId *xid);
-extern void ReadNewTransactionId(TransactionId *xid);
-extern void GetNewObjectId(Oid *oid_return);
+extern TransactionId GetNewTransactionId(bool isSubXact);
+extern TransactionId ReadNewTransactionId(void);
+extern Oid GetNewObjectId(void);
extern void CheckMaxObjectId(Oid assigned_oid);
-/* ----------------
- * global variable extern declarations
- * ----------------
- */
-
-/* in transam.c */
-extern Relation LogRelation;
-extern Relation VariableRelation;
-
-extern TransactionId cachedTestXid;
-extern XidStatus cachedTestXidStatus;
-
-extern TransactionId NullTransactionId;
-extern TransactionId AmiTransactionId;
-extern TransactionId FirstTransactionId;
-
-extern int RecoveryCheckingEnableState;
-
-/* in transsup.c */
-extern bool AMI_OVERRIDE;
-
-/* in varsup.c */
-extern int OidGenLockId;
-extern VariableCache ShmemVariableCache;
-
-#endif /* TRAMSAM_H */
+#endif /* TRAMSAM_H */