Trie Implementation
[csql.git] / include / Transaction.h
blob691aaada5a514c39939a6da09d575fc45ca40c6c
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,
47 InsertTrieIndexOperation = 9,
48 UpdateTrieIndexOperation = 10,
49 DeleteTrieIndexOperation = 11
51 class UndoLogInfo
53 public:
54 int size_;
55 OperationType opType_;
56 void *data_;
57 UndoLogInfo *next_;
58 void print() {
59 printf("<UndoLogInfo>\n");
60 printf(" <Size> %d </Size>\n", size_);
61 printf(" <OperationType> %d </OperationType>\n", opType_);
62 printf(" <TuplePtr> %x </TuplePtr>\n", (void *) *(long *)data_);
63 printf("</UndoLogInfo>\n");
68 class HashUndoLogInfo
70 public:
71 void *tuple_;
72 void *metaData_;
73 void *keyPtr_;
74 void *hChunk_;
75 void *bucket_;
76 HashUndoLogInfo()
77 { metaData_ = tuple_ = keyPtr_ = hChunk_ = bucket_ = NULL; }
80 class TreeUndoLogInfo
82 public:
83 void *tuple_;
84 void *metaData_;
85 //void *keyPtr_;
86 void *cIndex_;//CINDEX ptr
87 TreeUndoLogInfo()
88 { metaData_ = tuple_ = cIndex_ = NULL; }
90 class TrieUndoLogInfo:public HashUndoLogInfo
94 class DllExport Transaction
96 public:
97 InUse status_;
99 IsolationLevel isoLevel_;
101 TransHasNode *hasLockList_;
103 UndoLogInfo *firstUndoLog_;
105 LockHashNode *waitLock_;
107 DbRetVal releaseAllLocks(LockManager *lockManager_);
109 void updateWaitLock(LockHashNode *node) { waitLock_ = node; }
110 void removeWaitLock() { waitLock_ = NULL; }
111 DbRetVal insertIntoHasList(Database *sysdb, LockHashNode *node);
112 DbRetVal removeFromHasList(Database *sysdb, void *tuple);
113 bool findInHasList(Database *sysdb, LockHashNode *node);
115 DbRetVal appendUndoLog(Database *sysdb, OperationType type, void *data, size_t size);
116 DbRetVal appendLogicalUndoLog(Database *sysdb, OperationType type, void *data, size_t size, void *indexPtr);
117 DbRetVal appendLogicalHashUndoLog(Database *sysdb, OperationType type, void *data, size_t size);
118 DbRetVal appendLogicalTreeUndoLog(Database *sysdb, OperationType type, void *data, size_t size);
119 DbRetVal appendLogicalTrieUndoLog(Database *sysdb, OperationType type, void *data, size_t size);
120 UndoLogInfo* createUndoLog(Database *sysdb, OperationType type, void *data,
121 size_t size, DbRetVal *rv);
122 void addAtBegin(UndoLogInfo* logInfo);
124 UndoLogInfo* popUndoLog();
125 DbRetVal removeUndoLogs(Database *sysdb);
126 DbRetVal applyUndoLogs(Database *sysdb);
127 int noOfUndoLogs();
128 void printDebugInfo(Database *sysdb);
130 private:
131 DbRetVal handleVarcharUndoInsert(Database *sysdb, char *data);
132 DbRetVal handleVarcharUndoDelete(Database *sysdb, char *data);
133 DbRetVal handleVarcharUndoUpdate(Database *sysdb, char *data,void *ptrToTuple);
136 class DllExport TransactionManager
138 public:
139 TransactionManager() { }
140 ~TransactionManager() {}
141 //Transaction *trans;
143 Transaction *firstTrans;
144 IsolationLevel getIsoLevel() {
145 if(firstTrans) return firstTrans->isoLevel_;
146 else return READ_COMMITTED;}
147 void setFirstTrans(Transaction *trans);
148 void printUsageStatistics();
149 void printDebugInfo(Database *sysdb);
151 DbRetVal startTransaction(LockManager *lManager, IsolationLevel level);
152 DbRetVal commit(LockManager *lManager);
153 DbRetVal rollback(LockManager *lManager, Transaction *t=NULL);
154 bool isTransactionConsistent(Database *db);
157 #endif