1 /*-------------------------------------------------------------------------
4 * postgres transaction access method support code header
7 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: transam.h,v 1.26 2000/11/03 11:39:36 vadim 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
71 #define TP_DataSize (BLCKSZ - sizeof(XLogRecPtr))
73 #define TP_DataSize BLCKSZ
75 #define TP_NumXidStatusPerBlock (TP_DataSize * 4)
78 * LogRelationContents structure
80 * This structure describes the storage of the data in the
81 * first 128 bytes of the log relation. This storage is never
82 * used for transaction status because transaction id's begin
83 * their numbering at 512.
85 * The first 4 bytes of this relation store the version
86 * number of the transction system.
89 typedef struct LogRelationContentsData
92 XLogRecPtr LSN; /* temp hack: LSN is member of any block */
93 /* so should be described in bufmgr */
95 int TransSystemVersion;
96 } LogRelationContentsData;
98 typedef LogRelationContentsData *LogRelationContents;
101 * VariableRelationContents structure
103 * The variable relation is a special "relation" which
104 * is used to store various system "variables" persistantly.
105 * Unlike other relations in the system, this relation
106 * is updated in place whenever the variables change.
108 * The first 4 bytes of this relation store the version
109 * number of the transction system.
111 * Currently, the relation has only one page and the next
112 * available xid, the last committed xid and the next
113 * available oid are stored there.
116 typedef struct VariableRelationContentsData
121 int TransSystemVersion;
122 TransactionId nextXidData;
123 TransactionId lastXidData; /* unused */
125 } VariableRelationContentsData;
127 typedef VariableRelationContentsData *VariableRelationContents;
130 * VariableCache is placed in shmem and used by backends to
131 * get next available XID & OID without access to
132 * variable relation. Actually, I would like to have two
133 * different on-disk storages for next XID and OID...
134 * But hoping that someday we will use per database OID
135 * generator I leaved this as is. - vadim 07/21/98
137 typedef struct VariableCacheData
142 TransactionId nextXid;
147 typedef VariableCacheData *VariableCache;
150 * extern declarations
155 * prototypes for functions in transam/transam.c
157 extern void InitializeTransactionLog(void);
158 extern bool TransactionIdDidCommit(TransactionId transactionId);
159 extern bool TransactionIdDidAbort(TransactionId transactionId);
160 extern void TransactionIdCommit(TransactionId transactionId);
161 extern void TransactionIdAbort(TransactionId transactionId);
163 /* in transam/transsup.c */
164 extern void AmiTransactionOverride(bool flag);
165 extern void TransComputeBlockNumber(Relation relation,
166 TransactionId transactionId, BlockNumber *blockNumberOutP);
167 extern XidStatus TransBlockNumberGetXidStatus(Relation relation,
168 BlockNumber blockNumber, TransactionId xid, bool *failP);
169 extern void TransBlockNumberSetXidStatus(Relation relation,
170 BlockNumber blockNumber, TransactionId xid, XidStatus xstatus,
173 /* in transam/varsup.c */
174 extern void VariableRelationPutNextXid(TransactionId xid);
175 extern void GetNewTransactionId(TransactionId *xid);
176 extern void ReadNewTransactionId(TransactionId *xid);
177 extern void GetNewObjectId(Oid *oid_return);
178 extern void CheckMaxObjectId(Oid assigned_oid);
181 * global variable extern declarations
186 extern Relation LogRelation;
187 extern Relation VariableRelation;
189 extern TransactionId cachedTestXid;
190 extern XidStatus cachedTestXidStatus;
192 extern TransactionId NullTransactionId;
193 extern TransactionId AmiTransactionId;
194 extern TransactionId FirstTransactionId;
196 extern int RecoveryCheckingEnableState;
199 extern bool AMI_OVERRIDE;
202 extern int OidGenLockId;
204 #endif /* TRAMSAM_H */