exp changes and test case modification as we do not support mmap to
[csql.git] / include / SqlLogConnection.h
blob3f47e20b5569f3de825d63522cde32f7cf89f3b4
1 /***************************************************************************
2 * Copyright (C) 2007 by Prabakaran Thirumalai *
3 * praba_tuty@yahoo.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 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #ifndef SQLLOGCONNECTION_H
21 #define SQLLOGCONNECTION_H
22 #include<CSql.h>
23 #include<SqlFactory.h>
24 #include<Util.h>
25 #include<Network.h>
29 * @class SqlLogConnection
33 typedef struct my_msgbuffer {
34 long mtype;
35 void *data;
36 } Message;
38 class DllExport AbsSqlLogSend
40 public:
41 virtual DbRetVal prepare(int tId, int sId, int len, char *st, char *tn,
42 bool hasParam)=0;
43 virtual DbRetVal commit(int len, void *data)=0;
44 virtual DbRetVal free(int txnId, int stmtId, bool hasParam)=0;
47 class DllExport MsgQueueSend : public AbsSqlLogSend
49 int msgQId;
50 public:
51 MsgQueueSend() { msgQId = os::msgget(Conf::config.getMsgKey(), 0666); }
52 DbRetVal prepare(int tId, int sId, int len, char *stmt, char *tn,
53 bool hasParam);
54 DbRetVal commit(int len, void *data);
55 DbRetVal free(int txnId, int stmtId, bool hasParam);
58 class DllExport FileSend : public AbsSqlLogSend
60 int fdRedoLog;
61 int fdStmtLog;
62 public:
63 FileSend();
64 ~FileSend();
65 DbRetVal openRedoFile();
66 DbRetVal prepare(int txnId, int stmtId, int len, char *stmt, char*tn,
67 bool hasParam);
68 DbRetVal commit(int len, void *data);
69 DbRetVal free(int txnId, int stmtId, bool hasParam);
73 class DllExport OfflineLog : public AbsSqlLogSend
75 int fdOfflineLog;
76 void *metadata;
77 int fileSize;
78 DbRetVal createMetadataFile();
79 void *openMetadataFile();
80 public:
81 OfflineLog();
82 ~OfflineLog();
83 DbRetVal openOfflineLogFile();
84 DbRetVal prepare(int txnId, int stmtId, int len, char *stmt, char*tn,
85 bool hasParam);
86 DbRetVal commit(int len, void *data);
87 DbRetVal free(int txnId, int stmtId, bool hasParam);
91 enum ExecType
93 EXECONLY = 0,
94 SETPARAM
97 class ExecLogInfo
99 public:
100 ExecLogInfo() : pos(0), len(0), isNull(0) {}
101 int stmtId;
102 ExecType type;
103 int pos;
104 int isNull;
105 DataType dataType;
106 int len;
107 void *value; //Extendible value as per parameter type size
110 class DllExport SqlLogConnection : public AbsSqlConnection
112 Connection dummyConn;
114 List execLogStore;
115 int execLogStoreSize;
117 //sync mode of the current transaction
118 TransSyncMode syncMode;
120 AbsSqlLogSend *msgQSend;
121 AbsSqlLogSend *fileSend;
122 AbsSqlLogSend *offlineLog;
124 GlobalUniqueID txnUID;
125 static List cacheList;
126 int txnID;
127 DbRetVal populateCachedTableList();
128 public:
129 bool noMsgLog;
130 bool noOfflineLog;
132 SqlLogConnection() {
133 innerConn = NULL; syncMode = ASYNC;
134 msgQSend = NULL; fileSend = NULL; offlineLog = NULL;
135 #ifndef MMDB
136 if (Conf::config.useCache() && Conf::config.getCacheMode()==ASYNC_MODE)
137 msgQSend = new MsgQueueSend();
138 if (Conf::config.useCache() &&
139 Conf::config.getCacheMode() == OFFLINE_MODE)
140 offlineLog = new OfflineLog;
141 #endif
142 if (Conf::config.useDurability()) { fileSend = new FileSend(); }
143 txnUID.open();
144 execLogStoreSize =0;
145 noMsgLog = false;
146 noOfflineLog = false;
147 txnID = 0;
149 ~SqlLogConnection();
150 bool isTableCached(char *name);
152 inline bool isNoLogRequired()
154 if (!msgQSend && !fileSend && !offlineLog) return true;
155 else return false;
157 inline bool isMsgQReqd()
159 if (msgQSend) return true; else return false;
161 inline bool isFileLogReqd()
163 if (fileSend) return true; else return false;
165 inline bool isOfflineLogReqd()
167 if (offlineLog) return true; else return false;
169 //Note::forced to implement this as it is pure virtual in base class
170 Connection& getConnObject(){ return dummyConn; }
172 DbRetVal connect (char *user, char * pass);
174 DbRetVal disconnect();
176 DbRetVal commit();
178 DbRetVal rollback();
180 DbRetVal beginTrans (IsolationLevel isoLevel, TransSyncMode mode);
182 DbRetVal msgPrepare(int tId, int sId, int len, char *stmt, char *tname,
183 bool hasParam)
185 return msgQSend->prepare(tId, sId, len, stmt, tname, hasParam);
187 DbRetVal fileLogPrepare(int tId, int sId, int len, char *stmt, char *tname,
188 bool hasParam)
190 return fileSend->prepare(tId, sId, len, stmt, tname, hasParam);
192 DbRetVal offlineLogPrepare(int tId, int sId, int len, char *stmt,
193 char *tname, bool hasParam)
195 return offlineLog->prepare(tId, sId, len, stmt, tname, hasParam);
197 DbRetVal commitLogs(int logSize, void *data)
199 int txnId = getTxnID();
200 if (msgQSend && !noMsgLog) msgQSend->commit(logSize, data);
201 if (fileSend) fileSend->commit(logSize, data);
202 if (offlineLog && !noOfflineLog) offlineLog->commit(logSize, data);
203 return OK;
205 DbRetVal freeLogs(int stmtId, bool hasParam)
207 int txnId = getTxnID();
208 if (msgQSend && !noMsgLog) msgQSend->free(txnId, stmtId, hasParam);
209 if (fileSend) fileSend->free(txnId, stmtId, hasParam);
210 if (offlineLog && !noOfflineLog)
211 offlineLog->free(txnId, stmtId, hasParam);
212 return OK;
215 inline void addExecLog(ExecLogInfo *info) { execLogStore.append(info); }
216 inline void addToExecLogSize(int size) { execLogStoreSize += size; }
217 inline int getExecLogStoreSize() { return execLogStoreSize; }
218 List getExecLogList() { return execLogStore; }
220 DbRetVal setSyncMode(TransSyncMode mode);
221 inline void setNoMsgLog(bool nmlog) { noMsgLog = nmlog; }
222 inline void setNoOfflineLog(bool nolog) { noOfflineLog = nolog; }
223 inline TransSyncMode getSyncMode() { return syncMode; }
224 inline int getTxnID() { return txnID; }
225 friend class SqlFactory;
228 #endif