1 /*-------------------------------------------------------------------------
4 * postgres transaction access method support code header
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: transam.h,v 1.8 1997/09/07 04:56:14 momjian Exp $
12 * Transaction System Version 101 now support proper oid
13 * generation and recording in the variable relation.
15 *-------------------------------------------------------------------------
20 #include <storage/bufmgr.h>
21 #include <utils/nabstime.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 101
39 * transaction id status values
41 * someday we will use "11" = 3 = XID_INVALID to mean the
42 * starting of run-length encoded log data.
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_INVALID 3 /* other */
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
71 #define TP_NumXidStatusPerBlock (TP_DataSize * 4)
72 #define TP_NumTimePerBlock (TP_DataSize / 4)
75 * LogRelationContents structure
77 * This structure describes the storage of the data in the
78 * first 128 bytes of the log relation. This storage is never
79 * used for transaction status because transaction id's begin
80 * their numbering at 512.
82 * The first 4 bytes of this relation store the version
83 * number of the transction system.
86 typedef struct LogRelationContentsData
88 int TransSystemVersion;
89 } LogRelationContentsData;
91 typedef LogRelationContentsData *LogRelationContents;
94 * TimeRelationContents structure
96 * This structure describes the storage of the data in the
97 * first 2048 bytes of the time relation. This storage is never
98 * used for transaction commit times because transaction id's begin
99 * their numbering at 512.
101 * The first 4 bytes of this relation store the version
102 * number of the transction system.
105 typedef struct TimeRelationContentsData
107 int TransSystemVersion;
108 } TimeRelationContentsData;
110 typedef TimeRelationContentsData *TimeRelationContents;
113 * VariableRelationContents structure
115 * The variable relation is a special "relation" which
116 * is used to store various system "variables" persistantly.
117 * Unlike other relations in the system, this relation
118 * is updated in place whenever the variables change.
120 * The first 4 bytes of this relation store the version
121 * number of the transction system.
123 * Currently, the relation has only one page and the next
124 * available xid, the last committed xid and the next
125 * available oid are stored there.
128 typedef struct VariableRelationContentsData
130 int TransSystemVersion;
131 TransactionId nextXidData;
132 TransactionId lastXidData;
134 } VariableRelationContentsData;
136 typedef VariableRelationContentsData *VariableRelationContents;
139 * extern declarations
144 * prototypes for functions in transam/transam.c
146 extern AbsoluteTime TransactionIdGetCommitTime(TransactionId transactionId);
147 extern void InitializeTransactionLog(void);
148 extern bool TransactionIdDidCommit(TransactionId transactionId);
149 extern bool TransactionIdDidAbort(TransactionId transactionId);
150 extern void TransactionIdCommit(TransactionId transactionId);
151 extern void TransactionIdAbort(TransactionId transactionId);
153 /* in transam/transsup.c */
154 extern void AmiTransactionOverride(bool flag);
156 TransComputeBlockNumber(Relation relation,
157 TransactionId transactionId, BlockNumber * blockNumberOutP);
159 TransBlockNumberGetXidStatus(Relation relation,
160 BlockNumber blockNumber, TransactionId xid, bool * failP);
162 TransBlockNumberSetXidStatus(Relation relation,
163 BlockNumber blockNumber, TransactionId xid, XidStatus xstatus,
166 TransBlockNumberGetCommitTime(Relation relation,
167 BlockNumber blockNumber, TransactionId xid, bool * failP);
169 TransBlockNumberSetCommitTime(Relation relation,
170 BlockNumber blockNumber, TransactionId xid, AbsoluteTime xtime,
173 /* in transam/varsup.c */
174 extern void VariableRelationPutNextXid(TransactionId xid);
175 extern void GetNewTransactionId(TransactionId * xid);
176 extern void UpdateLastCommittedXid(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 TimeRelation;
188 extern Relation VariableRelation;
190 extern TransactionId cachedGetCommitTimeXid;
191 extern AbsoluteTime cachedGetCommitTime;
192 extern TransactionId cachedTestXid;
193 extern XidStatus cachedTestXidStatus;
195 extern TransactionId NullTransactionId;
196 extern TransactionId AmiTransactionId;
197 extern TransactionId FirstTransactionId;
199 extern int RecoveryCheckingEnableState;
202 extern bool AMI_OVERRIDE;
205 extern int OidGenLockId;
207 #endif /* TRAMSAM_H */