]> granicus.if.org Git - postgresql/blob - src/include/access/transam.h
Another PGINDENT run that changes variable indenting and case label indenting. Also...
[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.9 1997/09/08 02:34:27 momjian 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 <storage/bufmgr.h>
21 #include <utils/nabstime.h>
22
23 /* ----------------
24  *              transaction system version id
25  *
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.
30  *
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.
34  * ----------------
35  */
36 #define TRANS_SYSTEM_VERSION    101
37
38 /* ----------------
39  *              transaction id status values
40  *
41  *              someday we will use "11" = 3 = XID_INVALID to mean the
42  *              starting of run-length encoded log data.
43  * ----------------
44  */
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 */
49
50 typedef unsigned char XidStatus;/* (2 bits) */
51
52 /* ----------
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.
56  * ----------
57  */
58 #define BootstrapObjectIdData 16384
59
60 /* ----------------
61  *              BitIndexOf computes the index of the Nth xid on a given block
62  * ----------------
63  */
64 #define BitIndexOf(N)   ((N) * 2)
65
66 /* ----------------
67  *              transaction page definitions
68  * ----------------
69  */
70 #define TP_DataSize                             BLCKSZ
71 #define TP_NumXidStatusPerBlock (TP_DataSize * 4)
72 #define TP_NumTimePerBlock              (TP_DataSize / 4)
73
74 /* ----------------
75  *              LogRelationContents structure
76  *
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.
81  *
82  *              The first 4 bytes of this relation store the version
83  *              number of the transction system.
84  * ----------------
85  */
86 typedef struct LogRelationContentsData
87 {
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 {
107         int                     TransSystemVersion;
108 }                       TimeRelationContentsData;
109
110 typedef TimeRelationContentsData *TimeRelationContents;
111
112 /* ----------------
113  *              VariableRelationContents structure
114  *
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.
119  *
120  *              The first 4 bytes of this relation store the version
121  *              number of the transction system.
122  *
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.
126  * ----------------
127  */
128 typedef struct VariableRelationContentsData
129 {
130         int                     TransSystemVersion;
131         TransactionId nextXidData;
132         TransactionId lastXidData;
133         Oid                     nextOid;
134 }                       VariableRelationContentsData;
135
136 typedef VariableRelationContentsData *VariableRelationContents;
137
138 /* ----------------
139  *              extern declarations
140  * ----------------
141  */
142
143 /*
144  * prototypes for functions in transam/transam.c
145  */
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);
152
153 /* in transam/transsup.c */
154 extern void AmiTransactionOverride(bool flag);
155 extern void
156 TransComputeBlockNumber(Relation relation,
157                          TransactionId transactionId, BlockNumber * blockNumberOutP);
158 extern          XidStatus
159 TransBlockNumberGetXidStatus(Relation relation,
160                            BlockNumber blockNumber, TransactionId xid, bool * failP);
161 extern void
162 TransBlockNumberSetXidStatus(Relation relation,
163                    BlockNumber blockNumber, TransactionId xid, XidStatus xstatus,
164                                                          bool * failP);
165 extern          AbsoluteTime
166 TransBlockNumberGetCommitTime(Relation relation,
167                            BlockNumber blockNumber, TransactionId xid, bool * failP);
168 extern void
169 TransBlockNumberSetCommitTime(Relation relation,
170                   BlockNumber blockNumber, TransactionId xid, AbsoluteTime xtime,
171                                                           bool * failP);
172
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);
179
180 /* ----------------
181  *              global variable extern declarations
182  * ----------------
183  */
184
185 /* in transam.c */
186 extern Relation LogRelation;
187 extern Relation TimeRelation;
188 extern Relation VariableRelation;
189
190 extern TransactionId cachedGetCommitTimeXid;
191 extern AbsoluteTime cachedGetCommitTime;
192 extern TransactionId cachedTestXid;
193 extern XidStatus cachedTestXidStatus;
194
195 extern TransactionId NullTransactionId;
196 extern TransactionId AmiTransactionId;
197 extern TransactionId FirstTransactionId;
198
199 extern int      RecoveryCheckingEnableState;
200
201 /* in transsup.c */
202 extern bool AMI_OVERRIDE;
203
204 /* in varsup.c */
205 extern int      OidGenLockId;
206
207 #endif                                                  /* TRAMSAM_H */