Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef XACT_H
00015 #define XACT_H
00016
00017 #include "access/xlog.h"
00018 #include "nodes/pg_list.h"
00019 #include "storage/relfilenode.h"
00020
00021
00022
00023
00024
00025 #define XACT_READ_UNCOMMITTED 0
00026 #define XACT_READ_COMMITTED 1
00027 #define XACT_REPEATABLE_READ 2
00028 #define XACT_SERIALIZABLE 3
00029
00030 extern int DefaultXactIsoLevel;
00031 extern PGDLLIMPORT int XactIsoLevel;
00032
00033
00034
00035
00036
00037
00038
00039
00040 #define IsolationUsesXactSnapshot() (XactIsoLevel >= XACT_REPEATABLE_READ)
00041 #define IsolationIsSerializable() (XactIsoLevel == XACT_SERIALIZABLE)
00042
00043
00044 extern bool DefaultXactReadOnly;
00045 extern bool XactReadOnly;
00046
00047
00048
00049
00050
00051 extern bool DefaultXactDeferrable;
00052 extern bool XactDeferrable;
00053
00054 typedef enum
00055 {
00056 SYNCHRONOUS_COMMIT_OFF,
00057 SYNCHRONOUS_COMMIT_LOCAL_FLUSH,
00058 SYNCHRONOUS_COMMIT_REMOTE_WRITE,
00059
00060 SYNCHRONOUS_COMMIT_REMOTE_FLUSH
00061 } SyncCommitLevel;
00062
00063
00064 #define SYNCHRONOUS_COMMIT_ON SYNCHRONOUS_COMMIT_REMOTE_FLUSH
00065
00066
00067 extern int synchronous_commit;
00068
00069
00070 extern bool MyXactAccessedTempRel;
00071
00072
00073
00074
00075 typedef enum
00076 {
00077 XACT_EVENT_COMMIT,
00078 XACT_EVENT_ABORT,
00079 XACT_EVENT_PREPARE,
00080 XACT_EVENT_PRE_COMMIT,
00081 XACT_EVENT_PRE_PREPARE
00082 } XactEvent;
00083
00084 typedef void (*XactCallback) (XactEvent event, void *arg);
00085
00086 typedef enum
00087 {
00088 SUBXACT_EVENT_START_SUB,
00089 SUBXACT_EVENT_COMMIT_SUB,
00090 SUBXACT_EVENT_ABORT_SUB,
00091 SUBXACT_EVENT_PRE_COMMIT_SUB
00092 } SubXactEvent;
00093
00094 typedef void (*SubXactCallback) (SubXactEvent event, SubTransactionId mySubid,
00095 SubTransactionId parentSubid, void *arg);
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 #define XLOG_XACT_COMMIT 0x00
00108 #define XLOG_XACT_PREPARE 0x10
00109 #define XLOG_XACT_ABORT 0x20
00110 #define XLOG_XACT_COMMIT_PREPARED 0x30
00111 #define XLOG_XACT_ABORT_PREPARED 0x40
00112 #define XLOG_XACT_ASSIGNMENT 0x50
00113 #define XLOG_XACT_COMMIT_COMPACT 0x60
00114
00115 typedef struct xl_xact_assignment
00116 {
00117 TransactionId xtop;
00118 int nsubxacts;
00119 TransactionId xsub[1];
00120 } xl_xact_assignment;
00121
00122 #define MinSizeOfXactAssignment offsetof(xl_xact_assignment, xsub)
00123
00124 typedef struct xl_xact_commit_compact
00125 {
00126 TimestampTz xact_time;
00127 int nsubxacts;
00128
00129 TransactionId subxacts[1];
00130 } xl_xact_commit_compact;
00131
00132 #define MinSizeOfXactCommitCompact offsetof(xl_xact_commit_compact, subxacts)
00133
00134 typedef struct xl_xact_commit
00135 {
00136 TimestampTz xact_time;
00137 uint32 xinfo;
00138 int nrels;
00139 int nsubxacts;
00140 int nmsgs;
00141 Oid dbId;
00142 Oid tsId;
00143
00144 RelFileNode xnodes[1];
00145
00146
00147 } xl_xact_commit;
00148
00149 #define MinSizeOfXactCommit offsetof(xl_xact_commit, xnodes)
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 #define XACT_COMPLETION_UPDATE_RELCACHE_FILE 0x01
00160 #define XACT_COMPLETION_FORCE_SYNC_COMMIT 0x02
00161
00162
00163 #define XactCompletionRelcacheInitFileInval(xinfo) (xinfo & XACT_COMPLETION_UPDATE_RELCACHE_FILE)
00164 #define XactCompletionForceSyncCommit(xinfo) (xinfo & XACT_COMPLETION_FORCE_SYNC_COMMIT)
00165
00166 typedef struct xl_xact_abort
00167 {
00168 TimestampTz xact_time;
00169 int nrels;
00170 int nsubxacts;
00171
00172 RelFileNode xnodes[1];
00173
00174 } xl_xact_abort;
00175
00176
00177
00178 #define MinSizeOfXactAbort offsetof(xl_xact_abort, xnodes)
00179
00180
00181
00182
00183
00184
00185
00186
00187 typedef struct xl_xact_commit_prepared
00188 {
00189 TransactionId xid;
00190 xl_xact_commit crec;
00191
00192 } xl_xact_commit_prepared;
00193
00194 #define MinSizeOfXactCommitPrepared offsetof(xl_xact_commit_prepared, crec.xnodes)
00195
00196 typedef struct xl_xact_abort_prepared
00197 {
00198 TransactionId xid;
00199 xl_xact_abort arec;
00200
00201 } xl_xact_abort_prepared;
00202
00203 #define MinSizeOfXactAbortPrepared offsetof(xl_xact_abort_prepared, arec.xnodes)
00204
00205
00206
00207
00208
00209
00210 extern bool IsTransactionState(void);
00211 extern bool IsAbortedTransactionBlockState(void);
00212 extern TransactionId GetTopTransactionId(void);
00213 extern TransactionId GetTopTransactionIdIfAny(void);
00214 extern TransactionId GetCurrentTransactionId(void);
00215 extern TransactionId GetCurrentTransactionIdIfAny(void);
00216 extern TransactionId GetStableLatestTransactionId(void);
00217 extern SubTransactionId GetCurrentSubTransactionId(void);
00218 extern bool SubTransactionIsActive(SubTransactionId subxid);
00219 extern CommandId GetCurrentCommandId(bool used);
00220 extern TimestampTz GetCurrentTransactionStartTimestamp(void);
00221 extern TimestampTz GetCurrentStatementStartTimestamp(void);
00222 extern TimestampTz GetCurrentTransactionStopTimestamp(void);
00223 extern void SetCurrentStatementStartTimestamp(void);
00224 extern int GetCurrentTransactionNestLevel(void);
00225 extern bool TransactionIdIsCurrentTransactionId(TransactionId xid);
00226 extern void CommandCounterIncrement(void);
00227 extern void ForceSyncCommit(void);
00228 extern void StartTransactionCommand(void);
00229 extern void CommitTransactionCommand(void);
00230 extern void AbortCurrentTransaction(void);
00231 extern void BeginTransactionBlock(void);
00232 extern bool EndTransactionBlock(void);
00233 extern bool PrepareTransactionBlock(char *gid);
00234 extern void UserAbortTransactionBlock(void);
00235 extern void ReleaseSavepoint(List *options);
00236 extern void DefineSavepoint(char *name);
00237 extern void RollbackToSavepoint(List *options);
00238 extern void BeginInternalSubTransaction(char *name);
00239 extern void ReleaseCurrentSubTransaction(void);
00240 extern void RollbackAndReleaseCurrentSubTransaction(void);
00241 extern bool IsSubTransaction(void);
00242 extern bool IsTransactionBlock(void);
00243 extern bool IsTransactionOrTransactionBlock(void);
00244 extern char TransactionBlockStatusCode(void);
00245 extern void AbortOutOfAnyTransaction(void);
00246 extern void PreventTransactionChain(bool isTopLevel, const char *stmtType);
00247 extern void RequireTransactionChain(bool isTopLevel, const char *stmtType);
00248 extern bool IsInTransactionChain(bool isTopLevel);
00249 extern void RegisterXactCallback(XactCallback callback, void *arg);
00250 extern void UnregisterXactCallback(XactCallback callback, void *arg);
00251 extern void RegisterSubXactCallback(SubXactCallback callback, void *arg);
00252 extern void UnregisterSubXactCallback(SubXactCallback callback, void *arg);
00253
00254 extern int xactGetCommittedChildren(TransactionId **ptr);
00255
00256 extern void xact_redo(XLogRecPtr lsn, XLogRecord *record);
00257 extern void xact_desc(StringInfo buf, uint8 xl_info, char *rec);
00258
00259 #endif