コード例 #1
0
   INT32 rtnCoordDelete::_prepareMainCLOp( CoordCataInfoPtr &cataInfo,
                                           CoordGroupSubCLMap &grpSubCl,
                                           rtnSendMsgIn &inMsg,
                                           rtnSendOptions &options,
                                           netMultiRouteAgent *pRouteAgent,
                                           pmdEDUCB *cb,
                                           rtnProcessResult &result,
                                           ossValuePtr &outPtr )
   {
      INT32 rc                = SDB_OK ;
      MsgOpDelete *pDelMsg    = ( MsgOpDelete* )inMsg.msg() ;

      INT32 flag              = 0 ;
      CHAR *pCollectionName   = NULL;
      CHAR *pDeletor          = NULL;
      CHAR *pHint             = NULL;
      BSONObj boDeletor ;
      BSONObj boHint ;
      BSONObj boNew ;

      CHAR *pBuff             = NULL ;
      INT32 buffLen           = 0 ;
      INT32 buffPos           = 0 ;
      vector<CHAR*> *pBlock   = NULL ;

      CoordGroupSubCLMap::iterator it ;

      outPtr                  = (ossValuePtr)0 ;
      inMsg.data()->clear() ;

      rc = msgExtractDelete( (CHAR*)inMsg.msg(), &flag, &pCollectionName,
                             &pDeletor, &pHint ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to parse delete request, rc: %d",
                   rc ) ;

      boDeletor = BSONObj( pDeletor ) ;
      boHint = BSONObj( pHint ) ;

      pBlock = new vector< CHAR* >( 16 ) ;
      if ( !pBlock )
      {
         PD_LOG( PDERROR, "Alloc vector failed" ) ;
         rc = SDB_OOM ;
         goto error ;
      }

      it = grpSubCl.begin() ;
      while( it != grpSubCl.end() )
      {
         CoordSubCLlist &subCLLst = it->second ;

         netIOVec &iovec = inMsg._datas[ it->first ] ;
         netIOV ioItem ;

         // 1. first vec
         ioItem.iovBase = (CHAR*)inMsg.msg() + sizeof( MsgHeader ) ;
         ioItem.iovLen = ossRoundUpToMultipleX ( offsetof(MsgOpDelete, name) +
                                                 pDelMsg->nameLength + 1, 4 ) -
                         sizeof( MsgHeader ) ;
         iovec.push_back( ioItem ) ;

         // 2. new deletor vec
         boNew = _buildNewDeletor( boDeletor, subCLLst ) ;
         // 2.1 add to buff
         INT32 roundLen = ossRoundUpToMultipleX( boNew.objsize(), 4 ) ;
         if ( buffPos + roundLen > buffLen )
         {
            INT32 alignLen = ossRoundUpToMultipleX( roundLen,
                                                    DMS_PAGE_SIZE4K ) ;
            rc = cb->allocBuff( alignLen, &pBuff, buffLen ) ;
            PD_RC_CHECK( rc, PDERROR, "Alloc buff[%d] failed, rc: %d",
                         alignLen, rc ) ;
            pBlock->push_back( pBuff ) ;
            buffPos = 0 ;
         }
         ossMemcpy( &pBuff[ buffPos ], boNew.objdata(), boNew.objsize() ) ;
         ioItem.iovBase = &pBuff[ buffPos ] ;
         ioItem.iovLen = roundLen ;
         buffPos += roundLen ;
         iovec.push_back( ioItem ) ;

         // 3. hinter vec
         ioItem.iovBase = boHint.objdata() ;
         ioItem.iovLen = boHint.objsize() ;
         iovec.push_back( ioItem ) ;         

         ++it ;
      }

      outPtr = ( ossValuePtr )pBlock ;

   done:
      return rc ;
   error:
      if ( pBlock )
      {
         for ( INT32 i = 0 ; i < (INT32)pBlock->size() ; ++i )
         {
            cb->releaseBuff( (*pBlock)[ i ] ) ;
         }
         delete pBlock ;
         pBlock = NULL ;
      }
      goto done ;
   }
コード例 #2
0
ファイル: rtnCoordQuery.cpp プロジェクト: 247687009/SequoiaDB
   INT32 rtnCoordQuery::queryOnMainCL( CoordGroupSubCLMap &groupSubCLMap,
                                       MsgOpQuery *pSrc,
                                       pmdEDUCB *cb,
                                       netMultiRouteAgent *pRouteAgent,
                                       CoordGroupList &sendGroupList,
                                       rtnContextCoord *pContext )
   {
      INT32 rc = SDB_OK;
      INT32 rcTmp = SDB_OK;
      CHAR *pBuffer = NULL;
      INT32 bufferSize = 0;
      REPLY_QUE replyQue;
      BOOLEAN takeOver = FALSE ;

      SDB_ASSERT( pContext, "pContext can't be NULL!" );

      try
      {
         CoordGroupSubCLMap::iterator iterGroup;
         REQUESTID_MAP sendNodes;

         INT32 flag;
         CHAR *pCollectionName;
         SINT64 numToSkip;
         SINT64 numToReturn;
         CHAR *pQuery;
         CHAR *pFieldSelector;
         CHAR *pOrderBy;
         CHAR *pHint;
         BSONObj boQuery;
         BSONObj boFieldSelector;
         BSONObj boOrderBy;
         BSONObj boHint;
         rc = msgExtractQuery( (CHAR *)pSrc, &flag, &pCollectionName,
                               &numToSkip, &numToReturn, &pQuery,
                               &pFieldSelector, &pOrderBy, &pHint );
         PD_RC_CHECK( rc, PDERROR,
                     "failed to parse query message(rc=%d)", rc );
         boQuery           = BSONObj( pQuery );
         boFieldSelector   = BSONObj( pFieldSelector );
         boOrderBy         = BSONObj( pOrderBy );
         boHint            = BSONObj( pHint );

         iterGroup = groupSubCLMap.begin();
         while( iterGroup != groupSubCLMap.end() )
         {
            BSONArrayBuilder babSubCL;
            CoordGroupInfoPtr groupInfo;
            CoordSubCLlist::iterator iterSubCL
                                    = iterGroup->second.begin();
            while( iterSubCL != iterGroup->second.end() )
            {
               babSubCL.append( *iterSubCL );
               ++iterSubCL;
            }
            BSONObjBuilder bobNewQuery;
            bobNewQuery.appendElements( boQuery );
            bobNewQuery.appendArray( CAT_SUBCL_NAME, babSubCL.arr() );
            BSONObj boNewQuery = bobNewQuery.obj();
            rc = msgBuildQueryMsg( &pBuffer, &bufferSize, pCollectionName,
                                   flag, 0, numToSkip, numToReturn,
                                   &boNewQuery, &boFieldSelector,
                                   &boOrderBy, &boHint );
            PD_CHECK( SDB_OK == rc, rc, RECV_MSG, PDERROR,
                      "Failed to build query message(rc=%d)", rc );
            {
               MsgOpQuery *pReqMsg = (MsgOpQuery *)pBuffer;
               pReqMsg->version = pSrc->version;
               pReqMsg->w = pSrc->w;
            }
            rc = rtnCoordGetGroupInfo( cb, iterGroup->first, FALSE,
                                       groupInfo ) ;
            PD_CHECK( SDB_OK == rc, rc, RECV_MSG, PDERROR,
                      "Failed to get group info(groupId=%u, rc=%d)",
                      iterGroup->first, rc ) ;
            rc = rtnCoordSendRequestToOne( pBuffer, groupInfo, sendNodes,
                                           pRouteAgent,
                                           MSG_ROUTE_SHARD_SERVCIE, cb ) ;
            PD_CHECK( SDB_OK == rc, rc, RECV_MSG, PDERROR,
                      "Failed to send request(rc=%d)", rc ) ;
            ++iterGroup;
         }

      RECV_MSG:
         rcTmp = rtnCoordGetReply( cb, sendNodes, replyQue, MSG_BS_QUERY_RES ) ;
         if ( SDB_OK != rcTmp )
         {
            PD_LOG( PDWARNING, "failed to get reply(rcTmp=%d)", rcTmp );
            if ( SDB_APP_INTERRUPT == rcTmp || SDB_OK == rc )
            {
               rc = rcTmp;
            }
         }
         while( !replyQue.empty() )
         {
            takeOver             = FALSE ;
            MsgOpReply *pReply   = NULL;
            pReply               = (MsgOpReply *)(replyQue.front());
            rcTmp                = pReply->flags ;
            replyQue.pop();
            UINT32 groupID = pReply->header.routeID.columns.groupID;
            if ( rcTmp != SDB_OK )
            {
               if ( SDB_OK == rc )
               {
                  rc = rcTmp;
               }
               if ( SDB_DMS_EOC == rcTmp )
               {
                  sendGroupList[ groupID ] = groupID;
                  groupSubCLMap.erase( groupID );
                  rcTmp = SDB_OK;
               }
               else
               {
                  CoordGroupInfoPtr groupInfoTmp;
                  cb->getCoordSession()->removeLastNode( groupID );
                  if ( SDB_CLS_FULL_SYNC == rcTmp )
                  {
                     rtnCoordUpdateNodeStatByRC( pReply->header.routeID,
                                                rcTmp );
                  }
                  else
                  {
                     rcTmp = rtnCoordGetGroupInfo( cb, groupID, TRUE,
                                                   groupInfoTmp );
                     if ( rcTmp )
                     {
                        PD_LOG ( PDERROR, "Failed to update group info"
                                 "(groupID=%u, rc=%d)",
                                 pReply->header.routeID.columns.groupID,
                                 rcTmp );
                        if ( SDB_OK == rc )
                        {
                           rc = rcTmp;
                        }
                     }
                  }
               }
            }
            else
            {
               rcTmp = pContext->addSubContext( pReply, takeOver );
               if ( SDB_OK == rcTmp )
               {
                  sendGroupList[ groupID ] = groupID;
                  groupSubCLMap.erase( groupID );
               }
            }
            if ( rcTmp != SDB_OK && SDB_OK == rc )
            {
               rc = rcTmp;
            }

            if ( !takeOver )
            {
               SDB_OSS_FREE( pReply );
            }
         }
      }
      catch ( std::exception &e )
      {
         PD_RC_CHECK( SDB_INVALIDARG, PDERROR, "Occur unexpected error:%s",
                      e.what() ) ;
      }
   done:
      if ( pBuffer != NULL )
      {
         SDB_OSS_FREE( pBuffer );
         pBuffer = NULL;
      }
      return rc;
   error:
      goto done;
   }