Ejemplo n.º 1
0
   // PD_TRACE_DECLARE_FUNCTION ( COORD_INTERRUPT_EXE, "_coordInterrupt::execute" )
   INT32 _coordInterrupt::execute( MsgHeader *pMsg,
                                   pmdEDUCB *cb,
                                   INT64 &contextID,
                                   rtnContextBuf *buf )
   {
      INT32 rc = SDB_OK;
      PD_TRACE_ENTRY ( COORD_INTERRUPT_EXE ) ;
      SDB_RTNCB *pRtncb = pmdGetKRCB()->getRTNCB() ;
      pmdRemoteSessionSite *pSite = NULL ;
      INT64 tmpContextID = -1 ;

      contextID = -1 ;

      if ( cb->getRemoteSite() )
      {
         pSite = (pmdRemoteSessionSite*)cb->getRemoteSite() ;
         pSite->interruptAllSubSession() ;
      }

      cb->interrupt() ;

      while ( -1 != ( tmpContextID = cb->contextPeek() ) )
      {
         pRtncb->contextDelete( tmpContextID, NULL ) ;
      }

      PD_TRACE_EXITRC ( COORD_INTERRUPT_EXE, rc ) ;
      return rc ;
   }
Ejemplo n.º 2
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 ;
   }
Ejemplo n.º 3
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 ;
   }
Ejemplo n.º 4
0
   _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 ) ;
   }
Ejemplo n.º 5
0
   INT32 _coordCMDEval::_buildContext( _spdSession *session,
                                       pmdEDUCB *cb,
                                       SINT64 &contextID )
   {
      INT32 rc = SDB_OK ;
      const BSONObj &evalRes = session->getRetMsg() ;
      SDB_ASSERT( !evalRes.isEmpty(), "impossible" ) ;

      SDB_RTNCB *rtnCB = pmdGetKRCB()->getRTNCB() ;
      rtnContextSP *context = NULL ;
      rc = rtnCB->contextNew ( RTN_CONTEXT_SP, (rtnContext**)&context,
                               contextID, cb ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to create new context, rc: %d", rc ) ;

      rc = context->open( session ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to open context[%lld], rc: %d",
                   context->contextID(), rc ) ;
   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 ;
   }
Ejemplo n.º 8
0
   INT32 _coordCMDListLobs::execute( MsgHeader *pMsg,
                                     pmdEDUCB *cb,
                                     INT64 &contextID,
                                     rtnContextBuf *buf )
   {
      INT32 rc = SDB_OK ;
      SDB_RTNCB *pRtncb = pmdGetKRCB()->getRTNCB() ;

      CHAR *pQuery = NULL ;
      BSONObj query ;

      rtnContextCoord *context = NULL ;
      coordQueryOperator queryOpr( TRUE ) ;
      coordQueryConf queryConf ;
      coordSendOptions sendOpt ;

      contextID = -1 ;

      rc = msgExtractQuery( (CHAR*)pMsg, NULL, NULL,
                            NULL, NULL, &pQuery,
                            NULL, NULL, NULL ) ;

      PD_RC_CHECK( rc, PDERROR, "Parse message failed, rc: %d", rc ) ;

      try
      {
         query = BSONObj( pQuery ) ;
         BSONElement ele = query.getField( FIELD_NAME_COLLECTION ) ;
         if ( String != ele.type() )
         {
            PD_LOG( PDERROR, "invalid obj of list lob:%s",
                    query.toString( FALSE, TRUE ).c_str() ) ;
            rc = SDB_INVALIDARG ;
            goto error ;
         }
         queryConf._realCLName = ele.valuestr() ;
      }
      catch ( std::exception &e )
      {
         PD_LOG( PDERROR, "unexpected err happened:%s", e.what() ) ;
         rc = SDB_SYS ;
         goto error ;
      }

      rc = queryOpr.init( _pResource, cb, getTimeout() ) ;
      if ( rc )
      {
         PD_LOG( PDERROR, "Init query operator failed, rc: %d", rc ) ;
         goto error ;
      }

      queryConf._openEmptyContext = TRUE ;
      queryConf._allCataGroups = TRUE ;
      rc = queryOpr.queryOrDoOnCL( pMsg, cb, &context,
                                   sendOpt, &queryConf, buf ) ;
      PD_RC_CHECK( rc, PDERROR, "List lobs[%s] on groups failed, rc: %d",
                   queryConf._realCLName.c_str(), rc ) ;

      contextID = context->contextID() ;

   done:
      return rc ;
   error:
      if ( context )
      {
         pRtncb->contextDelete( context->contextID(), cb ) ;
      }
      goto done ;
   }
Ejemplo n.º 9
0
   INT32 _coordCMDListCLInDomain::_rebuildListResult(
                                    const vector<BSONObj> &infoFromCata,
                                    pmdEDUCB *cb,                       
                                    SINT64 &contextID )
   {
      INT32 rc = SDB_OK ;
      rtnContext *context = NULL ;
      SDB_RTNCB *rtnCB = sdbGetRTNCB() ;

      rc = rtnCB->contextNew( RTN_CONTEXT_DUMP,
                              &context,
                              contextID,
                              cb ) ;
      if  ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "failed to create new context:%d", rc ) ;
         goto error ;
      }

      rc = (( rtnContextDump * )context)->open( BSONObj(), BSONObj() ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "failed to open context:%d", rc ) ;
         goto error ;
      }

      for ( vector<BSONObj>::const_iterator itr = infoFromCata.begin();
            itr != infoFromCata.end();
            itr++ )
      {
         BSONElement cl ;
         BSONElement cs = itr->getField( FIELD_NAME_NAME ) ;
         if ( String != cs.type() )
         {
            PD_LOG( PDERROR, "invalid collection space info:%s",
                    itr->toString().c_str() ) ;
            rc = SDB_SYS ;
            goto error ;
         }

         cl = itr->getField( FIELD_NAME_COLLECTION ) ;
         if ( Array != cl.type() )
         {
            PD_LOG( PDERROR, "invalid collection space info:%s",
                    itr->toString().c_str() ) ;
            rc = SDB_SYS ;
            goto error ;
         }
         else
         {
            BSONObjIterator clItr( cl.embeddedObject() ) ;
            while ( clItr.more() )
            {
               stringstream ss ;
               BSONElement clName ;
               BSONElement oneCl = clItr.next() ;
               if ( Object != oneCl.type() )
               {
                  PD_LOG( PDERROR, "invalid collection space info:%s",
                          itr->toString().c_str() ) ;
                  rc = SDB_SYS ;
                  goto error ;
               }

               clName = oneCl.embeddedObject().getField( FIELD_NAME_NAME ) ;
               if ( String != clName.type() )
               {
                  PD_LOG( PDERROR, "invalid collection space info: %s",
                          itr->toString().c_str() ) ;
                  rc = SDB_SYS ;
                  goto error ;
               }

               ss << cs.valuestr() << "." << clName.valuestr() ;
               context->append( BSON( FIELD_NAME_NAME << ss.str() ) ) ;
            }
         }
      }

   done:
      return rc ;
   error:
      if ( -1 != contextID )
      {
         rtnCB->contextDelete ( contextID, cb ) ;
         contextID = -1 ;
      }
      goto done ;
   }
Ejemplo n.º 10
0
   // PD_TRACE_DECLARE_FUNCTION ( COORD_CMDSTATBASE_EXE, "_coordCMDStatisticsBase::execute" )
   INT32 _coordCMDStatisticsBase::execute( MsgHeader *pMsg,
                                           pmdEDUCB *cb,
                                           INT64 &contextID,
                                           rtnContextBuf *buf )
   {
      INT32 rc = SDB_OK;
      PD_TRACE_ENTRY ( COORD_CMDSTATBASE_EXE ) ;

      SDB_RTNCB *pRtncb                = pmdGetKRCB()->getRTNCB() ;

      contextID                        = -1 ;

      coordQueryOperator queryOpr( isReadOnly() ) ;
      rtnContextCoord *pContext = NULL ;
      coordQueryConf queryConf ;
      coordSendOptions sendOpt ;
      queryConf._openEmptyContext = openEmptyContext() ;

      CHAR *pHint = NULL ;

      rc = msgExtractQuery( (CHAR*)pMsg, NULL, NULL,
                            NULL, NULL, NULL, NULL,
                            NULL, &pHint );
      PD_RC_CHECK ( rc, PDERROR, "Execute failed, failed to parse query "
                    "request, rc: %d", rc ) ;

      try
      {
         BSONObj boHint( pHint ) ;
         BSONElement ele = boHint.getField( FIELD_NAME_COLLECTION ) ;
         PD_CHECK ( ele.type() == String,
                    SDB_INVALIDARG, error, PDERROR,
                    "Execute failed, failed to get the field(%s)",
                    FIELD_NAME_COLLECTION ) ;
         queryConf._realCLName = ele.str() ;
      }
      catch( std::exception &e )
      {
         PD_RC_CHECK ( rc, PDERROR, "Execute failed, occured unexpected "
                       "error:%s", e.what() ) ;
      }

      rc = queryOpr.init( _pResource, cb, getTimeout() ) ;
      if ( rc )
      {
         PD_LOG( PDERROR, "Init query operator failed, rc: %d", rc ) ;
         goto error ;
      }

      rc = queryOpr.queryOrDoOnCL( pMsg, cb, &pContext,
                                   sendOpt, &queryConf, buf ) ;
      PD_RC_CHECK( rc, PDERROR, "Query failed, rc: %d", rc ) ;

      rc = generateResult( pContext, cb ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to execute statistics, rc: %d", rc ) ;

      contextID = pContext->contextID() ;
      pContext->reopen() ;

   done:
      PD_TRACE_EXITRC ( COORD_CMDSTATBASE_EXE, rc ) ;
      return rc;
   error:
      if ( pContext )
      {
         pRtncb->contextDelete( pContext->contextID(), cb ) ;
      }
      goto done ;
   }
Ejemplo n.º 11
0
   INT32 rtnCoordQuery::executeQuery( CHAR *pSrc ,
                                      BSONObj &boQuery ,
                                      BSONObj &boOrderBy ,
                                      const CHAR * pCollectionName ,
                                      netMultiRouteAgent *pRouteAgent ,
                                      pmdEDUCB *cb ,
                                      rtnContextCoord *&pContext )
   {
      SDB_ASSERT( pSrc, "pSrc can't be null!" ) ;
      SDB_ASSERT( pCollectionName, "pCollectionName can't be null!" ) ;
      INT32 rc = SDB_OK ;
      SINT64 contextID = -1 ;
      BOOLEAN isNeedRefresh = FALSE ;
      BOOLEAN hasRetry = FALSE ;
      CoordCataInfoPtr cataInfo ;
      CoordGroupList sendGroupList ;
      MsgOpQuery *pQuery = (MsgOpQuery *)pSrc ;
      SDB_RTNCB *pRtncb = pmdGetKRCB()->getRTNCB() ;
      rc = pRtncb->contextNew( RTN_CONTEXT_COORD,
                               (rtnContext **)&pContext,
                               contextID, cb ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to allocate context(rc=%d)", rc ) ;

      if ( FLG_QUERY_EXPLAIN & pQuery->flags )
      {
         rc = pContext->open( BSONObj(), -1, 0 ) ;
      }
      else
      {
         rc = pContext->open( boOrderBy, pQuery->numToReturn,
                              pQuery->numToSkip ) ;
      }
      PD_RC_CHECK( rc, PDERROR, "Open context failed(rc=%d)", rc ) ;
      pQuery->header.routeID.value = 0;
      pQuery->header.TID = cb->getTID();
      if ( pQuery->numToReturn > 0 && pQuery->numToSkip > 0 )
      {
         pQuery->numToReturn += pQuery->numToSkip ;
      }
      pQuery->numToSkip = 0 ;

   retry:
      rc = rtnCoordGetCataInfo( cb, pCollectionName,
                                isNeedRefresh, cataInfo ) ;
      PD_RC_CHECK( rc, PDERROR,
                   "Failed to get the catalog info(collection:%s)",
                   pCollectionName ) ;
      pQuery->version = cataInfo->getVersion() ;
      if ( cataInfo->isMainCL() )
      {
         CoordSubCLlist subCLList ;
         CoordGroupSubCLMap groupSubCLMap ;
         rc = cataInfo->getMatchSubCLs( boQuery, subCLList ) ;
         PD_CHECK( SDB_OK == rc, rc, retry_check, PDWARNING,
                   "Failed to get match sub collection(rc=%d)",
                   rc ) ;
         rc = rtnCoordGetSubCLsByGroups( subCLList, sendGroupList,
                                         cb, groupSubCLMap ) ;
         PD_CHECK( SDB_OK == rc, rc, retry_check, PDWARNING,
                   "Failed to get sub-collection info(rc=%d)",
                   rc );
         rc = queryOnMainCL( groupSubCLMap, pQuery, cb, pRouteAgent,
                             sendGroupList, pContext ) ;
         PD_CHECK( SDB_OK == rc, rc, retry_check, PDWARNING,
                   "Query on main collection failed(rc=%d)",
                   rc );
      }
      else
      {
         CoordGroupList groupList ;
         rc = getNodeGroups( cataInfo, boQuery,
                             sendGroupList, groupList ) ;
         PD_CHECK( SDB_OK == rc, rc, retry_check, PDWARNING,
                   "Failed to get match sharding(rc=%d)",
                   rc ) ;
         rc = queryToDataNodeGroup( pSrc, groupList, sendGroupList,
                                    pRouteAgent, cb, pContext ) ;
         PD_CHECK( SDB_OK == rc, rc, retry_check, PDWARNING,
                   "Query on data node failed(rc=%d)",
                   rc ) ;
      }

   retry_check:
      if ( rc != SDB_OK )
      {
         if ( rc != SDB_APP_INTERRUPT && !hasRetry )
         {
            hasRetry = TRUE ;
            isNeedRefresh = TRUE ;
            goto retry ;
         }
         goto error ;
      }
   done:
      return rc ;
   error:
      if ( SDB_CAT_NO_MATCH_CATALOG == rc )
      {
         rc = SDB_OK ;
         goto done ;
      }
      if ( contextID >= 0 )
      {
         pRtncb->contextDelete( contextID, cb ) ;
         contextID = -1 ;
         pContext = NULL ;
      }
      goto done ;
   }