submitting patch from enterprise version
[csql.git] / include / SqlLogConnection.h
blob9fee482ec29209a743b4451dfebe8a013f6d125b
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>
27 /**
28 * @class SqlLogConnection
32 class AbsSqlLogSend
34 public:
35 virtual DbRetVal prepare(int txnId, int stmtId, int len, char *stmt)=0;
36 virtual DbRetVal commit(int len, void *data)=0;
37 virtual DbRetVal free(int txnId, int stmtId)=0;
40 class FileSend : public AbsSqlLogSend
42 int fdRedoLog;
43 public:
44 FileSend();
45 DbRetVal prepare(int txnId, int stmtId, int len, char *stmt);
46 DbRetVal commit(int len, void *data);
47 DbRetVal free(int txnId, int stmtId);
50 enum ExecType
52 EXECONLY = 0,
53 SETPARAM
56 class ExecLogInfo
58 public:
59 ExecLogInfo() : pos(0), len(0) {}
60 int stmtId;
61 ExecType type;
62 int pos;
63 DataType dataType;
64 int len;
65 char value[1];
68 class SqlLogConnection : public AbsSqlConnection
70 Connection dummyConn;
72 //stores all the sql log packets to be shipped to peers
73 List logStore;
75 List execLogStore;
76 int execLogStoreSize;
78 //stores all the prepare log packets to be shipped to peers
79 //as soon as connection is reestablished to cache server
80 List prepareStore;
82 //stores all the prepare log packets to be shipped between two
83 //consecutive commits. Commit() call sends first all the stmts
84 //prepared during the course and then sends the exec pkts
85 List curPrepareStore;
87 //sync mode of the current transaction
88 TransSyncMode syncMode;
90 //stores client objects in it for peer
91 NetworkTable nwTable;
92 AbsSqlLogSend *fileSend;
94 static GlobalUniqueID txnUID;
95 static List cacheList;
96 int txnID;
97 DbRetVal populateCachedTableList();
98 public:
99 SqlLogConnection() {
100 innerConn = NULL; syncMode = ASYNC;
101 if (Conf::config.useDurability()) { fileSend = new FileSend(); }
102 execLogStoreSize =0;
104 bool isTableCached(char *name);
106 //Note::forced to implement this as it is pure virtual in base class
107 Connection& getConnObject(){ return dummyConn; }
109 DbRetVal connect (char *user, char * pass);
111 DbRetVal disconnect();
113 DbRetVal commit();
115 DbRetVal rollback();
117 DbRetVal beginTrans (IsolationLevel isoLevel, TransSyncMode mode);
119 DbRetVal fileLogPrepare(int txnId, int stmtId, int len, char *stmt)
121 return fileSend->prepare(txnId, stmtId, len, stmt);
123 DbRetVal commitLogs(int logSize, void *data)
125 int txnId = getTxnID();
126 if (Conf::config.useDurability()) fileSend->commit(logSize, data);
127 return OK;
129 DbRetVal freeLogs(int stmtId)
131 int txnId = getTxnID();
132 if (Conf::config.useDurability()) fileSend->free(txnId, stmtId);
133 return OK;
135 void addExecLog(ExecLogInfo *info) { execLogStore.append(info); }
136 void addToExecLogSize(int size){ execLogStoreSize += size; }
137 int getExecLogStoreSize() { return execLogStoreSize; }
138 List getExecLogList() { return execLogStore; }
139 DbRetVal addPacket(BasePacket *pkt);
140 DbRetVal addPreparePacket(PacketPrepare *pkt);
141 DbRetVal removePreparePacket(int stmtid);
143 DbRetVal setSyncMode(TransSyncMode mode);
144 TransSyncMode getSyncMode() { return syncMode; }
145 int getTxnID() { return txnID; }
146 DbRetVal connectIfNotConnected() { return nwTable.connectIfNotConnected(); }
147 DbRetVal sendAndReceive(NetworkPacketType type, char *packet, int length);
148 friend class SqlFactory;
151 #endif