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 ; }
INT32 _rtnDataSet::initByQuery( const rtnQueryOptions &options, _pmdEDUCB *cb ) { clear() ; _cb = cb ; INT32 rc = rtnQuery( options._fullName, options._query, options._selector, options._orderBy, options._hint, options._flag, _cb, options._skip, options._limit, sdbGetDMSCB(), _rtnCB, _contextID, NULL, FALSE ) ; _lastErr = rc ; return rc ; }
_rtnDataSet::_rtnDataSet( const rtnQueryOptions &options, _pmdEDUCB *cb ) :_contextID( -1 ), _cb( cb ), _lastErr( SDB_OK ), _fetchFromContext( TRUE ), _rtnCB( NULL ) { _rtnCB = sdbGetRTNCB() ; _lastErr = rtnQuery( options._fullName, options._query, options._selector, options._orderBy, options._hint, options._flag, _cb, options._skip, options._limit, sdbGetDMSCB(), _rtnCB, _contextID, NULL, FALSE ) ; }
INT32 _qgmPlScan::_executeOnData( _pmdEDUCB *eduCB ) { PD_TRACE_ENTRY( SDB__QGMPLSCAN__EXECONDATA ) ; INT32 rc = SDB_OK ; BSONObj selector = _selector.selector() ; rc = rtnQuery ( _collection.toString().c_str(), selector, _condition, _orderby, _hint, 0, eduCB, _skip, _return, _dmsCB, _rtnCB, _contextID, NULL, FALSE ) ; if ( SDB_OK != rc ) { goto error ; } done: PD_TRACE_EXITRC( SDB__QGMPLSCAN__EXECONDATA, rc ) ; return rc ; error: goto done ; }
INT32 _pmdDataProcessor::_onQueryReqMsg( MsgHeader * msg, SDB_DPSCB *dpsCB, _rtnContextBuf &buffObj, INT64 &contextID ) { INT32 rc = SDB_OK ; INT32 flags = 0 ; CHAR *pCollectionName = NULL ; CHAR *pQueryBuff = NULL ; CHAR *pFieldSelector = NULL ; CHAR *pOrderByBuffer = NULL ; CHAR *pHintBuffer = NULL ; INT64 numToSkip = -1 ; INT64 numToReturn = -1 ; _rtnCommand *pCommand = NULL ; rc = msgExtractQuery ( (CHAR *)msg, &flags, &pCollectionName, &numToSkip, &numToReturn, &pQueryBuff, &pFieldSelector, &pOrderByBuffer, &pHintBuffer ) ; PD_RC_CHECK( rc, PDERROR, "Session[%s] extract query msg failed, rc: %d", getSession()->sessionName(), rc ) ; if ( !rtnIsCommand ( pCollectionName ) ) { rtnContextBase *pContext = NULL ; try { BSONObj matcher ( pQueryBuff ) ; BSONObj selector ( pFieldSelector ) ; BSONObj orderBy ( pOrderByBuffer ) ; BSONObj hint ( pHintBuffer ) ; MON_SAVE_OP_DETAIL( eduCB()->getMonAppCB(), msg->opCode, "CL:%s, Match:%s, Selector:%s, OrderBy:%s, " "Hint:%s", pCollectionName, matcher.toString().c_str(), selector.toString().c_str(), orderBy.toString().c_str(), hint.toString().c_str() ) ; PD_LOG ( PDDEBUG, "Session[%s] Query: matcher: %s\nselector: " "%s\norderBy: %s\nhint:%s", getSession()->sessionName(), matcher.toString().c_str(), selector.toString().c_str(), orderBy.toString().c_str(), hint.toString().c_str() ) ; rc = rtnQuery( pCollectionName, selector, matcher, orderBy, hint, flags, eduCB(), numToSkip, numToReturn, _pDMSCB, _pRTNCB, contextID, &pContext, TRUE ) ; if ( rc ) { goto error ; } if ( ( flags & FLG_QUERY_WITH_RETURNDATA ) && NULL != pContext ) { rc = pContext->getMore( -1, buffObj, eduCB() ) ; if ( rc || pContext->eof() ) { _pRTNCB->contextDelete( contextID, eduCB() ) ; contextID = -1 ; } if ( SDB_DMS_EOC == rc ) { rc = SDB_OK ; } else if ( rc ) { PD_LOG( PDERROR, "Session[%s] failed to query with return " "data, rc: %d", getSession()->sessionName(), rc ) ; goto error ; } } } catch ( std::exception &e ) { PD_LOG ( PDERROR, "Session[%s] Failed to create matcher and " "selector for QUERY: %s", getSession()->sessionName(), e.what () ) ; rc = SDB_INVALIDARG ; goto error ; } } else { rc = rtnParserCommand( pCollectionName, &pCommand ) ; if ( SDB_OK != rc ) { PD_LOG ( PDERROR, "Parse command[%s] failed[rc:%d]", pCollectionName, rc ) ; goto error ; } rc = rtnInitCommand( pCommand , flags, numToSkip, numToReturn, pQueryBuff, pFieldSelector, pOrderByBuffer, pHintBuffer ) ; if ( SDB_OK != rc ) { goto error ; } PD_LOG ( PDDEBUG, "Command: %s", pCommand->name () ) ; rc = rtnRunCommand( pCommand, getSession()->getServiceType(), eduCB(), _pDMSCB, _pRTNCB, dpsCB, 1, &contextID ) ; if ( rc ) { goto error ; } } done: if ( pCommand ) { rtnReleaseCommand( &pCommand ) ; } return rc ; error: goto done ; }
INT32 omClusterNotifier::_updateNotifier() { INT32 rc = SDB_OK ; BSONObj selector ; BSONObj matcher ; BSONObj order ; BSONObj hint ; BSONObjBuilder builder ; SINT64 contextID = -1 ; BSONObjBuilder resultBuilder ; BSONObj result ; pmdKRCB *pKrcb = pmdGetKRCB() ; _SDB_DMSCB *pDMSCB = pKrcb->getDMSCB() ; _SDB_RTNCB *pRTNCB = pKrcb->getRTNCB() ; matcher = BSON( OM_HOST_FIELD_CLUSTERNAME << _clusterName ) ; selector = BSON( OM_HOST_FIELD_NAME << "" << OM_HOST_FIELD_IP << "" << OM_HOST_FIELD_USER << "" << OM_HOST_FIELD_PASSWORD << "" << OM_HOST_FIELD_AGENT_PORT << "" ) ; rc = rtnQuery( OM_CS_DEPLOY_CL_HOST, selector, matcher, order, hint, 0, _cb, 0, -1, pDMSCB, pRTNCB, contextID ); if ( rc ) { PD_LOG( PDERROR, "fail to query table:%s,rc=%d", OM_CS_DEPLOY_CL_HOST, rc ) ; goto error ; } _mapTargetAgents.clear() ; _vHostTable.clear() ; while ( TRUE ) { rtnContextBuf buffObj ; SINT64 startingPos = 0 ; rc = rtnGetMore ( contextID, 1, buffObj, startingPos, _cb, pRTNCB ) ; if ( rc ) { if ( SDB_DMS_EOC == rc ) { rc = SDB_OK ; break ; } contextID = -1 ; PD_LOG( PDERROR, "failed to get record from table:%s,rc=%d", OM_CS_DEPLOY_CL_HOST, rc ) ; goto error ; } BSONObj record( buffObj.data() ) ; omHostContent tmp ; tmp.hostName = record.getStringField( OM_HOST_FIELD_NAME ) ; tmp.ip = record.getStringField( OM_HOST_FIELD_IP ) ; tmp.serviceName = record.getStringField( OM_HOST_FIELD_AGENT_PORT ) ; tmp.user = record.getStringField( OM_HOST_FIELD_USER ) ; tmp.passwd = record.getStringField( OM_HOST_FIELD_PASSWORD ) ; _vHostTable.push_back( tmp ) ; _mapTargetAgents.insert( _MAPAGENT_VALUE( tmp.hostName, tmp ) ) ; } if ( _mapTargetAgents.size() > 0 ) { CHAR localHost[ OSS_MAX_HOSTNAME + 1 ] ; ossGetHostName( localHost, OSS_MAX_HOSTNAME ) ; _MAPAGENT_ITER iter = _mapTargetAgents.find( localHost ) ; if ( iter == _mapTargetAgents.end() ) { omHostContent content ; content.hostName = localHost ; content.ip = "127.0.0.1" ; string serviceName ; _getAgentService( serviceName ) ; content.serviceName = serviceName ; content.user = "" ; content.passwd = "" ; _mapTargetAgents.insert( _MAPAGENT_VALUE( content.hostName, content ) ) ; } } done: return rc ; error: if ( -1 != contextID ) { pRTNCB->contextDelete ( contextID, _cb ) ; } goto done ; }