INT32 _pmdController::loadForeignModule() { INT32 rc = SDB_OK ; const CHAR *MONGO_MODULE_NAME = "fapmongo" ; const CHAR *MONGO_MODULE_PATH = "./bin/fap/" ; _fapMongo = SDB_OSS_NEW pmdModuleLoader() ; if ( NULL == _fapMongo ) { PD_LOG( PDERROR, "Failed to alloc foreign access protocol module" ) ; rc = SDB_OOM ; goto error ; } rc = _fapMongo->load( MONGO_MODULE_NAME, MONGO_MODULE_PATH ) ; PD_RC_CHECK( rc, PDERROR, "Failed to load module: %s, path: %s" " rc: %d", MONGO_MODULE_NAME, MONGO_MODULE_PATH, rc ) ; rc = _fapMongo->create( _protocol ) ; PD_RC_CHECK( rc, PDERROR, "Failed to create protocol service" ) ; rc = _protocol->init( pmdGetKRCB() ) ; PD_RC_CHECK( rc, PDERROR, "Failed to init protocol" ) ; done: return rc ; error: goto done ; }
INT32 rtnCoord2PhaseCommit::doPhase2( CHAR * pReceiveBuffer, SINT32 packSize, CHAR * * ppResultBuffer, pmdEDUCB * cb, MsgOpReply & replyHeader ) { INT32 rc = SDB_OK; pmdKRCB *pKrcb = pmdGetKRCB(); CoordCB *pCoordcb = pKrcb->getCoordCB(); netMultiRouteAgent *pRouteAgent = pCoordcb->getRouteAgent(); CHAR *pMsgReq = NULL; MsgHeader *pMsgHead = NULL; CoordGroupList groupLst; CoordGroupList sendGroupLst; rc = buildPhase2Msg( pReceiveBuffer, &pMsgReq ); PD_RC_CHECK( rc, PDERROR, "failed to build the message on phase1(rc=%d)", rc ); pMsgHead = (MsgHeader *)pMsgReq; pMsgHead->TID = cb->getTID(); rc = executeOnDataGroup( pMsgReq, pRouteAgent, cb ); PD_RC_CHECK( rc, PDERROR, "failed to execute on data-group on phase1(rc=%d)", rc ); done: if ( pMsgReq ) { SDB_OSS_FREE( pMsgReq ); pMsgReq = NULL; } return rc; error: goto done; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__SDB_DMSCB_DISPATCHPAGECLEANSU, "_SDB_DMSCB::dispatchPageCleanSU" ) _dmsStorageUnit *_SDB_DMSCB::dispatchPageCleanSU ( dmsStorageUnitID *suID ) { PD_TRACE_ENTRY ( SDB__SDB_DMSCB_DISPATCHPAGECLEANSU ) ; *suID = DMS_INVALID_SUID ; pmdOptionsCB *optCB = pmdGetOptionCB() ; _dmsStorageUnit *su = NULL ; SDB_ASSERT ( suID, "suID can't be NULL" ) ; _pageCleanHistory firstSU ; ossTickDelta deltaTime ; ossScopedLock _lock(&_mutex, EXCLUSIVE) ; if ( _pageCleanHistoryList.size() == 0 ) goto done ; firstSU = _pageCleanHistoryList.front() ; deltaTime = pmdGetKRCB()->getCurTime () - firstSU.first ; if ( deltaTime.toUINT64() / 1000 > (UINT64)optCB->getPageCleanInterval() ) { PD_TRACE1 ( SDB__SDB_DMSCB_DISPATCHPAGECLEANSU, PD_PACK_ULONG ( firstSU.second ) ) ; if ( NULL != _cscbVec[firstSU.second] ) { *suID = firstSU.second ; _latchVec[*suID]->lock_r() ; su = _cscbVec[*suID]->_su ; } _pageCleanHistorySet.erase ( firstSU.second ) ; _pageCleanHistoryList.pop_front () ; } done : PD_TRACE_EXIT ( SDB__SDB_DMSCB_DISPATCHPAGECLEANSU ) ; return su ; }
INT32 _rtnCoordSql::execute( MsgHeader *pMsg, pmdEDUCB *cb, INT64 &contextID, rtnContextBuf *buf ) { INT32 rc = SDB_OK ; SQL_CB *sqlcb = pmdGetKRCB()->getSqlCB() ; CHAR *sql = NULL ; contextID = -1 ; rc = msgExtractSql( (CHAR*)pMsg, &sql ) ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to extract sql" ) ; rc = SDB_SYS ; goto error ; } // add last op info MON_SAVE_OP_DETAIL( cb->getMonAppCB(), pMsg->opCode, "%s", sql ) ; rc = sqlcb->exec( sql, cb, contextID ) ; done: return rc ; error: goto done ; }
INT32 _pmdController::activeForeignModule() { INT32 rc = SDB_OK ; pmdEDUParam *pProtocolData = NULL ; pmdEDUMgr *pEDUMgr = pmdGetKRCB()->getEDUMgr() ; EDUID eduID = PMD_INVALID_EDUID ; if ( NULL == _fapMongo ) { goto done ; } // listener for access protocol pProtocolData = new pmdEDUParam() ; pProtocolData->pSocket = (void *)_pMongoListener ; pProtocolData->protocol = _protocol ; rc = pEDUMgr->startEDU( EDU_TYPE_FAPLISTENER, (void*)pProtocolData, &eduID ) ; PD_RC_CHECK( rc, PDERROR, "Failed to start FAP listerner, rc: %d", rc ) ; pEDUMgr->regSystemEDU( EDU_TYPE_FAPLISTENER, eduID ) ; // wait until protocol listener starts rc = pEDUMgr->waitUntil ( eduID, PMD_EDU_RUNNING ) ; PD_RC_CHECK( rc, PDERROR, "Wait FAP Listener active failed, rc: %d", rc ) ; done: return rc ; error: goto done ; }
INT32 rtnCoordTransCommit::execute( CHAR * pReceiveBuffer, SINT32 packSize, CHAR * * ppResultBuffer, pmdEDUCB * cb, MsgOpReply & replyHeader, BSONObj **ppErrorObj ) { INT32 rc = SDB_OK; rtnCoordOperator *pRollbackOperator = NULL; rc = rtnCoord2PhaseCommit::execute( pReceiveBuffer, packSize, ppResultBuffer, cb, replyHeader, ppErrorObj ); SDB_ASSERT( NULL == *ppErrorObj, "impossible" ) ; PD_RC_CHECK( rc, PDERROR, "failed to commit the transaction(rc=%d)", rc ); cb->delTransaction(); done: return rc; error: pRollbackOperator = pmdGetKRCB()->getCoordCB()->getProcesserFactory( )->getOperator( MSG_BS_TRANS_ROLLBACK_REQ ); if ( pRollbackOperator ) { pRollbackOperator->execute( pReceiveBuffer, packSize, ppResultBuffer, cb, replyHeader, ppErrorObj ); SDB_ASSERT( NULL == *ppErrorObj, "impossible" ) ; } goto done; }
INT32 _coordOmOperatorBase::queryOnOmAndPushToVec( const rtnQueryOptions &options, pmdEDUCB *cb, vector< BSONObj > &objs, rtnContextBuf *buf ) { INT32 rc = SDB_OK ; SINT64 contextID = -1 ; rtnContextBuf bufObj ; SDB_RTNCB *rtnCB = pmdGetKRCB()->getRTNCB() ; rc = queryOnOm( options, cb, contextID, buf ) ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "Failed to query on om: %d", rc ) ; goto error ; } do { rc = rtnGetMore( contextID, -1, bufObj, cb, rtnCB ) ; if ( SDB_DMS_EOC == rc ) { rc = SDB_OK ; contextID = -1 ; break ; } else if ( SDB_OK != rc ) { contextID = -1 ; PD_LOG( PDERROR, "Failed to getmore from context, rc: %d", rc ) ; goto error ; } else { while ( !bufObj.eof() ) { BSONObj obj ; rc = bufObj.nextObj( obj ) ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "Failed to get obj from obj buf, rc: %d", rc ) ; goto error ; } objs.push_back( obj.getOwned() ) ; } } } while( TRUE ) ; done: if ( -1 != contextID ) { rtnCB->contextDelete( contextID, cb ) ; } return rc ; error: goto done ; }
void _monAppCB::startOperator() { _lastOpBeginTime = pmdGetKRCB()->getCurTime() ; _lastOpEndTime.clear() ; _lastOpType = MSG_NULL ; _cmdType = CMD_UNKNOW ; ossMemset( _lastOpDetail, 0, sizeof(_lastOpDetail) ) ; }
INT32 rtnCoordTransRollback::execute( CHAR * pReceiveBuffer, SINT32 packSize, CHAR * * ppResultBuffer, pmdEDUCB * cb, MsgOpReply & replyHeader, BSONObj **ppErrorObj ) { INT32 rc = SDB_OK; CHAR *pMsgReq = NULL; MsgHeader *pMsgHead = NULL; INT32 bufferSize = 0; pmdKRCB *pKrcb = pmdGetKRCB(); CoordCB *pCoordcb = pKrcb->getCoordCB(); netMultiRouteAgent *pRouteAgent = pCoordcb->getRouteAgent(); MsgHeader *pHeader = (MsgHeader *)pReceiveBuffer; replyHeader.header.messageLength = sizeof( MsgOpReply ); replyHeader.header.opCode = MSG_BS_TRANS_ROLLBACK_RSP; replyHeader.header.routeID.value = 0; replyHeader.contextID = -1; replyHeader.flags = SDB_OK; replyHeader.numReturned = 0; replyHeader.startFrom = 0; if ( pHeader ) { replyHeader.header.requestID = pHeader->requestID; replyHeader.header.TID = pHeader->TID; } if ( !cb->isTransaction() ) { rc = SDB_DPS_TRANS_NO_TRANS; goto error; } cb->startRollback(); rc = msgBuildTransRollbackMsg( &pMsgReq, &bufferSize ); PD_RC_CHECK( rc, PDERROR, "failed to build the message(rc=%d)", rc ); pMsgHead = (MsgHeader *)pMsgReq; pMsgHead->TID = cb->getTID(); rc = executeOnDataGroup( pMsgReq, pRouteAgent, cb ); cb->delTransaction(); PD_RC_CHECK( rc, PDERROR, "failed to rollback(rc=%d)", rc ); done: if ( pMsgReq ) { SDB_OSS_FREE( pMsgReq ); } cb->stopRollback(); return rc; error: replyHeader.flags = rc; goto done; }
// PD_TRACE_DECLARE_FUNCTION( SDB__QGMPLDELETE__EXEC, "_qgmPlDelete::_execute" ) INT32 _qgmPlDelete::_execute( _pmdEDUCB *eduCB ) { PD_TRACE_ENTRY( SDB__QGMPLDELETE__EXEC ) ; INT32 rc = SDB_OK ; _SDB_KRCB *krcb = pmdGetKRCB() ; SDB_ROLE role = krcb->getDBRole() ; CHAR *msg = NULL ; if ( SDB_ROLE_COORD == role ) { INT32 bufSize = 0 ; MsgOpReply dummyReply ; rtnCoordDelete del ; rc = msgBuildDeleteMsg( &msg, &bufSize, _collection.toString().c_str(), 0, 0, _condition.isEmpty()? NULL : &_condition ) ; if ( SDB_OK != rc ) { goto error ; } rc = del.execute( msg, *((SINT32 *)msg), eduCB, dummyReply, NULL ) ; } else { SDB_DPSCB *dpsCB = krcb->getDPSCB() ; if ( dpsCB && eduCB->isFromLocal() && !dpsCB->isLogLocal() ) { dpsCB = NULL ; } SDB_DMSCB *dmsCB = krcb->getDMSCB() ; BSONObj empty ; rc = rtnDelete( _collection.toString().c_str(), _condition, empty, 0, eduCB, dmsCB, dpsCB ) ; } if ( SDB_OK != rc ) { goto error ; } done: if ( NULL != msg ) { SDB_OSS_FREE( msg ) ; msg = NULL ; } PD_TRACE_EXITRC( SDB__QGMPLDELETE__EXEC, rc ) ; return rc ; error: goto done ; }
void _monAppCB::endOperator() { if ( (BOOLEAN)_lastOpBeginTime ) { _lastOpEndTime = pmdGetKRCB()->getCurTime() ; ossTickDelta delta = _lastOpEndTime - _lastOpBeginTime ; opTimeSpentInc( delta ) ; } }
void _qgmPlCommand::_killContext() { if ( -1 != _contextID ) { SDB_RTNCB *rtnCB = pmdGetKRCB()->getRTNCB() ; rtnKillContexts( 1, &_contextID, _eduCB, rtnCB ) ; _contextID = -1 ; } return ; }
void _pmdCoordProcessor::_onDetach() { pmdDataProcessor::_onDetach() ; _CoordCB *pCoordCB = pmdGetKRCB()->getCoordCB() ; if ( eduCB() && pCoordCB ) { netMultiRouteAgent *pRouteAgent = pCoordCB->getRouteAgent() ; pRouteAgent->delSession( eduCB()->getTID() ) ; } }
// PD_TRACE_DECLARE_FUNCTION ( SDB__CLSREPSET_INIT, "_clsReplicateSet::initialize" ) INT32 _clsReplicateSet::initialize () { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__CLSREPSET_INIT ) ; if ( !_agent ) { rc = SDB_INVALIDARG ; goto error ; } g_startShiftTime = (INT32)pmdGetOptionCB()->startShiftTime() ; _logger = pmdGetKRCB()->getDPSCB() ; _clsCB = pmdGetKRCB()->getClsCB() ; SDB_ASSERT( NULL != _logger, "logger should not be NULL" ) ; _logger->regEventHandler( this ) ; rc = _replBucket.init() ; PD_RC_CHECK( rc, PDERROR, "Init repl bucket failed, rc: %d", rc ) ; _totalLogSize = (UINT64)pmdGetOptionCB()->getReplLogFileSz()* (UINT64)pmdGetOptionCB()->getReplLogFileNum() ; { UINT32 rate = 2 ; UINT32 timeBase = CLS_SYNCCTRL_BASE_TIME ; for ( UINT32 idx = 0 ; idx < CLS_SYNCCTRL_THRESHOLD_SIZE ; ++idx ) { rate = 2 << idx ; _sizethreshold[ idx ] = _totalLogSize * ( rate - 1 ) / rate ; _timeThreshold[ idx ] = timeBase << idx ; } } done: PD_TRACE_EXITRC ( SDB__CLSREPSET_INIT, rc ); return rc ; error: goto done ; }
INT32 _CoordCB::init () { INT32 rc = SDB_OK ; CoordGroupInfo *pGroupInfo = NULL ; UINT32 catGID = CATALOG_GROUPID ; UINT16 catNID = SYS_NODE_ID_BEGIN + CLS_REPLSET_MAX_NODE_SIZE ; MsgRouteID id ; pmdOptionsCB *optCB = pmdGetOptionCB() ; vector< _pmdAddrPair > catAddrs = optCB->catAddrs() ; _pNetWork = SDB_OSS_NEW _netRouteAgent( &_multiRouteAgent ) ; if ( !_pNetWork ) { PD_LOG( PDERROR, "Failed to alloc memory for net agent" ) ; rc = SDB_OOM ; goto error ; } _multiRouteAgent.setNetWork( _pNetWork ) ; pGroupInfo = SDB_OSS_NEW CoordGroupInfo( CAT_CATALOG_GROUPID ) ; if ( !pGroupInfo ) { PD_LOG( PDERROR, "Failed to alloc memory for group info" ) ; rc = SDB_OOM ; goto error ; } _catGroupInfo = CoordGroupInfoPtr( pGroupInfo ) ; for ( UINT32 i = 0 ; i < catAddrs.size() ; ++i ) { if ( 0 == catAddrs[i]._host[ 0 ] ) { break ; } id.columns.groupID = catGID ; id.columns.nodeID = catNID++ ; id.columns.serviceID = MSG_ROUTE_CAT_SERVICE ; addCatNodeAddr( id, catAddrs[i]._host, catAddrs[i]._service ) ; } pmdGetStartup().ok( TRUE ) ; pmdGetKRCB()->setGroupName( COORD_GROUPNAME ) ; { MsgRouteID id ; id.value = MSG_INVALID_ROUTEID ; id.columns.groupID = COORD_GROUPID ; pmdSetNodeID( id ) ; } done: return rc ; error: goto done ; }
void _pmdEDUCB::clearTransInfo() { _curTransID = DPS_INVALID_TRANS_ID ; _relatedTransLSN = DPS_INVALID_LSN_OFFSET ; _curTransLSN = DPS_INVALID_LSN_OFFSET ; dpsTransCB *pTransCB = pmdGetKRCB()->getTransCB(); if ( pTransCB ) { pTransCB->transLockReleaseAll( this ); } }
// PD_TRACE_DECLARE_FUNCTION ( SDB__CLSCATCLR_HNDTMOUT, "_clsCatalogCaller::handleTimeout" ) void _clsCatalogCaller::handleTimeout( const UINT32 &millisec ) { PD_TRACE_ENTRY ( SDB__CLSCATCLR_HNDTMOUT ); callerMeta::iterator itr = _meta.begin() ; for ( ; itr != _meta.end(); itr++ ) { if ( CLS_CALLER_NO_SEND != itr->second.timeout ) { itr->second.timeout += millisec ; if ( CLS_CALLER_INTERVAL <= itr->second.timeout ) { pmdGetKRCB()->getClsCB()->updateCatGroup ( TRUE ) ; pmdGetKRCB()->getClsCB()->sendToCatlog( itr->second.header) ; itr->second.timeout = 0 ; } } } PD_TRACE_EXIT ( SDB__CLSCATCLR_HNDTMOUT ); return ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_PMDBGJOBENTPNT, "pmdBackgroundJobEntryPoint" ) INT32 pmdBackgroundJobEntryPoint( pmdEDUCB *cb, void *pData ) { SDB_ASSERT( NULL != pData, "impossible" ) ; PD_TRACE_ENTRY ( SDB_PMDBGJOBENTPNT ); rtnJobMgr *jobMgr = rtnGetJobMgr () ; pmdEDUMgr *pEDUMgr = pmdGetKRCB()->getEDUMgr() ; rtnBaseJob *job = (rtnBaseJob*)pData ; INT32 rc = SDB_OK ; BOOLEAN reuseEDU = job->reuseEDU() ; string expStr ; PD_LOG( PDINFO, "Start a background job[%s]", job->name() ) ; cb->setName( job->name() ) ; job->attachIn( cb ) ; try { pEDUMgr->activateEDU( cb ) ; rc = job->doit () ; if ( SDB_OK != rc ) { PD_LOG ( PDWARNING, "Background job[%s] do failed, rc = %d", job->name(), rc ) ; } else { PD_LOG ( PDINFO, "Background job[%s] finished", job->name() ) ; } } catch( std::exception &e ) { PD_LOG( PDERROR, "Occur exception: %s", e.what() ) ; rc = SDB_SYS ; expStr = e.what() ; } job->attachOut () ; jobMgr->_removeJob ( cb->getID(), rc ) ; if ( !reuseEDU ) { pEDUMgr->forceUserEDU( cb->getID() ) ; } if ( !expStr.empty() ) { throw pdGeneralException( rc, expStr ) ; } PD_TRACE_EXITRC ( SDB_PMDBGJOBENTPNT, rc ); return SDB_OK ; }
_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 ) ; }
/* _coordOmStrategyAccessor implement */ _coordOmStrategyAccessor::_coordOmStrategyAccessor( INT64 timeout ) { pmdKRCB *krcb = pmdGetKRCB() ; CoordCB *pCoord = krcb->getCoordCB() ; pmdOptionsCB *optionsCB = krcb->getOptionCB() ; _pOmProxy = pCoord->getResource()->getOmProxy() ; _oprTimeout = timeout ; optionsCB->getFieldStr( PMD_OPTION_CLUSTER_NAME, _clsName, "" ) ; optionsCB->getFieldStr( PMD_OPTION_BUSINESS_NAME, _bizName, "" ) ; }
INT32 catSplitCheckConflict( BSONObj & match, clsSplitTask & splitTask, BOOLEAN & conflict, pmdEDUCB * cb ) { INT32 rc = SDB_OK ; pmdKRCB *krcb = pmdGetKRCB() ; SDB_DMSCB *dmsCB = krcb->getDMSCB() ; SDB_RTNCB *rtnCB = krcb->getRTNCB() ; BSONObj dummyObj ; INT64 contextID = -1 ; rtnContextBuf buffObj ; INT64 startPos = 0 ; rc = rtnQuery( CAT_TASK_INFO_COLLECTION, dummyObj, match, dummyObj, dummyObj, 0, cb, 0, -1, dmsCB, rtnCB, contextID ) ; PD_RC_CHECK ( rc, PDERROR, "Failed to perform query, rc = %d", rc ) ; while ( SDB_OK == rc ) { rc = rtnGetMore( contextID, -1, buffObj, startPos, cb, rtnCB ) ; if ( rc ) { if ( SDB_DMS_EOC == rc ) { contextID = -1 ; rc = SDB_OK ; break ; } PD_LOG( PDERROR, "Failed to retreive record, rc = %d", rc ) ; goto error ; } rc = _checkSplitTaskConflict( &buffObj, conflict, &splitTask ) ; PD_RC_CHECK( rc, PDERROR, "Check split task conflict error, rc: %d", rc ) ; if ( conflict ) { break ; } } done: if ( -1 != contextID ) { rtnCB->contextDelete ( contextID, cb ) ; } return rc ; return rc ; error: goto done ; }
void _dpsLogWrapper::regEventHandler( dpsEventHandler *pHandler ) { SDB_ASSERT( pHandler, "Handle can't be NULL" ) ; SDB_ASSERT( FALSE == pmdGetKRCB()->isActive(), "Can't register handle when pmd actived" ) ; for ( UINT32 i = 0 ; i < _vecEventHandler.size() ; ++i ) { SDB_ASSERT( pHandler != _vecEventHandler[ i ], "Handle can't be same" ) ; } _vecEventHandler.push_back( pHandler ) ; _buf.regEventHandler( pHandler ) ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__DPSLGWRAPP_ACTIVE, "_dpsLogWrapper::active" ) INT32 _dpsLogWrapper::active () { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__DPSLGWRAPP_ACTIVE ) ; pmdEDUMgr *pEDUMgr = pmdGetKRCB()->getEDUMgr() ; EDUID eduID = PMD_INVALID_EDUID ; rc = pEDUMgr->startEDU( EDU_TYPE_LOGGW, (void*)this, &eduID ) ; if ( rc ) { PD_LOG( PDERROR, "Start dps log writer failed, rc: %d", rc ) ; goto error ; } rc = pEDUMgr->startEDU( EDU_TYPE_DPSROLLBACK, NULL, &eduID ) ; if ( rc ) { PD_LOG( PDERROR, "Start dps trans rollback failed, rc: %d", rc ) ; goto error ; } if ( pmdGetKRCB()->getOptionCB()->archiveOn() ) { rc = pEDUMgr->startEDU( EDU_TYPE_LOGARCHIVEMGR, (void*)this, &eduID ) ; if ( rc ) { PD_LOG( PDERROR, "Start dps log archiving failed, rc: %d", rc ) ; goto error ; } } done: PD_TRACE_EXITRC( SDB__DPSLGWRAPP_ACTIVE, rc ) ; return rc ; error: goto done ; }
INT32 _pmdController::active () { INT32 rc = SDB_OK ; pmdEDUParam *pProtocolData = NULL ; pmdEDUMgr *pEDUMgr = pmdGetKRCB()->getEDUMgr() ; EDUID eduID = PMD_INVALID_EDUID ; rc = _restAdptor.init( _fixBufSize, _maxRestBodySize, _restTimeout ) ; PD_RC_CHECK( rc, PDERROR, "Failed to init rest adaptor, rc: %d", rc ) ; rc = pEDUMgr->startEDU( EDU_TYPE_SYNCCLOCK, NULL, &eduID ) ; pEDUMgr->regSystemEDU( EDU_TYPE_SYNCCLOCK, eduID ) ; rc = pEDUMgr->startEDU( EDU_TYPE_TCPLISTENER, (void*)_pTcpListener, &eduID ) ; PD_RC_CHECK( rc, PDERROR, "Failed to start tcp listerner, rc: %d", rc ) ; pEDUMgr->regSystemEDU( EDU_TYPE_TCPLISTENER, eduID ) ; rc = pEDUMgr->waitUntil ( eduID, PMD_EDU_RUNNING ) ; PD_RC_CHECK( rc, PDERROR, "Wait Tcp Listerner active failed, rc: %d", rc ) ; rc = pEDUMgr->startEDU( EDU_TYPE_RESTLISTENER, (void*)_pHttpListener, &eduID ) ; PD_RC_CHECK( rc, PDERROR, "Failed to start rest listerner, rc: %d", rc ) ; pEDUMgr->regSystemEDU( EDU_TYPE_RESTLISTENER, eduID ) ; rc = pEDUMgr->waitUntil ( eduID, PMD_EDU_RUNNING ) ; PD_RC_CHECK( rc, PDERROR, "Wait rest Listener active failed, rc: %d", rc ) ; if ( SDB_ROLE_COORD != pmdGetDBRole() ) { UINT32 pageTaskNum = pmdGetOptionCB()->getPageCleanNum() ; UINT32 pageIntervel = pmdGetOptionCB()->getPageCleanInterval() ; for ( UINT32 i = 0; i < pageTaskNum ; ++i ) { startPageCleanerJob( NULL, (INT32)pageIntervel ) ; } rtnStartLoadJob() ; } done: return rc ; error: goto done ; }
INT32 sdbCatalogueCB::active () { INT32 rc = SDB_OK ; pmdEDUMgr *pEDUMgr = pmdGetKRCB()->getEDUMgr() ; EDUID eduID = PMD_INVALID_EDUID ; _catMainCtrl.getAttachEvent()->reset() ; rc = pEDUMgr->startEDU ( EDU_TYPE_CATMAINCONTROLLER, (_pmdObjBase*)getMainController(), &eduID ) ; PD_RC_CHECK( rc, PDERROR, "Failed to start cat main controller edu, " "rc: %d", rc ) ; pEDUMgr->regSystemEDU( EDU_TYPE_CATMAINCONTROLLER, eduID ) ; rc = _catMainCtrl.getAttachEvent()->wait( CAT_WAIT_EDU_ATTACH_TIMEOUT ) ; PD_RC_CHECK( rc, PDERROR, "Failed to wait cat main contoller edu " "attach, rc: %d", rc ) ; _catMainCtrl.getAttachEvent()->reset() ; rc = pEDUMgr->startEDU ( EDU_TYPE_CATCATALOGUEMANAGER, (_pmdObjBase*)getCatlogueMgr(), &eduID ) ; PD_RC_CHECK( rc, PDERROR, "Failed to start catlogue manager edu, " "rc: %d", rc ) ; pEDUMgr->regSystemEDU( EDU_TYPE_CATCATALOGUEMANAGER, eduID ) ; rc = _catMainCtrl.getAttachEvent()->wait( CAT_WAIT_EDU_ATTACH_TIMEOUT ) ; PD_RC_CHECK( rc, PDERROR, "Failed to wait catlogue manager edu " "attach, rc: %d", rc ) ; _catMainCtrl.getAttachEvent()->reset() ; rc = pEDUMgr->startEDU ( EDU_TYPE_CATNODEMANAGER, (_pmdObjBase*)getCatNodeMgr(), &eduID ) ; PD_RC_CHECK( rc, PDERROR, "Failed to start cat node manager edu, " "rc: %d", rc ) ; pEDUMgr->regSystemEDU( EDU_TYPE_CATNODEMANAGER, eduID ) ; rc = _catMainCtrl.getAttachEvent()->wait( CAT_WAIT_EDU_ATTACH_TIMEOUT ) ; PD_RC_CHECK( rc, PDERROR, "Failed to wait cat node manager edu " "attach, rc: %d", rc ) ; pEDUMgr->startEDU ( EDU_TYPE_CATNETWORK, (netRouteAgent*)netWork(), &eduID ) ; pEDUMgr->regSystemEDU ( EDU_TYPE_CATNETWORK, eduID ) ; rc = pEDUMgr->waitUntil( EDU_TYPE_CATNETWORK, PMD_EDU_RUNNING ) ; PD_RC_CHECK( rc, PDERROR, "Wait CATNET active failed, rc: %d", rc ) ; done: return rc ; error: goto done ; }
/* _pmdEDUCB implement */ _pmdEDUCB::_pmdEDUCB( _pmdEDUMgr *mgr, EDU_TYPES type ) : _tid( 0 ), _processEventCount( 0 ), _eduMgr( mgr ), _eduType( type ), _ctrlFlag( 0 ), _writingDB( FALSE ), _writingTime( 0 ), _threadHdl( 0 ), #if defined (_LINUX) _threadID( 0 ), #endif _pClientSock( NULL ) { _Name[0] = 0 ; _pSession = NULL ; _pCompressBuff = NULL ; _compressBuffLen = 0 ; _pUncompressBuff = NULL ; _uncompressBuffLen= 0 ; _totalCatchSize = 0 ; _totalMemSize = 0 ; _isDoRollback = FALSE ; #if defined ( SDB_ENGINE ) _pCoordSession = NULL ; _beginLsn = 0 ; _endLsn = 0 ; _lsnNumber = 0 ; _relatedTransLSN = DPS_INVALID_LSN_OFFSET ; _curTransLSN = DPS_INVALID_LSN_OFFSET ; _curTransID = DPS_INVALID_TRANS_ID ; _pTransNodeMap = NULL ; _transRC = SDB_OK ; _alignedMem = NULL ; _alignedMemSize = 0 ; _curRequestID = 1 ; _dmsLockLevel = 0 ; _monCfgCB = *( (monConfigCB*)(pmdGetKRCB()->getMonCB()) ) ; #endif // SDB_ENGINE _pErrorBuff = (CHAR *)SDB_OSS_MALLOC( EDU_ERROR_BUFF_SIZE + 1 ) ; if ( _pErrorBuff ) { ossMemset( _pErrorBuff, 0, EDU_ERROR_BUFF_SIZE + 1 ) ; } }
// PD_TRACE_DECLARE_FUNCTION ( SDB_COORDSN_CHECKREMOTEROUTEID, "CoordSession::checkRemoteRouteID" ) INT32 CoordSession::checkRemoteRouteID( const MsgRouteID & routeID ) { INT32 rc = SDB_OK; PD_TRACE_ENTRY ( SDB_COORDSN_CHECKREMOTEROUTEID ); netMultiRouteAgent *pRouteAgent = pmdGetKRCB()->getCoordCB()->getRouteAgent(); SDB_ASSERT( _pEduCB, "_pEduCB can't be NULL!" ); MsgCoordCheckRouteID msgReq; msgReq.header.requestID = 0; msgReq.header.messageLength = sizeof( MsgCoordCheckRouteID ); msgReq.header.opCode = MSG_COOR_CHECK_ROUTEID_REQ; msgReq.header.routeID.value = 0; msgReq.header.TID = _pEduCB->getTID(); msgReq.dstRouteID = routeID; REQUESTID_MAP requestIdMap; REPLY_QUE replyQue; rc = rtnCoordSendRequestToNodeWithoutCheck( (void *)(&msgReq), routeID, pRouteAgent, _pEduCB, requestIdMap ); PD_RC_CHECK( rc, PDERROR, "failed to send the message to the node" "(groupID=%u, nodeID=%u, serviceID=%u)", routeID.columns.groupID, routeID.columns.nodeID, routeID.columns.serviceID ); rc = rtnCoordGetReply( _pEduCB, requestIdMap, replyQue, MSG_COOR_CHECK_ROUTEID_RSP ); PD_RC_CHECK( rc, PDERROR, "failed to get reply from node" "(groupID=%u, nodeID=%u, serviceID=%u, rc=%d)", routeID.columns.groupID, routeID.columns.nodeID, routeID.columns.serviceID, rc ); while ( !replyQue.empty() ) { MsgOpReply *pReply = NULL; pReply = (MsgOpReply *)(replyQue.front()); SDB_ASSERT( pReply, "pReply can't be NULL!" ); replyQue.pop(); rc = rc ? rc : pReply->flags; SDB_OSS_FREE( pReply ); } done: PD_TRACE_EXIT ( SDB_COORDSN_CHECKREMOTEROUTEID ); return rc; error: rtnCoordClearRequest( _pEduCB, requestIdMap ); goto done; }
int pmdEDUMgr::returnEDU(EDUID eduID, bool force, bool* destroyed) { int rc = EDB_OK; EDU_TYPES type = EDU_TYPE_UNKNOWN; pmdEDUCB* eduCB = NULL; std::map<EDUID, pmdEDUCB*>::iterator it; _mutex.get_shared(); if (_runQueue.end() == (it = _runQueue.find(eduID))) { if (_idleQueue.end() == (it = _idleQueue.find(eduID))) { rc = EDB_SYS; *destroyed = false; _mutex.release_shared(); goto error; } } eduCB = (*it).second; if (eduCB) { type = eduCB->getType(); } _mutex.release_shared(); if (!isPoolable(type) || force || isDestroyed() || size() > (unsigned int) pmdGetKRCB()->getMaxPool()) { rc = _destroyEDU(eduID); if (destroyed) { if (EDB_OK == rc || EDB_SYS == rc) { *destroyed = true; } else { *destroyed = false; } } } else { rc = _deactivateEDU(eduID); if (destroyed) { if (EDB_SYS == rc) { *destroyed = true; } else { *destroyed = false; } } } done: return rc; error: goto done; }
INT32 rtnCoordAggregate::execute( CHAR *pReceiveBuffer, SINT32 packSize, pmdEDUCB *cb, MsgOpReply &replyHeader, rtnContextBuf *buf ) { INT32 rc = SDB_OK; MsgHeader *pHeader = (MsgHeader *)pReceiveBuffer; CHAR *pCollectionName = NULL; CHAR *pObjs = NULL; INT32 count = 0; BSONObj objs; SINT64 contextID = -1; replyHeader.contextID = -1; replyHeader.flags = SDB_OK; replyHeader.numReturned = 0; replyHeader.startFrom = 0; replyHeader.header.messageLength = sizeof( MsgOpReply ); replyHeader.header.opCode = MSG_BS_AGGREGATE_RSP; replyHeader.header.requestID = pHeader->requestID; replyHeader.header.routeID.value = 0; replyHeader.header.TID = pHeader->TID; rc = msgExtractAggrRequest( pReceiveBuffer, &pCollectionName, &pObjs, count ); PD_RC_CHECK( rc, PDERROR, "failed to parse aggregate request(rc=%d)", rc ); try { objs = BSONObj( pObjs ); } catch ( std::exception &e ) { PD_RC_CHECK( rc, PDERROR, "failed to execute aggregate, received unexpecte error:%s", e.what() ); } rc = pmdGetKRCB()->getAggrCB()->build( objs, count, pCollectionName, cb, contextID ); PD_RC_CHECK( rc, PDERROR, "failed to execute aggregation operation(rc=%d)", rc ); replyHeader.contextID = contextID; done: return rc; error: replyHeader.flags = rc; goto done; }
/* ENTRY POINTER FUNCTIONS */ INT32 pmdSyncClockEntryPoint( pmdEDUCB * cb, void * arg ) { ossTick tmp ; pmdKRCB *pKrcb = pmdGetKRCB() ; pKrcb->getEDUMgr()->activateEDU( cb ) ; while ( !cb->isDisconnected() ) { pKrcb->syncCurTime() ; pmdUpdateDBTick() ; ossSleep( PMD_SYNC_CLOCK_INTERVAL ) ; } return SDB_OK ; }