42 #ifndef SDB_DATA_SOURCE_HPP_
43 #define SDB_DATA_SOURCE_HPP_
52 #include "ossLatch.hpp"
54 #include "ossAtomic.hpp"
63 class sdbDataSourceStrategy ;
70 friend void createConnFunc(
void *args ) ;
71 friend void destroyConnFunc(
void *args ) ;
72 friend void bgTaskFunc(
void *args ) ;
91 _toDestroyConn(FALSE),
92 _toStopWorkers(FALSE),
93 _createConnWorker(NULL),
94 _destroyConnWorker(NULL),
95 _bgTaskWorker(NULL) {}
126 const std::vector<std::string> &vUrls,
134 INT32 getIdleConnNum()
const ;
141 INT32 getUsedConnNum()
const ;
148 INT32 getNormalCoordNum()
const ;
155 INT32 getAbnormalCoordNum()
const ;
162 INT32 getLocalCoordNum()
const ;
168 void addCoord(
const string &url ) ;
174 void removeCoord(
const string &url ) ;
203 INT32 getConnection(
sdb*& conn, INT64 timeoutms = 5000 ) ;
211 void releaseConnection(
sdb *conn) ;
227 BOOLEAN _checkAddrArg(
const string &url ) ;
230 INT32 _buildStrategy() ;
233 void _clearDataSource() ;
236 BOOLEAN _tryGetConn(
sdb*& conn ) ;
239 INT32 _createConnByNum( INT32 num ) ;
242 void _syncCoordNodes() ;
245 INT32 _retrieveAddrFromAbnormalList() ;
248 BOOLEAN _keepAliveTimeOut(
sdb *conn ) ;
251 void _checkMaxIdleConn() ;
254 BOOLEAN _addNewConnSafely(
sdb *conn,
const std::string &coord );
261 void _destroyConn() ;
268 std::list<sdb*> _idleList ;
269 ossAtomic32 _idleSize ;
271 std::list<sdb*> _busyList ;
272 ossAtomic32 _busySize ;
274 std::list<sdb*> _destroyList ;
278 sdbDataSourceStrategy* _strategy ;
280 ossSpinXLatch _connMutex ;
282 ossSpinXLatch _globalMutex ;
289 BOOLEAN _toCreateConn ;
290 BOOLEAN _toDestroyConn ;
291 BOOLEAN _toStopWorkers ;
292 sdbDSWorker* _createConnWorker ;
293 sdbDSWorker* _destroyConnWorker ;
294 sdbDSWorker* _bgTaskWorker ;