Exemplo n.º 1
0
   INT32 _qgmPlScan::_fetch( const CHAR *&result )
   {
      PD_TRACE_ENTRY( SDB__QGMPLSCAN__FETCH );
      INT32 rc = SDB_OK ;
      SDB_ASSERT ( _contextID != -1,
                   "context id must be initialized" ) ;

      rtnContextBuf buffObj ;
      rc = rtnGetMore( _contextID, 1, buffObj, _eduCB, _rtnCB ) ;
      if ( rc )
      {
         if ( SDB_DMS_EOC != rc )
         {
            PD_LOG( PDERROR, "Failed to getmore from context[%lld], rc = %d",
                    _contextID, rc ) ;
         }
         goto error ;
      }
      result = buffObj.data() ;

   done:
      PD_TRACE_EXITRC( SDB__QGMPLSCAN__FETCH, rc ) ;
      return rc ;
   error:
      goto done ;
   }
Exemplo n.º 2
0
   INT32 _pmdDataProcessor::_onGetMoreReqMsg( MsgHeader * msg,
                                              rtnContextBuf &buffObj,
                                              INT64 &contextID )
   {
      INT32 rc         = SDB_OK ;
      INT32 numToRead  = 0 ;

      rc = msgExtractGetMore ( (CHAR*)msg, &numToRead, &contextID ) ;
      PD_RC_CHECK( rc, PDERROR, "Session[%s] extract get more msg failed, "
                   "rc: %d", getSession()->sessionName(), rc ) ;

      MON_SAVE_OP_DETAIL( eduCB()->getMonAppCB(), msg->opCode,
                          "ContextID:%lld, NumToRead:%d",
                          contextID, numToRead ) ;

      PD_LOG ( PDDEBUG, "GetMore: contextID:%lld\nnumToRead: %d", contextID,
               numToRead ) ;

      rc = rtnGetMore ( contextID, numToRead, buffObj, eduCB(), _pRTNCB ) ;

   done:
      return rc ;
   error:
      goto done ;
   }
Exemplo n.º 3
0
   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 ;
   }
Exemplo n.º 4
0
   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 ;
   }
Exemplo n.º 5
0
   INT32 _rtnDataSet::next( BSONObj &obj )
   {
      INT32 rc = SDB_OK ;
      if ( SDB_OK != _lastErr )
      {
         goto error ;
      }

   retry:
      if ( _fetchFromContext )
      {
         rc = rtnGetMore( _contextID, -1, _contextBuf, _cb, _rtnCB ) ;
         if ( SDB_OK != rc )
         {
            if ( SDB_DMS_EOC != rc )
            {
               PD_LOG( PDERROR, "failed to get next object:%d", rc ) ;
            }
            else
            {
               _contextID = -1 ;
            }
            _lastErr = rc ;
            goto error ;
         }

         _fetchFromContext = FALSE ;
      }

      rc = _contextBuf.nextObj( obj ) ;
      if ( SDB_OK == rc )
      {
         goto done ;
      }
      else if ( SDB_DMS_EOC == rc )
      {
         rc = SDB_OK ;
         _fetchFromContext = TRUE ;
         goto retry ;
      }
      else
      {
         _lastErr = rc ;
         PD_LOG( PDERROR, "failed to get next from buf:%d", rc ) ;
         goto error ;
      } 
   done:
      return rc ;
   error:
      goto done ;
   }
Exemplo n.º 6
0
   // PD_TRACE_DECLARE_FUNCTION( SDB__QGMPLCOMMAND__FETCHNEXT, "_qgmPlCommand::_fetchNext" )
   INT32 _qgmPlCommand::_fetchNext( qgmFetchOut &next )
   {
      PD_TRACE_ENTRY( SDB__QGMPLCOMMAND__FETCHNEXT ) ;
      INT32 rc = SDB_OK ;

      rtnContextBuf buffObj ;
      SDB_RTNCB *rtnCB = pmdGetKRCB()->getRTNCB() ;

      rc = rtnGetMore( _contextID, 1, buffObj, _eduCB, rtnCB ) ;
      if ( SDB_OK != rc )
      {
         if ( SDB_DMS_EOC != rc )
         {
            PD_LOG( PDERROR, "Failed to getmore from non-coord, rc = %d",
                    rc) ;
         }
         goto error ;
      }

      try
      {
         next.obj = BSONObj( buffObj.data() ) ;
      }
      catch ( std::exception &e )
      {
         PD_LOG( PDERROR, "unexcepted err happened:%s", e.what() ) ;
         rc = SDB_SYS ;
         goto error ;
      }

   done:
      PD_TRACE_EXITRC( SDB__QGMPLCOMMAND__FETCHNEXT, rc ) ;
      return rc ;
   error:
      if ( SDB_DMS_EOC == rc )
         _contextID = -1 ;
      goto done ;
   }
Exemplo n.º 7
0
   INT32 _rtnDataSet::next( BSONObj &obj )
   {
      INT32 rc = SDB_OK ;
      if ( SDB_OK != _lastErr )
      {
         rc = _lastErr ;
         goto error ;
      }

      if ( _contextBuf.eof() && -1 != _contextID )
      {
         rc = rtnGetMore( _contextID, -1, _contextBuf, _cb, _rtnCB ) ;
         if ( rc )
         {
            if ( SDB_DMS_EOC != rc )
            {
               PD_LOG( PDERROR, "Get more from context[%lld] failed, rc: %d",
                       _contextID, rc ) ;
            }
            _contextID = -1 ;
            _lastErr = rc ;
            goto error ;
         }
      }

      rc = _contextBuf.nextObj( obj ) ;
      if ( rc )
      {
         _lastErr = rc ;
         goto error ;
      }

   done:
      return rc ;
   error:
      goto done ;
   }
   INT32 _coordOmStrategyAccessor::getMetaInfoFromOm( omStrategyMetaInfo &metaInfo,
                                                      pmdEDUCB *cb,
                                                      rtnContextBuf *buf )
   {
      INT32 rc = SDB_OK ;
      BSONObj condition ;
      rtnQueryOptions queryOpt ;
      INT64 contextID = -1 ;
      rtnContextBuf bufObj ;
      BSONObj tmpObj ;
      SDB_RTNCB *rtnCB = pmdGetKRCB()->getRTNCB() ;

      try
      {
         condition = BSON( FIELD_NAME_NAME << OM_STRATEGY_BS_TASK_META_NAME <<
                           OM_BSON_CLUSTER_NAME << _clsName <<
                           OM_BSON_BUSINESS_NAME << _bizName ) ;

         queryOpt.setCLFullName( OM_CS_STRATEGY_CL_META_DATA ) ;
         queryOpt.setQuery( condition ) ;
         queryOpt.setLimit( 1 ) ;
         queryOpt.setFlag( FLG_QUERY_WITH_RETURNDATA ) ;

         _pOmProxy->setOprTimeout( _oprTimeout ) ;
         rc = _pOmProxy->queryOnOm( queryOpt, cb, contextID, buf ) ;
         if ( rc )
         {
            PD_LOG( PDERROR, "Query strategy meta from om failed, rc: %d",
                    rc ) ;
            goto error ;
         }

         rc = rtnGetMore( contextID, 1, bufObj, cb, rtnCB ) ;
         if ( rc )
         {
            contextID = -1 ;
            if ( SDB_DMS_EOC == rc )
            {
               rc = SDB_OK ;
               goto done ;
            }
            PD_LOG( PDERROR, "Getmore failed, rc: %d", rc ) ;
            goto error ;
         }

         rc = bufObj.nextObj( tmpObj ) ;
         if ( rc )
         {
            goto error ;
         }

         rc = metaInfo.fromBSON( tmpObj ) ;
         if ( rc )
         {
            goto error ;
         }
      }
      catch( std::exception &e )
      {
         PD_LOG( PDERROR, "Occur exception: %s", e.what() ) ;
         rc = SDB_SYS ;
         goto error ;
      }

   done:
      if ( -1 != contextID )
      {
         rtnCB->contextDelete( contextID, cb ) ;
      }
      return rc ;
   error:
      goto done ;
   }
   INT32 _coordOmStrategyAccessor::getTaskInfoFromOm( vector<omTaskInfoPtr> &vecInfo,
                                                      pmdEDUCB *cb,
                                                      rtnContextBuf *buf )
   {
      INT32 rc = SDB_OK ;
      BSONObj condition ;
      rtnQueryOptions queryOpt ;
      INT64 contextID = -1 ;
      rtnContextBuf bufObj ;
      BSONObj tmpObj ;
      SDB_RTNCB *rtnCB = pmdGetKRCB()->getRTNCB() ;
      omTaskInfo *pTaskInfo = NULL ;

      try
      {
         condition = BSON( OM_REST_FIELD_STATUS << OM_STRATEGY_STATUS_ENABLE <<
                           OM_BSON_CLUSTER_NAME << _clsName <<
                           OM_BSON_BUSINESS_NAME << _bizName ) ;

         queryOpt.setCLFullName( OM_CS_STRATEGY_CL_TASK_PRO ) ;
         queryOpt.setQuery( condition ) ;
         queryOpt.setFlag( FLG_QUERY_WITH_RETURNDATA ) ;

         _pOmProxy->setOprTimeout( _oprTimeout ) ;
         rc = _pOmProxy->queryOnOm( queryOpt, cb, contextID, buf ) ;
         if ( rc )
         {
            PD_LOG( PDERROR, "Query strategy meta from om failed, rc: %d",
                    rc ) ;
            goto error ;
         }

         while( TRUE )
         {
            rc = rtnGetMore( contextID, -1, bufObj, cb, rtnCB ) ;
            if ( rc )
            {
               contextID = -1 ;
               if ( SDB_DMS_EOC == rc )
               {
                  rc = SDB_OK ;
                  break ;
               }
               PD_LOG( PDERROR, "Getmore failed, rc: %d", rc ) ;
               goto error ;
            }

            while( TRUE )
            {
               rc = bufObj.nextObj( tmpObj ) ;
               if ( rc )
               {
                  if ( SDB_DMS_EOC == rc )
                  {
                     rc = SDB_OK ;
                  }
                  break ;
               }

               pTaskInfo = SDB_OSS_NEW omTaskInfo() ;
               if ( !pTaskInfo )
               {
                  PD_LOG( PDERROR, "Allocate task info failed " ) ;
                  rc = SDB_OOM ;
                  goto error ;
               }
               vecInfo.push_back( omTaskInfoPtr( pTaskInfo ) ) ;

               rc = pTaskInfo->fromBSON( tmpObj ) ;
               if ( rc )
               {
                  goto error ;
               }
            }
         }
      }
      catch( std::exception &e )
      {
         PD_LOG( PDERROR, "Occur exception: %s", e.what() ) ;
         rc = SDB_SYS ;
         goto error ;
      }

   done:
      return rc ;
   error:
      if ( -1 != contextID )
      {
         rtnCB->contextDelete( contextID, cb ) ;
      }
      goto done ;
   }
Exemplo n.º 10
0
   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 ;
   }