00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _EYEDBSM_TRANSACTION_H
00026 #define _EYEDBSM_TRANSACTION_H
00027
00028 #include <time.h>
00029 #include "xm_alloc.h"
00030 #include <eyedblib/thread.h>
00031 #include <eyedbsm/eyedbsm.h>
00032 #include "eyedbsm/mutex.h"
00033
00034 #define TRY_DATA
00035 #define KEEP_ORDER
00036
00037
00038
00039 namespace eyedbsm {
00040 enum TransactionOP {
00041
00042 OCREATE = 0,
00043 OREAD,
00044 OWRITE,
00045 ODELETE,
00046 OCREADEL,
00047 OCHSIZE,
00048 OERROR,
00049 OP_CNT,
00050
00051
00052 PCREATE,
00053 PREAD,
00054 PWRITE,
00055 PDELETE,
00056 LOCKS = 0x200,
00057 LOCKX = 0x400,
00058 LOCKSX = 0x800,
00059 LOCKN = 0x1000
00060 };
00061
00062 enum LockModeIndex {
00063 R_S_W_S = 0,
00064 R_S_W_SX,
00065 R_S_W_X,
00066 R_SX_W_SX,
00067 R_SX_W_X,
00068 R_X_W_X,
00069 R_N_W_S,
00070 R_N_W_SX,
00071 R_N_W_X,
00072 R_N_W_N,
00073 DB_W,
00074 DB_RW,
00075 DB_Wtrans,
00076 LockModeIndex_CNT
00077 };
00078
00079 enum TransState {
00080 NilTransState,
00081 TransACTIVE,
00082 TransCOMMITING,
00083 TransABORTING,
00084 TransCOMMITED,
00085 TransABORTED
00086 };
00087
00088 enum ProcState {
00089 NilProcState,
00090 ProcRunning,
00091 ProcWaiting
00092 };
00093
00094 enum OPMode {
00095 OPImmediate = 1,
00096 OPGrowingPhase,
00097 OPShrinkingPhase,
00098 OPDefault = OPGrowingPhase
00099 };
00100
00101 #define TRS_SECURE
00102
00103 struct Transaction {
00104 #ifdef TRS_SECURE
00105 eyedblib::uint32 magic;
00106 #endif
00107 TransState trs_state;
00108 ProcState proc_state;
00109
00110 eyedblib::int64 create_time;
00111 eyedblib::int64 access_time;
00112 time_t timestamp;
00113 unsigned int xid;
00114 unsigned int obj_cnt;
00115 unsigned int del_obj_cnt;
00116 XMOffset trobj_wait;
00117 LockMode lock_wait;
00118 XMOffset ht_off;
00119
00120 Boolean wrimmediate;
00121 char dl;
00122 Boolean prot_update;
00123 XMOffset prev, next;
00124 #ifdef TRS_INTER_MUT
00125 eyedbsm::Mutex mut;
00126 eyedbsm::MutexP mp;
00127 #else
00128 eyedblib::Mutex mut;
00129 #endif
00130 };
00131
00132
00133
00134 enum State {
00135 Active = 1,
00136 Deleted,
00137 Zombie
00138 };
00139
00140 static const NS INVALID_NS = ~0U;
00141
00142 struct OidLoc {
00143 NS ns;
00144 short datid;
00145 };
00146
00147
00148
00149 struct TRObject {
00150 #ifdef TRS_SECURE
00151 eyedblib::uint32 magic;
00152 #endif
00153 TransactionOP op;
00154 unsigned int lockS;
00155 unsigned int lockX;
00156 unsigned int lockSX;
00157 unsigned int lockP;
00158 XMOffset po_off;
00159 Oid oid;
00160 OidLoc oidloc;
00161 State state;
00162 #ifdef EYEDB_USE_DATA_VMEM
00163 void *data;
00164 #else
00165 XMOffset data;
00166 #endif
00167 XMOffset prev, next;
00168 #ifdef KEEP_ORDER
00169 XMOffset xprev, xnext;
00170 #endif
00171 Boolean prot_oid_set;
00172 Oid prot_oid;
00173 #ifdef TRS_INTER_MUT
00174 eyedbsm::Mutex mut;
00175 eyedbsm::MutexP mp;
00176 #else
00177 eyedblib::Mutex mut;
00178 #endif
00179 };
00180
00181 struct TransOwner {
00182 XMOffset trs_off;
00183 LockMode trs_lock;
00184 XMOffset prev, next;
00185 };
00186
00187 struct PObject {
00188 #ifdef TRS_SECURE
00189 eyedblib::uint32 magic;
00190 #endif
00191 Oid oid;
00192 unsigned int lockS;
00193 unsigned int lockX;
00194 unsigned int lockSX;
00195 unsigned int lockPxid;
00196 unsigned int tridx;
00197 XMOffset cond;
00198
00199 int refcnt;
00200 int trs_cnt;
00201 TransOwner trs_own;
00202
00203 int wait_cnt;
00204
00205 State state;
00206 XMOffset prev, next;
00207 };
00208
00209 struct TransactionContext {
00210 XMOffset trs_off;
00211 TransactionParams params;
00212 LockModeIndex lockmodeIndex;
00213 Boolean skip;
00214 };
00215
00216 struct TransHeader {
00217 MutexP mut_access;
00218 XMOffset obj_ht;
00219 XMOffset first_trs;
00220 int tr_cnt;
00221 };
00222
00223 #ifdef TRS_SECURE
00224 static const unsigned int TRS_MAGIC = 0x23ffed12;
00225 static const unsigned int POBJ_MAGIC = 0x6e199930;
00226 static const unsigned int TROBJ_MAGIC = 0x5110293e;
00227 static const unsigned int MT_MAGIC_BASE = (eyedblib::uint32)0x62efd812;
00228
00229
00230 static const unsigned int MT_MAGIC = (MT_MAGIC_BASE + 1);
00231
00232 static const unsigned int POBJ_MAGIC_DELETED = 0xffe35601;
00233 static const unsigned int TROBJ_MAGIC_DELETED = 0x77ef1234;
00234
00235 enum {
00236 MAXTRS = 16
00237 };
00238
00239 extern TRObject *
00240 TRObjectAlloc(XMHandle *);
00241
00242 extern void
00243 TRObjectFree(XMHandle *, TRObject *);
00244
00245 extern PObject *
00246 PObjectAlloc(XMHandle *);
00247
00248 extern void
00249 PObjectFree(XMHandle *, PObject *);
00250
00251 extern void
00252 ESM_transactionObjectProtSet(TRObject *, const Oid *prot_oid);
00253
00254 extern Status
00255 ESM_objectLock(DbHandle const *dbh, const Oid *oid, TransactionOP,
00256 Boolean *, TRObject **),
00257 ESM_objectLockCheck(DbHandle const *dbh, const Oid *oid,
00258 TransactionOP op, Boolean *popsync,
00259 Boolean *mustExists, TRObject **ptro),
00260 ESM_objectGetLock(DbHandle const *dbh, const Oid *oid,
00261 LockMode *rmode),
00262 ESM_objectDownLock(DbHandle const *dbh, Oid const *const oid),
00263 ESM_transactionBegin(DbHandle const *, const TransactionParams *),
00264
00265 ESM_transactionCommit(DbHandle const *),
00266 ESM_transactionAbort(DbHandle const *),
00267
00268 ESM_transactionParamsSet(DbHandle const *dbh,
00269 const TransactionParams *params),
00270
00271 ESM_transactionParamsGet(DbHandle const *dbh,
00272 TransactionParams *params);
00273 extern char *
00274 ESM_trobjDataGet(DbHandle const *dbh, TRObject *tro, unsigned int size);
00275
00276 extern char *
00277 ESM_trobjDataGetIfExist(DbHandle const *dbh, TRObject *tro);
00278
00279 extern void
00280 ESM_trobjDataWrite(char *addr, const char *object, unsigned int start,
00281 unsigned int length, OPMode, Boolean);
00282
00283 extern Status
00284 ESM_trobjDataRead(char *object, const char *addr, const char *dbaddr,
00285 unsigned int start,
00286 unsigned int length, Boolean, Boolean);
00287
00288 extern void
00289 ESM_transInit(DbDescription *, char *, unsigned int);
00290
00291 extern Status
00292 ESM_transactionCreate(DbHandle const *, const TransactionParams *params,
00293 XMOffset *);
00294
00295 extern Status
00296 ESM_transactionDelete(DbHandle const *, XMOffset, TransState);
00297
00298 extern Status
00299 deadLockCheck(XMHandle *, Transaction *, PObject *, LockMode);
00300
00301 extern Status
00302 ESM_transactionLockSet(DbHandle const *dbh, ObjectLockMode mode,
00303 ObjectLockMode *omode);
00304
00305 extern Boolean
00306 ESM_protectionsMustUpdate(DbHandle const *);
00307
00308 extern const Oid *
00309 ESM_getProtection(DbHandle const *, const Oid *oid,
00310 const Oid *prot_oid);
00311
00312 extern Status
00313 ESM_transactionsGarbage(DbHandle const *dbh, Boolean mustLock);
00314
00315 extern Boolean ESM_isTransactionActive(Transaction *trs);
00316
00317 #define SHM_HEADSIZE sizeof(DbShmHeader)
00318
00319
00320 #endif
00321
00322 extern int trs_init(void);
00323
00324 extern Boolean trace_garb_trs;
00325
00326 }
00327 #endif