Ejemplo n.º 1
0
   INT32 _pmdDataProcessor::_onReadLobMsg( MsgHeader *msg,
                                           rtnContextBuf &buffObj )
   {
      INT32 rc = SDB_OK ;
      const MsgOpLob *header = NULL ;
      SINT64 offset = -1 ;
      UINT32 readLen = 0 ;
      UINT32 length = 0 ;
      const CHAR *data = NULL ;

      rc = msgExtractReadLobRequest( ( const CHAR * )msg, &header,
                                      &readLen, &offset ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "failed to extract read msg:%d", rc ) ;
         goto error ;
      }

      rc = rtnReadLob( header->contextID, eduCB(),
                       readLen, offset, &data, length ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "failed to read lob:%d", rc ) ;
         goto error ;
      }

      buffObj = rtnContextBuf( data, length, 0 ) ;
   done:
      return rc ;
   error:
      goto done ;
   }
Ejemplo n.º 2
0
   INT32 _pmdDataProcessor::_onOpenLobMsg( MsgHeader *msg, SDB_DPSCB *dpsCB,
                                           SINT64 &contextID,
                                           rtnContextBuf &buffObj )
   {
      INT32 rc = SDB_OK ;
      const MsgOpLob *header = NULL ;
      BSONObj lob ;
      BSONObj meta ;
      rc = msgExtractOpenLobRequest( ( const CHAR * )msg, &header, lob ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "failed to extract open msg:%d", rc ) ;
         goto error ;
      }

      rc = rtnOpenLob( lob, header->flags, TRUE, eduCB(),
                       dpsCB, header->w, contextID, meta ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "failed to open lob:%d", rc ) ;
         goto error ;
      }

      buffObj = rtnContextBuf( meta.objdata(), meta.objsize(), 1 ) ;
   done:
      return rc ;
   error:
      goto done ;
   }
Ejemplo n.º 3
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCOORDREADLOB_EXECUTE, "rtnCoordReadLob::execute" )
   INT32 rtnCoordReadLob::execute( CHAR * pReceiveBuffer,
                                   SINT32 packSize,
                                   pmdEDUCB * cb,
                                   MsgOpReply & replyHeader,
                                   rtnContextBuf *buf )
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY( SDB_RTNCOORDREADLOB_EXECUTE ) ;
      SDB_ASSERT( NULL != buf, "can not be null" ) ;
      const MsgOpLob *header = NULL ;
      const MsgHeader *baseHeader = ( const MsgHeader * )pReceiveBuffer ;
      BSONObj obj ;
      UINT32 len = 0 ;
      SINT64 offset = -1 ;
      const CHAR *data = NULL ;
      UINT32 readLen = 0 ;

      replyHeader.header.messageLength = sizeof( MsgOpReply ) ;
      replyHeader.header.opCode = MSG_BS_LOB_READ_RES ;
      replyHeader.header.requestID = baseHeader->requestID ;
      replyHeader.header.routeID.value = 0 ;
      replyHeader.header.TID = baseHeader->TID ;
      replyHeader.contextID = -1 ;
      replyHeader.flags = SDB_OK ;
      replyHeader.numReturned = 0 ;
      replyHeader.startFrom = 0 ;

      rc = msgExtractReadLobRequest( pReceiveBuffer, &header, &len,
                                     &offset ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "failed to extract msg:%d", rc ) ;
         goto error ;
      }

      rc = rtnReadLob( header->contextID, cb, len,
                       offset, &data, readLen ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "failed to read lob:%d", rc ) ;
         goto error ;   
      }

      *buf = rtnContextBuf( data, readLen, 1 ) ;
   done:
      PD_TRACE_EXITRC( SDB_RTNCOORDREADLOB_EXECUTE, rc ) ;
      return rc ;
   error:
      replyHeader.flags = rc ;
      goto done ;
   }
Ejemplo n.º 4
0
   INT32 _rtnDataSet::initByReply( MsgOpReply *pReply,
                                   _pmdEDUCB *cb,
                                   BOOLEAN ownned )
   {
      INT32 rc = SDB_OK ;

      /// context id must be invalid
      SDB_ASSERT( -1 == pReply->contextID, "Context id must be -1" ) ;

      /// first clear
      clear() ;

      _lastErr = pReply->flags ;
      _cb = cb ;

      rc = pReply->flags ;

      /// has data
      if ( SDB_OK == rc &&
           pReply->header.messageLength > (INT32)sizeof( MsgOpReply ) )
      {
         if ( !ownned )
         {
            _pBuff = ( CHAR* )pReply ;
         }
         else
         {
            _pBuff = ( CHAR* )SDB_OSS_MALLOC( pReply->header.messageLength ) ;
            if ( !_pBuff )
            {
               PD_LOG( PDERROR, "Alloc memory[%d] failed",
                       pReply->header.messageLength ) ;
               rc = SDB_OOM ;
               _lastErr = rc ;
               goto error ;
            }
            _ownned = TRUE ;
            ossMemcpy( _pBuff, pReply, pReply->header.messageLength ) ;
         }

         _contextBuf = rtnContextBuf( _pBuff + sizeof( MsgOpReply ),
                                      pReply->header.messageLength -
                                      sizeof( MsgOpReply ),
                                      pReply->numReturned ) ;
      }

   done:
      return rc ;
   error:
      goto done ;
   }
Ejemplo n.º 5
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCOORDOPENLOB_EXECUTE, "rtnCoordOpenLob::execute" )
   INT32 rtnCoordOpenLob::execute( CHAR * pReceiveBuffer,
                                   SINT32 packSize,
                                   pmdEDUCB * cb,
                                   MsgOpReply & replyHeader,
                                   rtnContextBuf *buf )
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY( SDB_RTNCOORDOPENLOB_EXECUTE ) ;
      SDB_ASSERT( NULL != buf, "can not be null" ) ;
      const MsgOpLob *header = NULL ;
      const MsgHeader *baseHeader = ( const MsgHeader * )pReceiveBuffer ;
      BSONObj obj ;
      BSONObj meta ;
      SINT64 contextID = -1 ;
      replyHeader.header.messageLength = sizeof( MsgOpReply );
      replyHeader.header.opCode = MSG_BS_LOB_OPEN_RES ;
      replyHeader.header.requestID = baseHeader->requestID ;
      replyHeader.header.routeID.value = 0 ;
      replyHeader.header.TID = baseHeader->TID ;
      replyHeader.contextID = -1 ;
      replyHeader.flags = SDB_OK ;
      replyHeader.numReturned = 0 ;
      replyHeader.startFrom = 0 ;

      rc = msgExtractOpenLobRequest( pReceiveBuffer, &header, obj ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "failed to extract open msg:%d", rc ) ;
         goto error ;
      }

      rc = rtnOpenLob( obj, 0, FALSE, cb,
                       NULL, 0, contextID,
                       meta ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "failed to open lob:%s, rc:%d",
                 obj.toString( FALSE, TRUE ).c_str(), rc ) ;
         goto error ;
      }

      replyHeader.contextID = contextID ;
      *buf = rtnContextBuf( meta ) ;
   done:
      PD_TRACE_EXITRC( SDB_RTNCOORDOPENLOB_EXECUTE, rc ) ;
      return rc ;
   error:
      replyHeader.flags = rc ;
      goto done ;
   }
Ejemplo n.º 6
0
   //PD_TRACE_DECLARE_FUNCTION ( COORD_OPERATORDEL_EXE, "_coordDeleteOperator::execute" )
   INT32 _coordDeleteOperator::execute( MsgHeader *pMsg,
                                        pmdEDUCB *cb,
                                        INT64 &contextID,
                                        rtnContextBuf *buf )
   {
      INT32 rc = SDB_OK ;
      INT32 rcTmp = SDB_OK ;
      PD_TRACE_ENTRY ( COORD_OPERATORDEL_EXE ) ;

      coordSendOptions sendOpt( TRUE ) ;
      coordSendMsgIn inMsg( pMsg ) ;
      coordProcessResult result ;
      ROUTE_RC_MAP nokRC ;
      result._pNokRC = &nokRC ;

      coordCataSel cataSel ;
      MsgRouteID errNodeID ;

      BSONObj boDeletor ;

      MsgOpDelete *pDelMsg             = (MsgOpDelete *)pMsg ;
      INT32 oldFlag                    = pDelMsg->flags ;
      pDelMsg->flags                  |= FLG_DELETE_RETURNNUM ;
      contextID                        = -1 ;

      INT32 flag = 0;
      CHAR *pCollectionName = NULL ;
      CHAR *pDeletor = NULL ;
      CHAR *pHint = NULL ;
      rc = msgExtractDelete( (CHAR*)pMsg, &flag, &pCollectionName,
                             &pDeletor, &pHint ) ;
      if( rc )
      {
         PD_LOG( PDERROR,"Failed to parse delete request, rc: %d", rc ) ;
         pCollectionName = NULL ;
         goto error ;
      }

      try
      {
         boDeletor = BSONObj( pDeletor ) ;
      }
      catch ( std::exception &e )
      {
         PD_RC_CHECK( SDB_INVALIDARG, PDERROR,
                      "Delete failed, received unexpected error: %s",
                      e.what() ) ;
      }

      MON_SAVE_OP_DETAIL( cb->getMonAppCB(), pMsg->opCode,
                          "Collection:%s, Deletor:%s, Hint:%s, "
                          "Flag:0x%08x(%u)",
                          pCollectionName,
                          boDeletor.toString().c_str(),
                          BSONObj(pHint).toString().c_str(),
                          oldFlag, oldFlag ) ;

      rc = cataSel.bind( _pResource, pCollectionName, cb, FALSE, TRUE ) ;
      if ( rc )
      {
         PD_LOG( PDERROR, "Get or update collection[%s]'s catalog info "
                 "failed, rc: %d", pCollectionName, rc ) ;
         goto error ;
      }

   retry:
      pDelMsg->version = cataSel.getCataPtr()->getVersion() ;
      pDelMsg->w = 0 ;
      rcTmp = doOpOnCL( cataSel, boDeletor, inMsg, sendOpt, cb, result ) ;

      if ( SDB_OK == rcTmp && nokRC.empty() )
      {
         goto done ;
      }
      else if ( checkRetryForCLOpr( rcTmp, &nokRC, cataSel, inMsg.msg(),
                                    cb, rc, &errNodeID, TRUE ) )
      {
         nokRC.clear() ;
         _groupSession.getGroupCtrl()->incRetry() ;
         goto retry ;
      }
      else
      {
         PD_LOG( PDERROR, "Delete failed on node[%s], rc: %d",
                 routeID2String( errNodeID ).c_str(), rc ) ;
         goto error ;
      }

   done:
      if ( oldFlag & FLG_DELETE_RETURNNUM )
      {
         contextID = _recvNum ;
      }
      if ( pCollectionName )
      {
         PD_AUDIT_OP( AUDIT_DML, MSG_BS_DELETE_REQ, AUDIT_OBJ_CL,
                      pCollectionName, rc,
                      "DeletedNum:%u, Deletor:%s, Hint:%s, Flag:0x%08x(%u)",
                      _recvNum, boDeletor.toString().c_str(),
                      BSONObj(pHint).toString().c_str(), oldFlag, oldFlag ) ;
      }
      PD_TRACE_EXITRC ( COORD_OPERATORDEL_EXE, rc ) ;
      return rc ;
   error:
      if ( buf && nokRC.size() > 0 )
      {
         *buf = rtnContextBuf( coordBuildErrorObj( _pResource, rc,
                                                   cb, &nokRC ) ) ;
      }
      goto done ;
   }
Ejemplo n.º 7
0
   INT32 _pmdCoordProcessor::_processCoordMsg( MsgHeader *msg, 
                                               MsgOpReply &replyHeader,
                                               rtnContextBuf &contextBuff )
   {
      INT32 rc = SDB_OK ;
      if ( NULL != _pErrorObj )
      {
         SDB_OSS_DEL _pErrorObj ;
         _pErrorObj = NULL ;
      }
      if ( NULL != _pResultBuff )
      {
         _pResultBuff = NULL ;
      }
      CoordCB *pCoordcb  = _pKrcb->getCoordCB();
      rtnCoordProcesserFactory *pProcesserFactory
                                        = pCoordcb->getProcesserFactory();

      if ( MSG_AUTH_VERIFY_REQ == msg->opCode )
      {
         rc = SDB_COORD_UNKNOWN_OP_REQ ;
         goto done ;
      }
      else if ( MSG_BS_INTERRUPTE == msg->opCode ||
                MSG_BS_INTERRUPTE_SELF == msg->opCode ||
                MSG_BS_DISCONNECT == msg->opCode )
      {
      }
      else if ( !getClient()->isAuthed() )
      {
         rc = getClient()->authenticate( "", "" ) ;
         if ( rc )
         {
            goto done ;
         }
      }

      switch ( msg->opCode )
      {
      case MSG_BS_GETMORE_REQ :
         rc = SDB_COORD_UNKNOWN_OP_REQ ;
         break ;
      case MSG_BS_QUERY_REQ:
         {
            MsgOpQuery *pQueryMsg   = ( MsgOpQuery * )msg ;
            CHAR *pQueryName        = pQueryMsg->name ;
            SINT32 queryNameLen     = pQueryMsg->nameLength ;
            if ( queryNameLen > 0 && '$' == pQueryName[0] )
            {
               rtnCoordCommand *pCmdProcesser = 
                           pProcesserFactory->getCommandProcesser( pQueryMsg ) ;
               if ( NULL != pCmdProcesser )
               {
                  rc = pCmdProcesser->execute( ( CHAR *)msg,
                                               msg->messageLength,
                                               eduCB(),
                                               replyHeader,
                                               &contextBuff ) ;
                  break ;
               }
            }
         }
      default:
         {
            rtnContextBase *pContext = NULL ;
            rtnCoordOperator *pOperator = 
                           pProcesserFactory->getOperator( msg->opCode ) ;
            rc = pOperator->execute( ( CHAR* )msg,
                                     msg->messageLength,
                                     eduCB(),
                                     replyHeader,
                                     &contextBuff ) ;
            if ( MSG_BS_QUERY_REQ == msg->opCode 
                 && ( ((MsgOpQuery*)msg)->flags & FLG_QUERY_WITH_RETURNDATA )
                 && -1 != replyHeader.contextID 
                 && NULL != ( pContext = _pRTNCB->contextFind( 
                                                    replyHeader.contextID ) ) )
            {
               rc = pContext->getMore( -1, contextBuff, eduCB() ) ;
               if ( rc || pContext->eof() )
               {
                  _pRTNCB->contextDelete( replyHeader.contextID, eduCB() ) ;
                  replyHeader.contextID = -1 ;
               }

               if ( SDB_DMS_EOC == rc )
               {
                  rc = SDB_OK ;
               }
               else if ( rc )
               {
                  PD_LOG( PDERROR, "Failed to query with return data, "
                          "rc: %d", rc ) ;
               }
            }
         }
         break;
      }

      if ( rc && contextBuff.size() == 0 )
      {
         if ( NULL != _pErrorObj )
         {
            contextBuff = rtnContextBuf( *_pErrorObj ) ;
         }
         else
         {
            BSONObj obj = utilGetErrorBson( rc, eduCB()->getInfo(
                                            EDU_INFO_ERROR ) ) ;
            contextBuff = rtnContextBuf( obj ) ;
         }
      }

   done:
      return rc ;
   }
Ejemplo n.º 8
0
   // PD_TRACE_DECLARE_FUNCTION ( COORD_EVAL_EXE, "_coordCMDEval::execute" )
   INT32 _coordCMDEval::execute( MsgHeader *pMsg,
                                 pmdEDUCB *cb,
                                 INT64 &contextID,
                                 rtnContextBuf *buf )
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY( COORD_EVAL_EXE ) ;
      spdSession *session = NULL ;
      contextID           = -1 ;

      CHAR *pQuery = NULL ;
      BSONObj procedures ;
      spdCoordDownloader downloader( this, cb ) ;
      BSONObj runInfo ;

      rc = msgExtractQuery( (CHAR*)pMsg, NULL, NULL,
                            NULL, NULL, &pQuery, NULL,
                            NULL, NULL );
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "failed to extract eval msg:%d", rc) ;
         goto error ;
      }

      try
      {
         procedures = BSONObj( pQuery ) ;
         PD_LOG( PDDEBUG, "eval:%s", procedures.toString().c_str() ) ;
      }
      catch ( std::exception &e )
      {
         PD_LOG( PDERROR, "unexpected err happened:%s", e.what() ) ;
         rc = SDB_SYS ;
         goto error ;
      }

      session = SDB_OSS_NEW _spdSession() ;
      if ( NULL == session )
      {
         PD_LOG( PDERROR, "failed to allocate mem." ) ;
         rc = SDB_OOM ;
         goto error ;
      }

      rc = session->eval( procedures, &downloader, cb ) ;
      if ( SDB_OK != rc )
      {
         const BSONObj &errmsg = session->getErrMsg() ;
         if ( !errmsg.isEmpty() )
         {
            *buf = rtnContextBuf( errmsg.getOwned() ) ;
         }
         PD_LOG( PDERROR, "failed to eval store procedure:%d", rc ) ;
         goto error ;
      }

      if ( FMP_RES_TYPE_VOID != session->resType() )
      {
         rc = _buildContext( session, cb, contextID ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "failed to prepare reply msg:%d", rc ) ;
            goto error ;
         }
      }

      runInfo = BSON( FIELD_NAME_RTYPE << session->resType() ) ;
      *buf = rtnContextBuf( runInfo ) ;

   done:
      if ( -1 == contextID )
      {
         SAFE_OSS_DELETE( session ) ;
      }
      PD_TRACE_EXITRC( COORD_EVAL_EXE, rc ) ;
      return rc ;
   error:
      if ( contextID >= 0 )
      {
         pmdGetKRCB()->getRTNCB()->contextDelete( contextID, cb ) ;
         contextID = -1 ;
      }
      goto done ;
   }