1 /*-------------------------------------------------------------------------
4 * postgres transaction access method support code header
7 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: transam.h,v 1.35 2001/05/25 15:45:33 momjian Exp $
13 * Transaction System Version 101 now support proper oid
14 * generation and recording in the variable relation.
16 *-------------------------------------------------------------------------
21 #include "storage/bufmgr.h"
24 * transaction system version id
26 * this is stored on the first page of the log, time and variable
27 * relations on the first 4 bytes. This is so that if we improve
28 * the format of the transaction log after postgres version 2, then
29 * people won't have to rebuild their databases.
31 * TRANS_SYSTEM_VERSION 100 means major version 1 minor version 0.
32 * Two databases with the same major version should be compatible,
33 * even if their minor versions differ.
36 #define TRANS_SYSTEM_VERSION 200
39 * transaction id status values
41 * someday we will use "11" = 3 = XID_COMMIT_CHILD to mean the
42 * commiting of child xactions.
45 #define XID_COMMIT 2 /* transaction commited */
46 #define XID_ABORT 1 /* transaction aborted */
47 #define XID_INPROGRESS 0 /* transaction in progress */
48 #define XID_COMMIT_CHILD 3 /* child xact commited */
50 typedef unsigned char XidStatus;/* (2 bits) */
53 * note: we reserve the first 16384 object ids for internal use.
54 * oid's less than this appear in the .bki files. the choice of
55 * 16384 is completely arbitrary.
58 #define BootstrapObjectIdData 16384
61 * BitIndexOf computes the index of the Nth xid on a given block
64 #define BitIndexOf(N) ((N) * 2)
67 * transaction page definitions
70 #define TP_DataSize (BLCKSZ - sizeof(XLogRecPtr))
71 #define TP_NumXidStatusPerBlock (TP_DataSize * 4)
74 * LogRelationContents structure
76 * This structure describes the storage of the data in the
77 * first 128 bytes of the log relation. This storage is never
78 * used for transaction status because transaction id's begin
79 * their numbering at 512.
81 * The first 4 bytes of this relation store the version
82 * number of the transaction system.
85 typedef struct LogRelationContentsData
87 XLogRecPtr LSN; /* temp hack: LSN is member of any block */
88 /* so should be described in bufmgr */
89 int TransSystemVersion;
90 } LogRelationContentsData;
92 typedef LogRelationContentsData *LogRelationContents;
95 * VariableCache is placed in shmem and used by
96 * backends to get next available XID & OID.
98 typedef struct VariableCacheData
100 TransactionId nextXid; /* next XID to assign */
101 Oid nextOid; /* next OID to assign */
102 uint32 oidCount; /* OIDs available before must do XLOG work */
105 typedef VariableCacheData *VariableCache;
108 * extern declarations
113 * prototypes for functions in transam/transam.c
115 extern void InitializeTransactionLog(void);
116 extern bool TransactionIdDidCommit(TransactionId transactionId);
117 extern bool TransactionIdDidAbort(TransactionId transactionId);
118 extern void TransactionIdCommit(TransactionId transactionId);
119 extern void TransactionIdAbort(TransactionId transactionId);
121 /* in transam/transsup.c */
122 extern void AmiTransactionOverride(bool flag);
123 extern void TransComputeBlockNumber(Relation relation,
124 TransactionId transactionId, BlockNumber *blockNumberOutP);
125 extern XidStatus TransBlockNumberGetXidStatus(Relation relation,
126 BlockNumber blockNumber, TransactionId xid, bool *failP);
127 extern void TransBlockNumberSetXidStatus(Relation relation,
128 BlockNumber blockNumber, TransactionId xid, XidStatus xstatus,
131 /* in transam/varsup.c */
132 extern void GetNewTransactionId(TransactionId *xid);
133 extern void ReadNewTransactionId(TransactionId *xid);
134 extern void GetNewObjectId(Oid *oid_return);
135 extern void CheckMaxObjectId(Oid assigned_oid);
138 * global variable extern declarations
143 extern Relation LogRelation;
145 extern TransactionId cachedTestXid;
146 extern XidStatus cachedTestXidStatus;
148 extern TransactionId NullTransactionId;
149 extern TransactionId AmiTransactionId;
150 extern TransactionId FirstTransactionId;
152 extern int RecoveryCheckingEnableState;
155 extern bool AMI_OVERRIDE;
158 extern SPINLOCK OidGenLockId;
159 extern SPINLOCK XidGenLockId;
160 extern VariableCache ShmemVariableCache;
162 #endif /* TRAMSAM_H */