migMaster::~migMaster() { if ( _ppBucket ) { for ( UINT32 i = 0; i < _pParameters->bucketNum; ++i ) { SAFE_OSS_DELETE ( _ppBucket[i] ) ; } } SAFE_OSS_FREE ( _ppBucket ) ; SAFE_OSS_DELETE ( _parser ) ; SAFE_OSS_FREE ( _sendMsg ) ; }
INT32 sdbDataSource::_buildStrategy() { INT32 rc = SDB_OK ; if ( _strategy ) SAFE_OSS_DELETE( _strategy ) ; switch( _conf.getConnectStrategy() ) { case DS_STY_SERIAL: _strategy = SDB_OSS_NEW sdbDSSerialStrategy() ; break ; case DS_STY_RANDOM: _strategy = SDB_OSS_NEW sdbDSRandomStrategy() ; break ; case DS_STY_LOCAL: _strategy = SDB_OSS_NEW sdbDSLocalStrategy() ; break ; case DS_STY_BALANCE: _strategy = SDB_OSS_NEW sdbDSBalanceStrategy() ; break ; } if (NULL == _strategy) { rc = SDB_OOM ; } return rc ; }
void sdbDataSource::_destroyConn() { while ( !_toStopWorkers ) { while ( !_toDestroyConn ) { if ( _toStopWorkers ) return ; ossSleep( SDB_DS_SLEEP_TIME ) ; } sdb* conn ; _connMutex.get() ; while( !_destroyList.empty() ) { conn = _destroyList.front() ; _destroyList.pop_front() ; if ( conn ) { _strategy->sync( conn, DELIDLECONN ) ; conn->disconnect() ; SAFE_OSS_DELETE( conn ) ; } } _connMutex.release() ; _toDestroyConn = FALSE ; } }
_sptSshSession::~_sptSshSession() { if ( NULL != _sock ) { _sock->close() ; SAFE_OSS_DELETE( _sock ) ; } }
void _qgmConditionNodeHelper::releaseNodes( qgmConditionNodePtrVec &nodes ) { qgmConditionNodePtrVec::iterator itr = nodes.begin() ; for ( ; itr != nodes.end(); itr++ ) { SAFE_OSS_DELETE( *itr ) ; } }
void sdbDataSource::close() { disable() ; if ( _strategy ) { SAFE_OSS_DELETE( _strategy ) ; } _isInited = FALSE; }
_mthSActionParser::~_mthSActionParser() { PARSERS::iterator itr = _parsers.begin() ; for ( ; itr != _parsers.end(); ++itr ) { SAFE_OSS_DELETE( itr->second ) ; } _parsers.clear() ; }
void _sptSshSession::close() { if ( NULL != _sock ) { _sock->close() ; SAFE_OSS_DELETE( _sock ) ; } _isOpen = FALSE ; }
INT32 _sptSshSession::open() { INT32 rc = SDB_OK ; _sock = SDB_OSS_NEW _ossSocket( _host.c_str(), _port ) ; if ( NULL == _sock ) { PD_LOG( PDERROR, "failed to allocate mem." ) ; rc = SDB_OOM ; goto error ; } rc = _sock->initSocket() ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to init socket:%d", rc ) ; goto error ; } rc = _sock->setKeepAlive( 1, OSS_SOCKET_KEEP_IDLE, OSS_SOCKET_KEEP_INTERVAL, OSS_SOCKET_KEEP_CONTER ) ; if( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to set keep alive:%d", rc ) ; goto error ; } rc = _sock->connect() ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "can not connect to host:%s:%d, rc:%d", _host.c_str(), _port, rc ) ; goto error ; } rc = _openSshSession() ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to open ssh session:%d", rc ) ; goto error ; } _isOpen = TRUE ; done: return rc ; error: if ( NULL != _sock ) { _sock->close() ; SAFE_OSS_DELETE( _sock ) ; } goto done ; }
BOOLEAN sdbDataSource::_tryGetConn( sdb*& conn ) { sdb* pConn = NULL ; BOOLEAN isGet = FALSE ; _connMutex.get() ; if ( 0 == _idleSize.peek() ) { _connMutex.release() ; goto error ; } else { pConn = _idleList.front() ;// TODO: empty or has a null value SDB_ASSERT(pConn, "the connection got from idle list can't be null") ; _idleList.pop_front() ; _idleSize.dec() ; _busyList.push_back( pConn ) ; _busySize.inc() ; _connMutex.release() ; _strategy->sync( pConn, ADDBUSYCONN ) ; } if ( _conf.getValidateConnection() ) { if ( !pConn->isValid() ) { list<sdb*>::iterator iter ; _connMutex.get() ; iter = std::find(_busyList.begin(), _busyList.end(), pConn) ; if (iter != _busyList.end()) { _busyList.erase(iter) ; _busySize.dec() ; } _connMutex.release() ; _strategy->sync( pConn, DELBUSYCONN ) ; if ( pConn ) { pConn->disconnect() ; } SAFE_OSS_DELETE( pConn ) ; goto error ; } } conn = pConn ; isGet = TRUE ; done : return isGet ; error : isGet = FALSE ; goto done ; }
_rtnContextLob::~_rtnContextLob() { if ( NULL != _stream && _stream->isOpened() ) { pmdKRCB *krcb = pmdGetKRCB() ; pmdEDUMgr *eduMgr = krcb->getEDUMgr() ; pmdEDUCB *cb = eduMgr->getEDUByID( eduID() ) ; _stream->closeWithException( cb ) ; } SAFE_OSS_DELETE( _stream ) ; }
INT32 aggrSortParser::buildNode( const BSONElement &elem, const CHAR *pCLName, qgmOptiTreeNode *&pNode, _qgmPtrTable *pTable, _qgmParamTable *pParamTable ) { INT32 rc = SDB_OK; qgmOptiSelect *pSelect = SDB_OSS_NEW qgmOptiSelect( pTable, pParamTable ); PD_CHECK( pSelect!=NULL, SDB_OOM, error, PDERROR, "malloc failed!" ); PD_CHECK( elem.type()==Object, SDB_INVALIDARG, error, PDERROR, "failed to parse the parameter(%s),type must be number!", elem.fieldName() ); try { qgmOpField selectAll; rc = buildOrderBy( elem, pSelect->_orderby, pTable, pCLName ); PD_RC_CHECK( rc, PDERROR, "failed to build \"sort\" field(rc=%d)", rc ); selectAll.type = SQL_GRAMMAR::WILDCARD; pSelect->_selector.push_back( selectAll ); pSelect->_limit = -1; pSelect->_skip = 0; pSelect->_type = QGM_OPTI_TYPE_SELECT; pSelect->_hasFunc = FALSE; rc = pTable->getOwnField( AGGR_CL_DEFAULT_ALIAS, pSelect->_alias ); PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", AGGR_CL_DEFAULT_ALIAS ); if ( pCLName != NULL ) { qgmField clValAttr; qgmField clValRelegation; rc = pTable->getOwnField( pCLName, clValAttr ); PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", pCLName ); rc = pTable->getOwnField( AGGR_CL_DEFAULT_ALIAS, pSelect->_collection.alias ); PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", AGGR_CL_DEFAULT_ALIAS ); pSelect->_collection.value = qgmDbAttr( clValRelegation, clValAttr ); pSelect->_collection.type = SQL_GRAMMAR::DBATTR; } } catch ( std::exception &e ) { PD_CHECK( SDB_INVALIDARG, SDB_INVALIDARG, error, PDERROR, "failed to parse the \"sort\", received unexpected error:%s", e.what() ); } pNode = pSelect; done: return rc; error: SAFE_OSS_DELETE( pSelect ); goto done; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_SE_NEWSCOPE, "ScriptEngine::newScope" ) Scope *ScriptEngine::newScope() { PD_TRACE_ENTRY ( SDB_SE_NEWSCOPE ); Scope *scope = SDB_OSS_NEW Scope ; VERIFY( scope ); VERIFY( scope->init() ); done : PD_TRACE_EXIT ( SDB_SE_NEWSCOPE ); return scope ; error : SAFE_OSS_DELETE( scope ); scope = NULL ; goto done ; }
void sdbDataSource::_clearDataSource() { list<sdbclient::sdb*>::const_iterator iter ; sdbclient::sdb* conn = NULL ; for ( iter = _idleList.begin() ; iter != _idleList.end() ; ++iter ) { conn = *iter ; if ( conn ) { conn->disconnect() ; SAFE_OSS_DELETE( conn ) ; } } _idleList.clear() ; _idleSize.init( 0 ) ; for ( iter = _busyList.begin() ; iter != _busyList.end() ; ++iter ) { conn = *iter ; if ( conn ) { conn->disconnect() ; SAFE_OSS_DELETE( conn) ; } } _busyList.clear() ; _busySize.init( 0 ) ; for ( iter = _destroyList.begin() ; iter != _destroyList.end() ; ++iter ) { conn = *iter ; if (conn) { conn->disconnect() ; SAFE_OSS_DELETE( conn ) ; } } _destroyList.clear() ; if ( _createConnWorker ) { SAFE_OSS_DELETE( _createConnWorker ) ; } if ( _destroyConnWorker ) { SAFE_OSS_DELETE( _destroyConnWorker ) ; } if ( _bgTaskWorker ) { SAFE_OSS_DELETE( _bgTaskWorker ) ; } }
_rtnContextMain::~_rtnContextMain() { pmdKRCB* pKrcb = pmdGetKRCB() ; SDB_RTNCB* rtnCB = pKrcb->getRTNCB() ; pmdEDUCB* eduCB = pKrcb->getEDUMgr()->getEDUByID( eduID() ) ; SUB_ORDERED_CTX_MAP::iterator orderIter = _orderedContextMap.begin() ; while ( orderIter != _orderedContextMap.end() ) { rtnCB->contextDelete( orderIter->second->contextID(), eduCB ) ; SDB_OSS_DEL orderIter->second ; ++orderIter ; } _orderedContextMap.clear() ; SAFE_OSS_DELETE( _keyGen ) ; }
INT32 sdbDataSource::init( const std::vector<string> &vUrls, const sdbDataSourceConf &conf ) { INT32 rc = SDB_OK ; int validUrlCnt = 0 ; if ( TRUE == _isInited ) { goto done ; } _conf = conf ; if ( !_conf.isValid() ) { rc = SDB_INVALIDARG ; goto error ; } rc = _buildStrategy(); if ( SDB_OK != rc ) { SAFE_OSS_DELETE(_strategy) ; goto error ; } for ( UINT32 i = 0 ; i < vUrls.size() ; ++i ) { if ( _checkAddrArg( vUrls[i] ) ) { _strategy->addCoord( vUrls[i] ) ; validUrlCnt++ ; } } if ( 0 == validUrlCnt ) { rc = SDB_INVALIDARG ; goto error ; } _isInited = TRUE ; done : return rc ; error : goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_SE_GLBSE, "ScriptEngine::globalScriptEngine" ) ScriptEngine * ScriptEngine::globalScriptEngine() { PD_TRACE_ENTRY ( SDB_SE_GLBSE ); if ( ! globalEngine ) { globalEngine = SDB_OSS_NEW ScriptEngine ; VERIFY( globalEngine ); VERIFY( globalEngine->init() ); } done : PD_TRACE_EXIT ( SDB_SE_GLBSE ); return globalEngine ; error : SAFE_OSS_DELETE( globalEngine ); globalEngine = NULL ; goto done ; }
// PD_TRACE_DECLARE_FUNCTION( SDB__QGMCONDITIONNODEHELPER_SEPARATE2, "_qgmConditionNodeHelper::_separate2" ) void _qgmConditionNodeHelper::_separate( _qgmConditionNode *predicate, qgmConditionNodePtrVec &nodes ) { PD_TRACE_ENTRY( SDB__QGMCONDITIONNODEHELPER_SEPARATE2 ) ; SDB_ASSERT( NULL != predicate, "predicate can't be NULL" ) ; if ( SQL_GRAMMAR::AND == predicate->type ) { _separate( predicate->left, nodes ) ; _separate( predicate->right, nodes ) ; predicate->dettach() ; SAFE_OSS_DELETE( predicate ) ; } else if ( predicate ) { nodes.push_back( predicate ) ; } PD_TRACE_EXIT( SDB__QGMCONDITIONNODEHELPER_SEPARATE2 ) ; }
_sptScope* _sptContainer::_createScope( SPT_SCOPE_TYPE type ) { INT32 rc = SDB_OK ; _sptScope *scope = NULL ; if ( SPT_SCOPE_TYPE_SP == type ) { scope = SDB_OSS_NEW _sptSPScope() ; } if ( NULL == scope ) { PD_LOG( PDERROR, "it is a unknown type of scope:%d", type ) ; goto error ; } rc = scope->start() ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "Failed to init scope, rc: %d", rc ) ; goto error ; } rc = _loadObj( scope ) ; if ( rc ) { PD_LOG( PDERROR, "Failed to load objs, rc: %d", rc ) ; goto error ; } done: return scope ; error: SAFE_OSS_DELETE( scope ) ; goto done ; }
///PD_TRACE_DECLARE_FUNCTION ( SDB__MTHSACTIONPARSER__REGISTERPARSERS, "_mthSActionParser::_registerParsers" ) INT32 _mthSActionParser::_registerParsers() { INT32 rc = SDB_OK ; PD_TRACE_ENTRY( SDB__MTHSACTIONPARSER__REGISTERPARSERS ) ; parser *p = NULL ; MTH_ADD_PARSER( _mthIncludeParser ) ; MTH_ADD_PARSER( _mthDefaultParser ) ; MTH_ADD_PARSER( _mthSliceParser ) ; MTH_ADD_PARSER( _mthElemMatchParser ) ; MTH_ADD_PARSER( _mthElemMatchOneParser ) ; done: PD_TRACE_EXITRC( SDB__MTHSACTIONPARSER__REGISTERPARSERS, rc ) ; return rc ; error: SAFE_OSS_DELETE( p ) ; goto done ; }
virtual ~_qgmOptiDelete() { SAFE_OSS_DELETE( _condition ) ; }
void ScriptEngine::purgeGlobalScriptEngine() { SAFE_OSS_DELETE( globalEngine ); globalEngine = NULL ; }
sdbDataSource::~sdbDataSource() { disable() ; SAFE_OSS_DELETE(_strategy) ; }
INT32 sdbDataSource::_createConnByNum( INT32 num ) { INT32 rc = SDB_OK ; INT32 crtNum = 0 ; sdb* conn = NULL ; while( crtNum < num ) { INT32 pos = 0 ; string coord ; rc = _strategy->getNextCoord(coord) ; if ( SDB_OK != rc ) { INT32 cnt = _retrieveAddrFromAbnormalList() ; if ( 0 == cnt ) { break ; } else { continue ; } } conn = new(std::nothrow) sdb( _conf.getUseSSL() ) ; if ( NULL == conn ) { break ; } pos = coord.find_first_of( ":" ) ; rc = conn->connect( coord.substr(0, pos).c_str(), coord.substr(pos+1, coord.length()).c_str(), _conf.getUserName().c_str(), _conf.getPasswd().c_str() ) ; if ( SDB_OK == rc ) { if ( _addNewConnSafely(conn, coord) ) { ++crtNum ; } else { conn->disconnect(); SAFE_OSS_DELETE( conn ) ; break ; } continue ; } // connect success else { INT32 retryTime = 0 ; BOOLEAN toBreak = FALSE ; while ( retryTime < SDB_DS_CREATECONN_RETRYTIME ) { rc = conn->connect( coord.substr( 0, pos ).c_str(), coord.substr( pos+1, coord.length() ).c_str(), _conf.getUserName().c_str(), _conf.getPasswd().c_str() ) ; if ( SDB_OK != rc ) { ++retryTime ; ossSleep( SDB_DS_SLEEP_TIME ) ; // TODO: (new) why we need to continue ; } // retry failed else { if ( _addNewConnSafely(conn, coord) ) { ++crtNum ; } else { conn->disconnect(); SAFE_OSS_DELETE( conn ) ; toBreak = TRUE ; } break ; } // retry success } // while for retry if ( retryTime == SDB_DS_CREATECONN_RETRYTIME ) { SAFE_OSS_DELETE( conn ) ; _strategy->mvCoordToAbnormal( coord ) ; } if ( toBreak ) { break; } } // connect failed } // while return crtNum ; }
_qgmPlNLJoin::~_qgmPlNLJoin() { SAFE_OSS_DELETE( _innerF ) ; }
_qgmOptiNLJoin::~_qgmOptiNLJoin() { SAFE_OSS_DELETE( _condition ) ; }
~_qgmOpStream() { SAFE_OSS_DELETE( next ) ; }
void sdbDataSource::releaseConnection( sdb *conn ) { BOOLEAN isLock = FALSE ; INT32 rc = SDB_OK ; sdb* tmp = NULL ; if ( _isEnabled ) { list<sdb*>::iterator iter ; _connMutex.get() ; isLock = TRUE ; if ( _isEnabled ) { iter = std::find( _busyList.begin(), _busyList.end(), conn ) ; if ( iter != _busyList.end() ) { tmp = *iter ; _busyList.erase( iter ) ; _busySize.dec() ; if ( _conf.getKeepAliveTimeout() > 0 && _keepAliveTimeOut( tmp ) ) { goto error ; } else { bson::BSONObj obj ; obj = BSON( "PreferedInstance" << "A" ) ; rc = tmp->setSessionAttr( obj ) ; if ( SDB_OK != rc ) { goto error ; } rc = tmp->closeAllCursors() ; if ( SDB_OK != rc ) { goto error ; } _idleList.push_back( tmp ) ; _idleSize.inc() ; _strategy->sync( tmp, ADDIDLECONN ) ; } } } // secondly check _isEnabled } // firstly check _isEnabled done : if ( TRUE == isLock ) { _connMutex.release() ; } return ; error : _strategy->sync( tmp, DELBUSYCONN ) ; if ( tmp ) { tmp->disconnect() ; } SAFE_OSS_DELETE( tmp ) ; goto done ; }
INT32 aggrProjectParser::buildNode( const BSONElement &elem, const CHAR *pCLName, qgmOptiTreeNode *&pNode, _qgmPtrTable *pTable, _qgmParamTable *pParamTable ) { INT32 rc = SDB_OK; BOOLEAN hasFunc = FALSE; BSONObj obj; qgmOptiSelect *pSelect = SDB_OSS_NEW qgmOptiSelect( pTable, pParamTable ); PD_CHECK( pSelect!=NULL, SDB_OOM, error, PDERROR, "malloc failed" ); PD_CHECK( elem.type() == Object, SDB_INVALIDARG, error, PDERROR, "failed to parse the parameter:%s(type=%d, expectType=%d)", elem.fieldName(), elem.type(), Object ); try { obj = elem.embeddedObject(); { PD_CHECK( !obj.isEmpty(), SDB_INVALIDARG, error, PDERROR, "Parameter-object can't be empty!" ); } BSONObjIterator iter( obj ); while ( iter.more() ) { BSONElement beField = iter.next(); const CHAR *pFieldName = beField.fieldName(); PD_CHECK( pFieldName[0] != AGGR_KEYWORD_PREFIX, SDB_INVALIDARG, error, PDERROR, "failed to parse \"project\", field name can't begin with\"$\"!" ); rc = parseSelectorField( beField, pCLName, pSelect->_selector, pTable, hasFunc ); PD_RC_CHECK( rc, PDERROR, "failed to parse the field:%s", pFieldName ); } if ( pSelect->_selector.empty() ) { qgmOpField selectAll; selectAll.type = SQL_GRAMMAR::WILDCARD; pSelect->_selector.push_back( selectAll ); } } catch ( std::exception &e ) { PD_CHECK( SDB_INVALIDARG, SDB_INVALIDARG, error, PDERROR, "failed to parse the Parameter-object, received unexpected error:%s", e.what() ); } pSelect->_limit = -1; pSelect->_skip = 0; pSelect->_type = QGM_OPTI_TYPE_SELECT; pSelect->_hasFunc = hasFunc; rc = pTable->getOwnField( AGGR_CL_DEFAULT_ALIAS, pSelect->_alias ); PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", AGGR_CL_DEFAULT_ALIAS ); if ( pCLName != NULL ) { qgmField clValAttr; qgmField clValRelegation; rc = pTable->getOwnField( pCLName, clValAttr ); PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", pCLName ); rc = pTable->getOwnField( AGGR_CL_DEFAULT_ALIAS, pSelect->_collection.alias ); PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", AGGR_CL_DEFAULT_ALIAS ); pSelect->_collection.value = qgmDbAttr( clValRelegation, clValAttr ); pSelect->_collection.type = SQL_GRAMMAR::DBATTR; } pNode = pSelect; done: return rc; error: SAFE_OSS_DELETE( pSelect ); goto done; }
sdbDSWorker::~sdbDSWorker() { if (_managed) SAFE_OSS_DELETE( _thread.args ) ; }