]> granicus.if.org Git - postgresql/blob - src/include/access/xact.h
pgindent run for 9.0
[postgresql] / src / include / access / xact.h
1 /*-------------------------------------------------------------------------
2  *
3  * xact.h
4  *        postgres transaction system definitions
5  *
6  *
7  * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/access/xact.h,v 1.103 2010/02/26 02:01:21 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef XACT_H
15 #define XACT_H
16
17 #include "access/xlog.h"
18 #include "nodes/pg_list.h"
19 #include "storage/relfilenode.h"
20 #include "utils/timestamp.h"
21
22
23 /*
24  * Xact isolation levels
25  */
26 #define XACT_READ_UNCOMMITTED   0
27 #define XACT_READ_COMMITTED             1
28 #define XACT_REPEATABLE_READ    2
29 #define XACT_SERIALIZABLE               3
30
31 extern int      DefaultXactIsoLevel;
32 extern int      XactIsoLevel;
33
34 /*
35  * We only implement two isolation levels internally.  This macro should
36  * be used to check which one is selected.
37  */
38 #define IsXactIsoLevelSerializable (XactIsoLevel >= XACT_REPEATABLE_READ)
39
40 /* Xact read-only state */
41 extern bool DefaultXactReadOnly;
42 extern bool XactReadOnly;
43
44 /* Asynchronous commits */
45 extern bool XactSyncCommit;
46
47 /* Kluge for 2PC support */
48 extern bool MyXactAccessedTempRel;
49
50 /*
51  *      start- and end-of-transaction callbacks for dynamically loaded modules
52  */
53 typedef enum
54 {
55         XACT_EVENT_COMMIT,
56         XACT_EVENT_ABORT,
57         XACT_EVENT_PREPARE
58 } XactEvent;
59
60 typedef void (*XactCallback) (XactEvent event, void *arg);
61
62 typedef enum
63 {
64         SUBXACT_EVENT_START_SUB,
65         SUBXACT_EVENT_COMMIT_SUB,
66         SUBXACT_EVENT_ABORT_SUB
67 } SubXactEvent;
68
69 typedef void (*SubXactCallback) (SubXactEvent event, SubTransactionId mySubid,
70                                                                         SubTransactionId parentSubid, void *arg);
71
72
73 /* ----------------
74  *              transaction-related XLOG entries
75  * ----------------
76  */
77
78 /*
79  * XLOG allows to store some information in high 4 bits of log
80  * record xl_info field
81  */
82 #define XLOG_XACT_COMMIT                        0x00
83 #define XLOG_XACT_PREPARE                       0x10
84 #define XLOG_XACT_ABORT                         0x20
85 #define XLOG_XACT_COMMIT_PREPARED       0x30
86 #define XLOG_XACT_ABORT_PREPARED        0x40
87 #define XLOG_XACT_ASSIGNMENT            0x50
88
89 typedef struct xl_xact_assignment
90 {
91         TransactionId xtop;                     /* assigned XID's top-level XID */
92         int                     nsubxacts;              /* number of subtransaction XIDs */
93         TransactionId xsub[1];          /* assigned subxids */
94 } xl_xact_assignment;
95
96 #define MinSizeOfXactAssignment offsetof(xl_xact_assignment, xsub)
97
98 typedef struct xl_xact_commit
99 {
100         TimestampTz xact_time;          /* time of commit */
101         uint32          xinfo;                  /* info flags */
102         int                     nrels;                  /* number of RelFileNodes */
103         int                     nsubxacts;              /* number of subtransaction XIDs */
104         int                     nmsgs;                  /* number of shared inval msgs */
105         Oid                     dbId;                   /* MyDatabaseId */
106         Oid                     tsId;                   /* MyDatabaseTableSpace */
107         /* Array of RelFileNode(s) to drop at commit */
108         RelFileNode xnodes[1];          /* VARIABLE LENGTH ARRAY */
109         /* ARRAY OF COMMITTED SUBTRANSACTION XIDs FOLLOWS */
110         /* ARRAY OF SHARED INVALIDATION MESSAGES FOLLOWS */
111 } xl_xact_commit;
112
113 #define MinSizeOfXactCommit offsetof(xl_xact_commit, xnodes)
114
115 /*
116  * These flags are set in the xinfo fields of WAL commit records,
117  * indicating a variety of additional actions that need to occur
118  * when emulating transaction effects during recovery.
119  * They are named XactCompletion... to differentiate them from
120  * EOXact... routines which run at the end of the original
121  * transaction completion.
122  */
123 #define XACT_COMPLETION_UPDATE_RELCACHE_FILE    0x01
124 #define XACT_COMPLETION_FORCE_SYNC_COMMIT               0x02
125
126 /* Access macros for above flags */
127 #define XactCompletionRelcacheInitFileInval(xlrec)      ((xlrec)->xinfo & XACT_COMPLETION_UPDATE_RELCACHE_FILE)
128 #define XactCompletionForceSyncCommit(xlrec)            ((xlrec)->xinfo & XACT_COMPLETION_FORCE_SYNC_COMMIT)
129
130 typedef struct xl_xact_abort
131 {
132         TimestampTz xact_time;          /* time of abort */
133         int                     nrels;                  /* number of RelFileNodes */
134         int                     nsubxacts;              /* number of subtransaction XIDs */
135         /* Array of RelFileNode(s) to drop at abort */
136         RelFileNode xnodes[1];          /* VARIABLE LENGTH ARRAY */
137         /* ARRAY OF ABORTED SUBTRANSACTION XIDs FOLLOWS */
138 } xl_xact_abort;
139
140 /* Note the intentional lack of an invalidation message array c.f. commit */
141
142 #define MinSizeOfXactAbort offsetof(xl_xact_abort, xnodes)
143
144 /*
145  * COMMIT_PREPARED and ABORT_PREPARED are identical to COMMIT/ABORT records
146  * except that we have to store the XID of the prepared transaction explicitly
147  * --- the XID in the record header will be for the transaction doing the
148  * COMMIT PREPARED or ABORT PREPARED command.
149  */
150
151 typedef struct xl_xact_commit_prepared
152 {
153         TransactionId xid;                      /* XID of prepared xact */
154         xl_xact_commit crec;            /* COMMIT record */
155         /* MORE DATA FOLLOWS AT END OF STRUCT */
156 } xl_xact_commit_prepared;
157
158 #define MinSizeOfXactCommitPrepared offsetof(xl_xact_commit_prepared, crec.xnodes)
159
160 typedef struct xl_xact_abort_prepared
161 {
162         TransactionId xid;                      /* XID of prepared xact */
163         xl_xact_abort arec;                     /* ABORT record */
164         /* MORE DATA FOLLOWS AT END OF STRUCT */
165 } xl_xact_abort_prepared;
166
167 #define MinSizeOfXactAbortPrepared offsetof(xl_xact_abort_prepared, arec.xnodes)
168
169
170 /* ----------------
171  *              extern definitions
172  * ----------------
173  */
174 extern bool IsTransactionState(void);
175 extern bool IsAbortedTransactionBlockState(void);
176 extern TransactionId GetTopTransactionId(void);
177 extern TransactionId GetTopTransactionIdIfAny(void);
178 extern TransactionId GetCurrentTransactionId(void);
179 extern TransactionId GetCurrentTransactionIdIfAny(void);
180 extern SubTransactionId GetCurrentSubTransactionId(void);
181 extern CommandId GetCurrentCommandId(bool used);
182 extern TimestampTz GetCurrentTransactionStartTimestamp(void);
183 extern TimestampTz GetCurrentStatementStartTimestamp(void);
184 extern TimestampTz GetCurrentTransactionStopTimestamp(void);
185 extern void SetCurrentStatementStartTimestamp(void);
186 extern int      GetCurrentTransactionNestLevel(void);
187 extern bool TransactionIdIsCurrentTransactionId(TransactionId xid);
188 extern void CommandCounterIncrement(void);
189 extern void ForceSyncCommit(void);
190 extern void StartTransactionCommand(void);
191 extern void CommitTransactionCommand(void);
192 extern void AbortCurrentTransaction(void);
193 extern void BeginTransactionBlock(void);
194 extern bool EndTransactionBlock(void);
195 extern bool PrepareTransactionBlock(char *gid);
196 extern void UserAbortTransactionBlock(void);
197 extern void ReleaseSavepoint(List *options);
198 extern void DefineSavepoint(char *name);
199 extern void RollbackToSavepoint(List *options);
200 extern void BeginInternalSubTransaction(char *name);
201 extern void ReleaseCurrentSubTransaction(void);
202 extern void RollbackAndReleaseCurrentSubTransaction(void);
203 extern bool IsSubTransaction(void);
204 extern bool IsTransactionBlock(void);
205 extern bool IsTransactionOrTransactionBlock(void);
206 extern char TransactionBlockStatusCode(void);
207 extern void AbortOutOfAnyTransaction(void);
208 extern void PreventTransactionChain(bool isTopLevel, const char *stmtType);
209 extern void RequireTransactionChain(bool isTopLevel, const char *stmtType);
210 extern bool IsInTransactionChain(bool isTopLevel);
211 extern void RegisterXactCallback(XactCallback callback, void *arg);
212 extern void UnregisterXactCallback(XactCallback callback, void *arg);
213 extern void RegisterSubXactCallback(SubXactCallback callback, void *arg);
214 extern void UnregisterSubXactCallback(SubXactCallback callback, void *arg);
215
216 extern int      xactGetCommittedChildren(TransactionId **ptr);
217
218 extern void xact_redo(XLogRecPtr lsn, XLogRecord *record);
219 extern void xact_desc(StringInfo buf, uint8 xl_info, char *rec);
220
221 #endif   /* XACT_H */