allocator fixes
[csql.git] / include / Transaction.h
blob1b851f3e4db8b8ca473b8894049c01d82e090030
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #ifndef TXN_H
17 #define TXN_H
18 #include<os.h>
19 #include<Debug.h>
20 #include<Session.h>
21 class LockHashNode;
23 enum TransStatus
25 TransNotUsed = 0,
26 TransCommitting = 1,
27 TransAborting = 2,
28 TransRunning = 3,
29 TransUnknown = 4,
30 TransReserved = 5
32 class TransHasNode;
33 class LockManager;
34 class Database;
36 enum OperationType
38 InsertOperation = 0,
39 DeleteOperation = 1,
40 UpdateOperation = 2,
41 InsertHashIndexOperation = 3,
42 UpdateHashIndexOperation = 4,
43 DeleteHashIndexOperation = 5,
44 InsertTreeIndexOperation = 6,
45 UpdateTreeIndexOperation = 7,
46 DeleteTreeIndexOperation = 8
48 class UndoLogInfo
50 public:
51 int size_;
52 OperationType opType_;
53 void *data_;
54 UndoLogInfo *next_;
55 void print() {
56 printf("<UndoLogInfo>\n");
57 printf(" <Size> %d </Size>\n", size_);
58 printf(" <OperationType> %d </OperationType>\n", opType_);
59 printf(" <TuplePtr> %x </TuplePtr>\n", (void *) *(long *)data_);
60 printf("</UndoLogInfo>\n");
65 class HashUndoLogInfo
67 public:
68 void *tuple_;
69 void *metaData_;
70 void *keyPtr_;
71 void *hChunk_;
72 void *bucket_;
73 HashUndoLogInfo()
74 { metaData_ = tuple_ = keyPtr_ = hChunk_ = bucket_ = NULL; }
77 class TreeUndoLogInfo
79 public:
80 void *tuple_;
81 void *metaData_;
82 //void *keyPtr_;
83 void *cIndex_;//CINDEX ptr
84 TreeUndoLogInfo()
85 { metaData_ = tuple_ = cIndex_ = NULL; }
88 class Transaction
90 public:
91 int status_;
93 IsolationLevel isoLevel_;
95 TransHasNode *hasLockList_;
97 UndoLogInfo *firstUndoLog_;
99 LockHashNode *waitLock_;
101 DbRetVal releaseAllLocks(LockManager *lockManager_);
103 void updateWaitLock(LockHashNode *node) { waitLock_ = node; }
104 void removeWaitLock() { waitLock_ = NULL; }
105 DbRetVal insertIntoHasList(Database *sysdb, LockHashNode *node);
106 DbRetVal removeFromHasList(Database *sysdb, void *tuple);
107 bool findInHasList(Database *sysdb, LockHashNode *node);
109 DbRetVal appendUndoLog(Database *sysdb, OperationType type, void *data, size_t size);
110 DbRetVal appendLogicalUndoLog(Database *sysdb, OperationType type, void *data, size_t size, void *indexPtr);
111 DbRetVal appendLogicalHashUndoLog(Database *sysdb, OperationType type, void *data, size_t size);
112 DbRetVal appendLogicalTreeUndoLog(Database *sysdb, OperationType type, void *data, size_t size);
113 UndoLogInfo* createUndoLog(Database *sysdb, OperationType type, void *data,
114 size_t size, DbRetVal *rv);
115 void addAtBegin(UndoLogInfo* logInfo);
117 UndoLogInfo* popUndoLog();
118 DbRetVal removeUndoLogs(Database *sysdb);
119 DbRetVal applyUndoLogs(Database *sysdb);
120 int noOfUndoLogs();
121 void printDebugInfo(Database *sysdb);
124 class TransactionManager
126 public:
127 TransactionManager() { }
128 ~TransactionManager() {}
129 //Transaction *trans;
131 Transaction *firstTrans;
132 IsolationLevel getIsoLevel() {
133 if(firstTrans) return firstTrans->isoLevel_;
134 else return READ_COMMITTED;}
135 void setFirstTrans(Transaction *trans);
136 void printUsageStatistics();
137 void printDebugInfo(Database *sysdb);
139 DbRetVal startTransaction(LockManager *lManager, IsolationLevel level);
140 DbRetVal commit(LockManager *lManager);
141 DbRetVal rollback(LockManager *lManager, Transaction *t=NULL);
142 bool isTransactionConsistent(Database *db);
145 #endif