Trie Index changes for retreiving metadata through catalog tool and
[csql.git] / include / Transaction.h
blobfcc0a0161f5feb94ff6c1c7ace2da7b9ef098130
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
92 public:
94 void **bucketPtr_;
95 TrieUndoLogInfo() { bucketPtr_ = NULL; }
98 class DllExport Transaction
100 public:
101 InUse status_;
103 IsolationLevel isoLevel_;
105 TransHasNode *hasLockList_;
107 UndoLogInfo *firstUndoLog_;
109 LockHashNode *waitLock_;
111 DbRetVal releaseAllLocks(LockManager *lockManager_);
113 void updateWaitLock(LockHashNode *node) { waitLock_ = node; }
114 void removeWaitLock() { waitLock_ = NULL; }
115 DbRetVal insertIntoHasList(Database *sysdb, LockHashNode *node);
116 DbRetVal removeFromHasList(Database *sysdb, void *tuple);
117 bool findInHasList(Database *sysdb, LockHashNode *node);
119 DbRetVal appendUndoLog(Database *sysdb, OperationType type, void *data, size_t size);
120 DbRetVal appendLogicalUndoLog(Database *sysdb, OperationType type, void *data, size_t size, void *indexPtr);
121 DbRetVal appendLogicalHashUndoLog(Database *sysdb, OperationType type, void *data, size_t size);
122 DbRetVal appendLogicalTreeUndoLog(Database *sysdb, OperationType type, void *data, size_t size);
123 DbRetVal appendLogicalTrieUndoLog(Database *sysdb, OperationType type, void *data, size_t size);
124 UndoLogInfo* createUndoLog(Database *sysdb, OperationType type, void *data,
125 size_t size, DbRetVal *rv);
126 void addAtBegin(UndoLogInfo* logInfo);
128 UndoLogInfo* popUndoLog();
129 DbRetVal removeUndoLogs(Database *sysdb);
130 DbRetVal applyUndoLogs(Database *sysdb);
131 int noOfUndoLogs();
132 void printDebugInfo(Database *sysdb);
133 void printTotalNodes();
135 private:
136 DbRetVal handleVarcharUndoInsert(Database *sysdb, char *data);
137 DbRetVal handleVarcharUndoDelete(Database *sysdb, char *data);
138 DbRetVal handleVarcharUndoUpdate(Database *sysdb, char *data,void *ptrToTuple);
141 class DllExport TransactionManager
143 public:
144 TransactionManager() { }
145 ~TransactionManager() {}
146 //Transaction *trans;
148 Transaction *firstTrans;
149 IsolationLevel getIsoLevel() {
150 if(firstTrans) return firstTrans->isoLevel_;
151 else return READ_COMMITTED;}
152 void setFirstTrans(Transaction *trans);
153 void printUsageStatistics();
154 void printDebugInfo(Database *sysdb);
156 DbRetVal startTransaction(LockManager *lManager, IsolationLevel level);
157 DbRetVal commit(LockManager *lManager);
158 DbRetVal rollback(LockManager *lManager, Transaction *t=NULL);
159 bool isTransactionConsistent(Database *db);
162 #endif