1 /***************************************************************************
2 * Copyright (C) 2007 by Prabakaran Thirumalai *
3 * praba_tuty@yahoo.com *
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. *
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. *
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
23 #include<SqlFactory.h>
28 * @class SqlLogConnection
32 typedef struct my_msgbuffer
{
40 virtual DbRetVal
prepare(int tId
, int sId
, int len
, char *st
,
42 virtual DbRetVal
commit(int len
, void *data
)=0;
43 virtual DbRetVal
free(int txnId
, int stmtId
)=0;
46 class MsgQueueSend
: public AbsSqlLogSend
50 MsgQueueSend() { msgQId
= os::msgget(Conf::config
.getMsgKey(), 0666); }
51 DbRetVal
prepare(int tId
, int sId
, int len
, char *stmt
, char *tn
);
52 DbRetVal
commit(int len
, void *data
);
53 DbRetVal
free(int txnId
, int stmtId
);
56 class FileSend
: public AbsSqlLogSend
62 DbRetVal
prepare(int txnId
, int stmtId
, int len
, char *stmt
, char*tn
);
63 DbRetVal
commit(int len
, void *data
);
64 DbRetVal
free(int txnId
, int stmtId
);
76 ExecLogInfo() : pos(0), len(0) {}
82 int value
; //Extendible value as per parameter type size
85 class SqlLogConnection
: public AbsSqlConnection
89 //stores all the sql log packets to be shipped to peers
95 //stores all the prepare log packets to be shipped to peers
96 //as soon as connection is reestablished to cache server
99 //stores all the prepare log packets to be shipped between two
100 //consecutive commits. Commit() call sends first all the stmts
101 //prepared during the course and then sends the exec pkts
102 List curPrepareStore
;
104 //sync mode of the current transaction
105 TransSyncMode syncMode
;
107 //stores client objects in it for peer
108 NetworkTable nwTable
;
109 AbsSqlLogSend
*msgQSend
;
110 AbsSqlLogSend
*fileSend
;
112 GlobalUniqueID txnUID
;
113 static List cacheList
;
115 DbRetVal
populateCachedTableList();
118 innerConn
= NULL
; syncMode
= ASYNC
;
119 if (Conf::config
.useCache() &&
120 Conf::config
.getCacheMode()==ASYNC_MODE
)
121 msgQSend
= new MsgQueueSend();
122 else msgQSend
= NULL
;
123 if (Conf::config
.useDurability()) { fileSend
= new FileSend(); }
124 else fileSend
= NULL
;
130 bool isTableCached(char *name
);
132 //Note::forced to implement this as it is pure virtual in base class
133 Connection
& getConnObject(){ return dummyConn
; }
135 DbRetVal
connect (char *user
, char * pass
);
137 DbRetVal
disconnect();
143 DbRetVal
beginTrans (IsolationLevel isoLevel
, TransSyncMode mode
);
145 DbRetVal
msgPrepare(int tId
, int sId
, int len
, char *stmt
, char *tname
)
147 return msgQSend
->prepare(tId
, sId
, len
, stmt
, tname
);
149 DbRetVal
fileLogPrepare(int tId
, int sId
, int len
, char *stmt
, char *tname
)
151 return fileSend
->prepare(tId
, sId
, len
, stmt
, tname
);
153 DbRetVal
commitLogs(int logSize
, void *data
)
155 int txnId
= getTxnID();
156 if (((Conf::config
.useCache() &&
157 Conf::config
.getCacheMode() == ASYNC_MODE
)) && !noMsgLog
)
158 msgQSend
->commit(logSize
, data
);
159 if (Conf::config
.useDurability()) fileSend
->commit(logSize
, data
);
162 DbRetVal
freeLogs(int stmtId
)
164 int txnId
= getTxnID();
165 if ( ((Conf::config
.useCache() &&
166 Conf::config
.getCacheMode() == ASYNC_MODE
)) && !noMsgLog
)
167 msgQSend
->free(txnId
, stmtId
);
168 if (Conf::config
.useDurability()) fileSend
->free(txnId
, stmtId
);
171 void addExecLog(ExecLogInfo
*info
) { execLogStore
.append(info
); }
172 void addToExecLogSize(int size
){ execLogStoreSize
+= size
; }
173 int getExecLogStoreSize() { return execLogStoreSize
; }
174 List
getExecLogList() { return execLogStore
; }
175 DbRetVal
addPacket(BasePacket
*pkt
);
176 DbRetVal
addPreparePacket(PacketPrepare
*pkt
);
177 DbRetVal
removePreparePacket(int stmtid
);
179 DbRetVal
setSyncMode(TransSyncMode mode
);
180 void setNoMsgLog(bool nmlog
) { noMsgLog
= nmlog
; }
181 TransSyncMode
getSyncMode() { return syncMode
; }
182 int getTxnID() { return txnID
; }
183 DbRetVal
connectIfNotConnected() { return nwTable
.connectIfNotConnected(); }
184 DbRetVal
sendAndReceive(NetworkPacketType type
, char *packet
, int length
);
185 friend class SqlFactory
;