]> granicus.if.org Git - postgresql/blob - src/include/access/transam.h
SET TRANSACTION ISOLATION LEVEL ...
[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.18 1998/12/18 09:09:52 vadim 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
22 /* ----------------
23  *              transaction system version id
24  *
25  *              this is stored on the first page of the log, time and variable
26  *              relations on the first 4 bytes.  This is so that if we improve
27  *              the format of the transaction log after postgres version 2, then
28  *              people won't have to rebuild their databases.
29  *
30  *              TRANS_SYSTEM_VERSION 100 means major version 1 minor version 0.
31  *              Two databases with the same major version should be compatible,
32  *              even if their minor versions differ.
33  * ----------------
34  */
35 #define TRANS_SYSTEM_VERSION    200
36
37 /* ----------------
38  *              transaction id status values
39  *
40  *              someday we will use "11" = 3 = XID_COMMIT_CHILD to mean the
41  *              commiting of child xactions.
42  * ----------------
43  */
44 #define XID_COMMIT                      2       /* transaction commited */
45 #define XID_ABORT                       1       /* transaction aborted */
46 #define XID_INPROGRESS          0       /* transaction in progress */
47 #define XID_COMMIT_CHILD        3       /* child xact commited */
48
49 typedef unsigned char XidStatus;/* (2 bits) */
50
51 /* ----------
52  *              note: we reserve the first 16384 object ids for internal use.
53  *              oid's less than this appear in the .bki files.  the choice of
54  *              16384 is completely arbitrary.
55  * ----------
56  */
57 #define BootstrapObjectIdData 16384
58
59 /* ----------------
60  *              BitIndexOf computes the index of the Nth xid on a given block
61  * ----------------
62  */
63 #define BitIndexOf(N)   ((N) * 2)
64
65 /* ----------------
66  *              transaction page definitions
67  * ----------------
68  */
69 #define TP_DataSize                             BLCKSZ
70 #define TP_NumXidStatusPerBlock (TP_DataSize * 4)
71
72 /* ----------------
73  *              LogRelationContents structure
74  *
75  *              This structure describes the storage of the data in the
76  *              first 128 bytes of the log relation.  This storage is never
77  *              used for transaction status because transaction id's begin
78  *              their numbering at 512.
79  *
80  *              The first 4 bytes of this relation store the version
81  *              number of the transction system.
82  * ----------------
83  */
84 typedef struct LogRelationContentsData
85 {
86         int                     TransSystemVersion;
87 } LogRelationContentsData;
88
89 typedef LogRelationContentsData *LogRelationContents;
90
91 /* ----------------
92  *              VariableRelationContents structure
93  *
94  *              The variable relation is a special "relation" which
95  *              is used to store various system "variables" persistantly.
96  *              Unlike other relations in the system, this relation
97  *              is updated in place whenever the variables change.
98  *
99  *              The first 4 bytes of this relation store the version
100  *              number of the transction system.
101  *
102  *              Currently, the relation has only one page and the next
103  *              available xid, the last committed xid and the next
104  *              available oid are stored there.
105  * ----------------
106  */
107 typedef struct VariableRelationContentsData
108 {
109         int                     TransSystemVersion;
110         TransactionId nextXidData;
111         TransactionId lastXidData;      /* unused */
112         Oid                     nextOid;
113 } VariableRelationContentsData;
114
115 typedef VariableRelationContentsData *VariableRelationContents;
116
117 /*
118  * VariableCache is placed in shmem and used by backends to
119  * get next available XID & OID without access to
120  * variable relation. Actually, I would like to have two
121  * different on-disk storages for next XID and OID...
122  * But hoping that someday we will use per database OID
123  * generator I leaved this as is.       - vadim 07/21/98
124  */
125 typedef struct VariableCacheData
126 {
127         uint32          xid_count;
128         TransactionId nextXid;
129         uint32          oid_count;              /* not implemented, yet */
130         Oid                     nextOid;
131 }                       VariableCacheData;
132
133 typedef VariableCacheData *VariableCache;
134
135 /* ----------------
136  *              extern declarations
137  * ----------------
138  */
139
140 /*
141  * prototypes for functions in transam/transam.c
142  */
143 extern void InitializeTransactionLog(void);
144 extern bool TransactionIdDidCommit(TransactionId transactionId);
145 extern bool TransactionIdDidAbort(TransactionId transactionId);
146 extern void TransactionIdCommit(TransactionId transactionId);
147 extern void TransactionIdAbort(TransactionId transactionId);
148 extern void     TransactionIdFlushCache(void);
149
150 /* in transam/transsup.c */
151 extern void AmiTransactionOverride(bool flag);
152 extern void TransComputeBlockNumber(Relation relation,
153                           TransactionId transactionId, BlockNumber *blockNumberOutP);
154 extern XidStatus TransBlockNumberGetXidStatus(Relation relation,
155                                 BlockNumber blockNumber, TransactionId xid, bool *failP);
156 extern void TransBlockNumberSetXidStatus(Relation relation,
157                    BlockNumber blockNumber, TransactionId xid, XidStatus xstatus,
158                                                          bool *failP);
159
160 /* in transam/varsup.c */
161 extern void VariableRelationPutNextXid(TransactionId xid);
162 extern void GetNewTransactionId(TransactionId *xid);
163 extern void ReadNewTransactionId(TransactionId *xid);
164 extern void GetNewObjectId(Oid *oid_return);
165 extern void CheckMaxObjectId(Oid assigned_oid);
166
167 /* ----------------
168  *              global variable extern declarations
169  * ----------------
170  */
171
172 /* in transam.c */
173 extern Relation LogRelation;
174 extern Relation VariableRelation;
175
176 extern TransactionId cachedTestXid;
177 extern XidStatus cachedTestXidStatus;
178
179 extern TransactionId NullTransactionId;
180 extern TransactionId AmiTransactionId;
181 extern TransactionId FirstTransactionId;
182
183 extern int      RecoveryCheckingEnableState;
184
185 /* in transsup.c */
186 extern bool AMI_OVERRIDE;
187
188 /* in varsup.c */
189 extern int      OidGenLockId;
190
191 #endif   /* TRAMSAM_H */