]> granicus.if.org Git - postgresql/blob - src/include/access/transam.h
Major code cleanups from D'arcy (-Wall -Werror)
[postgresql] / src / include / access / transam.h
1 /*-------------------------------------------------------------------------
2  *
3  * transam.h--
4  *    postgres transaction access method support code header
5  *
6  *
7  * Copyright (c) 1994, Regents of the University of California
8  *
9  * $Id: transam.h,v 1.2 1996/10/23 07:41:31 scrappy Exp $
10  *
11  *   NOTES
12  *      Transaction System Version 101 now support proper oid
13  *      generation and recording in the variable relation.
14  *
15  *-------------------------------------------------------------------------
16  */
17 #ifndef TRANSAM_H
18 #define TRANSAM_H
19
20 #include "utils/nabstime.h"
21 #include "utils/rel.h"
22 #include "storage/bufmgr.h"
23
24 /* ----------------
25  *      transaction system version id
26  *
27  *      this is stored on the first page of the log, time and variable
28  *      relations on the first 4 bytes.  This is so that if we improve
29  *      the format of the transaction log after postgres version 2, then
30  *      people won't have to rebuild their databases.
31  *
32  *      TRANS_SYSTEM_VERSION 100 means major version 1 minor version 0.
33  *      Two databases with the same major version should be compatible,
34  *      even if their minor versions differ.
35  * ----------------
36  */
37 #define TRANS_SYSTEM_VERSION    101
38
39 /* ----------------
40  *      transaction id status values
41  *
42  *      someday we will use "11" = 3 = XID_INVALID to mean the
43  *      starting of run-length encoded log data.
44  * ----------------
45  */
46 #define XID_COMMIT      2                       /* transaction commited */
47 #define XID_ABORT       1                       /* transaction aborted */
48 #define XID_INPROGRESS  0                       /* transaction in progress */
49 #define XID_INVALID     3                       /* other */
50
51 typedef unsigned char XidStatus;                /* (2 bits) */
52
53 /* ----------
54  *      note: we reserve the first 16384 object ids for internal use.
55  *      oid's less than this appear in the .bki files.  the choice of
56  *      16384 is completely arbitrary.
57  * ----------
58  */
59 #define BootstrapObjectIdData 16384
60
61 /* ----------------
62  *      BitIndexOf computes the index of the Nth xid on a given block
63  * ----------------
64  */
65 #define BitIndexOf(N)   ((N) * 2)
66
67 /* ----------------
68  *      transaction page definitions
69  * ----------------
70  */
71 #define TP_DataSize             BLCKSZ
72 #define TP_NumXidStatusPerBlock (TP_DataSize * 4)
73 #define TP_NumTimePerBlock      (TP_DataSize / 4)
74
75 /* ----------------
76  *      LogRelationContents structure
77  *
78  *      This structure describes the storage of the data in the
79  *      first 128 bytes of the log relation.  This storage is never
80  *      used for transaction status because transaction id's begin
81  *      their numbering at 512.
82  *
83  *      The first 4 bytes of this relation store the version
84  *      number of the transction system.
85  * ----------------
86  */
87 typedef struct LogRelationContentsData {
88     int                 TransSystemVersion;
89 } LogRelationContentsData;
90
91 typedef LogRelationContentsData *LogRelationContents;
92
93 /* ----------------
94  *      TimeRelationContents structure
95  *
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.
100  *
101  *      The first 4 bytes of this relation store the version
102  *      number of the transction system.
103  * ----------------
104  */
105 typedef struct TimeRelationContentsData {
106     int                 TransSystemVersion;
107 } TimeRelationContentsData;
108
109 typedef TimeRelationContentsData *TimeRelationContents;
110
111 /* ----------------
112  *      VariableRelationContents structure
113  *
114  *      The variable relation is a special "relation" which
115  *      is used to store various system "variables" persistantly.
116  *      Unlike other relations in the system, this relation
117  *      is updated in place whenever the variables change.
118  *
119  *      The first 4 bytes of this relation store the version
120  *      number of the transction system.
121  *
122  *      Currently, the relation has only one page and the next
123  *      available xid, the last committed xid and the next
124  *      available oid are stored there.
125  * ----------------
126  */
127 typedef struct VariableRelationContentsData {
128     int                 TransSystemVersion;
129     TransactionId       nextXidData;
130     TransactionId       lastXidData;
131     Oid                 nextOid;
132 } VariableRelationContentsData;
133
134 typedef VariableRelationContentsData *VariableRelationContents;
135
136 /* ----------------
137  *      extern declarations
138  * ----------------
139  */
140
141 /*
142  * prototypes for functions in transam/transam.c
143  */
144 extern int RecoveryCheckingEnabled();
145 extern void SetRecoveryCheckingEnabled(bool state);
146 extern bool TransactionLogTest(TransactionId transactionId, XidStatus status);
147 extern void TransactionLogUpdate(TransactionId transactionId,
148                                  XidStatus status);
149 extern AbsoluteTime TransactionIdGetCommitTime(TransactionId transactionId);
150 extern void TransRecover(Relation logRelation);
151 extern void InitializeTransactionLog();
152 extern bool TransactionIdDidCommit(TransactionId transactionId);
153 extern bool TransactionIdDidAbort(TransactionId transactionId);
154 extern bool TransactionIdIsInProgress(TransactionId transactionId);
155 extern void TransactionIdCommit(TransactionId transactionId);
156 extern void TransactionIdAbort(TransactionId transactionId);
157 extern void TransactionIdSetInProgress(TransactionId transactionId);
158
159 /* in transam/transsup.c */
160 extern void AmiTransactionOverride(bool flag);
161 extern void TransComputeBlockNumber(Relation relation,
162         TransactionId transactionId, BlockNumber *blockNumberOutP);
163 extern XidStatus TransBlockGetLastTransactionIdStatus(Block tblock,
164         TransactionId baseXid, TransactionId *returnXidP);
165 extern XidStatus TransBlockGetXidStatus(Block tblock,
166                                         TransactionId transactionId);
167 extern void TransBlockSetXidStatus(Block tblock,
168         TransactionId transactionId, XidStatus xstatus);
169 extern AbsoluteTime TransBlockGetCommitTime(Block tblock,
170         TransactionId transactionId);
171 extern void TransBlockSetCommitTime(Block tblock,
172         TransactionId transactionId, AbsoluteTime commitTime);
173 extern XidStatus TransBlockNumberGetXidStatus(Relation relation,
174         BlockNumber blockNumber, TransactionId xid, bool *failP);
175 extern void TransBlockNumberSetXidStatus(Relation relation,
176         BlockNumber blockNumber, TransactionId xid, XidStatus xstatus,
177         bool *failP);
178 extern AbsoluteTime TransBlockNumberGetCommitTime(Relation relation,
179         BlockNumber blockNumber, TransactionId xid, bool *failP);
180 extern void TransBlockNumberSetCommitTime(Relation relation,
181         BlockNumber blockNumber, TransactionId xid, AbsoluteTime xtime,
182         bool *failP);
183 extern void TransGetLastRecordedTransaction(Relation relation,
184         TransactionId xid, bool *failP);
185
186 /* in transam/varsup.c */
187 extern void VariableRelationGetNextXid(TransactionId *xidP);
188 extern void VariableRelationGetLastXid(TransactionId *xidP);
189 extern void VariableRelationPutNextXid(TransactionId xid);
190 extern void VariableRelationPutLastXid(TransactionId xid);
191 extern void VariableRelationGetNextOid(Oid *oid_return);
192 extern void VariableRelationPutNextOid(Oid *oidP);
193 extern void GetNewTransactionId(TransactionId *xid);
194 extern void UpdateLastCommittedXid(TransactionId xid);
195 extern void GetNewObjectIdBlock(Oid *oid_return, int oid_block_size);
196 extern void GetNewObjectId(Oid *oid_return);
197 extern void CheckMaxObjectId(Oid assigned_oid);
198
199 /* ----------------
200  *      global variable extern declarations
201  * ----------------
202  */
203
204 /* in transam.c */
205 extern Relation LogRelation;
206 extern Relation TimeRelation;
207 extern Relation VariableRelation;
208
209 extern TransactionId    cachedGetCommitTimeXid;
210 extern AbsoluteTime     cachedGetCommitTime;
211 extern TransactionId    cachedTestXid;
212 extern XidStatus        cachedTestXidStatus;
213
214 extern TransactionId NullTransactionId;
215 extern TransactionId AmiTransactionId;
216 extern TransactionId FirstTransactionId;
217
218 extern int RecoveryCheckingEnableState;
219
220 /* in transsup.c */
221 extern bool AMI_OVERRIDE;       
222
223 /* in varsup.c */
224 extern int OidGenLockId;
225
226 #endif /* TRAMSAM_H */