コード例 #1
0
 INT32 rtnCoordTransCommit::executeOnDataGroup( CHAR * pMsg,
                                                netMultiRouteAgent * pRouteAgent,
                                                pmdEDUCB * cb )
 {
    INT32 rc = SDB_OK;
    REQUESTID_MAP requestIdMap;
    REPLY_QUE replyQue;
    MsgHeader *pMsgHead = (MsgHeader *)pMsg;
    DpsTransNodeMap *pNodeMap = cb->getTransNodeLst();
    DpsTransNodeMap::iterator iterMap = pNodeMap->begin();
    while( iterMap != pNodeMap->end() )
    {
       rc = rtnCoordSendRequestToNode( (void *)pMsg, iterMap->second,
                                       pRouteAgent, cb, requestIdMap );
       if ( rc )
       {
          rtnCoordClearRequest( cb, requestIdMap );
       }
       PD_RC_CHECK( rc, PDERROR,
                   "failed to send the request to the node"
                   "(groupID=%u, nodeID=%u, rc=%d). ",
                   iterMap->second.columns.groupID,
                   iterMap->second.columns.nodeID,
                   rc );
       ++iterMap;
    }
    rc = rtnCoordGetReply( cb, requestIdMap, replyQue,
                           MAKE_REPLY_TYPE( pMsgHead->opCode ) ) ;
    PD_RC_CHECK( rc, PDERROR,
                "failed to get the reply(rc=%d)",
                rc );
    while ( !replyQue.empty() )
    {
       MsgOpReply *pReply = NULL;
       pReply = (MsgOpReply *)(replyQue.front());
       replyQue.pop();
       INT32 rcTmp = pReply->flags;
       if ( rcTmp != SDB_OK )
       {
          rc = rc ? rc : rcTmp;
          PD_LOG( PDERROR,
                "failed to execute on data node(rc=%d, groupID=%u, nodeID=%u)",
                rcTmp, pReply->header.routeID.columns.groupID,
                pReply->header.routeID.columns.nodeID );
       }
       SDB_OSS_FREE( pReply );
    }
    if ( rc )
    {
       goto error;
    }
 done:
    return rc;
 error:
    goto done;
 }
コード例 #2
0
ファイル: rtnCoordInsert.cpp プロジェクト: Niwalker/SequoiaDB
   // PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCOINS_INSTOGROUP, "rtnCoordInsert::insertToAGroup" )
   INT32 rtnCoordInsert::insertToAGroup( CHAR *pBuffer,
                                         UINT32 grpID,
                                         netMultiRouteAgent *pRouteAgent,
                                         pmdEDUCB *cb )
   {
      INT32 rc = SDB_OK;
      PD_TRACE_ENTRY ( SDB_RTNCOINS_INSTOGROUP ) ;
      BOOLEAN isNeedRetry = FALSE;
      BOOLEAN hasRetry = FALSE;
      CoordGroupList groupLst;
      CoordGroupList successGroupLst;
      groupLst[grpID] = grpID;
      MsgHeader *pHead = (MsgHeader *)pBuffer ;

      if ( cb->isTransaction() )
      {
         pHead->opCode = MSG_BS_TRANS_INSERT_REQ;
      }
      do
      {
         hasRetry = isNeedRetry;
         isNeedRetry = FALSE;
         REQUESTID_MAP sendNodes;
         rc = rtnCoordSendRequestToNodeGroups( pBuffer, groupLst, TRUE,
                                               pRouteAgent, cb, sendNodes );
         if ( rc )
         {
            rtnCoordClearRequest( cb, sendNodes );
         }
         PD_RC_CHECK( rc, PDERROR, "Failed to insert on data-node, "
                      "send request failed(rc=%d)", rc ) ;

         REPLY_QUE replyQue;
         rc = rtnCoordGetReply( cb, sendNodes, replyQue,
                                MAKE_REPLY_TYPE( pHead->opCode ) );
         PD_RC_CHECK( rc, PDWARNING, "Failed to insert on data-node, "
                      "get reply failed(rc=%d)", rc );

         rc = processReply( replyQue, successGroupLst, cb );
         if ( SDB_CLS_NOT_PRIMARY == rc && !hasRetry )
         {
            isNeedRetry = TRUE;
            rc = SDB_OK;
         }
         PD_RC_CHECK( rc, PDWARNING, "Failed to process the reply(rc=%d)",
                      rc );
      } while ( isNeedRetry );

   done:
      PD_TRACE_EXITRC ( SDB_RTNCOINS_INSTOGROUP, rc ) ;
      return rc;
   error:
      goto done;
   }
コード例 #3
0
ファイル: coordSession.cpp プロジェクト: 2015520/SequoiaDB
   // PD_TRACE_DECLARE_FUNCTION ( SDB_COORDSN_CHECKREMOTEROUTEID, "CoordSession::checkRemoteRouteID" )
   INT32 CoordSession::checkRemoteRouteID( const MsgRouteID & routeID )
   {
      INT32 rc = SDB_OK;
      PD_TRACE_ENTRY ( SDB_COORDSN_CHECKREMOTEROUTEID );
      netMultiRouteAgent *pRouteAgent = pmdGetKRCB()->getCoordCB()->getRouteAgent();
      SDB_ASSERT( _pEduCB, "_pEduCB can't be NULL!" );
      MsgCoordCheckRouteID msgReq;
      msgReq.header.requestID = 0;
      msgReq.header.messageLength = sizeof( MsgCoordCheckRouteID );
      msgReq.header.opCode = MSG_COOR_CHECK_ROUTEID_REQ;
      msgReq.header.routeID.value = 0;
      msgReq.header.TID = _pEduCB->getTID();
      msgReq.dstRouteID = routeID;
      REQUESTID_MAP requestIdMap;
      REPLY_QUE replyQue;

      rc = rtnCoordSendRequestToNodeWithoutCheck( (void *)(&msgReq), routeID,
                                                pRouteAgent, _pEduCB,
                                                requestIdMap );
      PD_RC_CHECK( rc, PDERROR,
                  "failed to send the message to the node"
                  "(groupID=%u, nodeID=%u, serviceID=%u)",
                  routeID.columns.groupID,
                  routeID.columns.nodeID,
                  routeID.columns.serviceID );
      rc = rtnCoordGetReply( _pEduCB, requestIdMap, replyQue,
                             MSG_COOR_CHECK_ROUTEID_RSP );
      PD_RC_CHECK( rc, PDERROR,
                  "failed to get reply from node"
                  "(groupID=%u, nodeID=%u, serviceID=%u, rc=%d)",
                  routeID.columns.groupID,
                  routeID.columns.nodeID,
                  routeID.columns.serviceID,
                  rc );
      while ( !replyQue.empty() )
      {
         MsgOpReply *pReply = NULL;
         pReply = (MsgOpReply *)(replyQue.front());
         SDB_ASSERT( pReply, "pReply can't be NULL!" );
         replyQue.pop();
         rc = rc ? rc : pReply->flags;
         SDB_OSS_FREE( pReply );
      }
   done:
      PD_TRACE_EXIT ( SDB_COORDSN_CHECKREMOTEROUTEID );
      return rc;
   error:
      rtnCoordClearRequest( _pEduCB, requestIdMap );
      goto done;
   }
コード例 #4
0
ファイル: rtnCoordInsert.cpp プロジェクト: Niwalker/SequoiaDB
   //PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCOINS_INSTOGROUPS, "rtnCoordInsert::insertToGroups" )
   INT32 rtnCoordInsert::insertToGroups( const GroupInsertMsgMap &groupMsgMap,
                                         MsgOpInsert *pSrcMsg,
                                         netMultiRouteAgent *pRouteAgent,
                                         pmdEDUCB *cb,
                                         CoordGroupList &successGroupList )
   {
      INT32 rc = SDB_OK;
      PD_TRACE_ENTRY ( SDB_RTNCOINS_INSTOGROUPS ) ;
      SINT32 opCode;
      if ( cb->isTransaction() )
      {
         opCode = MSG_BS_TRANS_INSERT_REQ;
      }
      else
      {
         opCode = MSG_BS_INSERT_REQ;
      }
      REQUESTID_MAP sendNodes;
      REPLY_QUE replyQue;
      rc = sendToGroups( groupMsgMap, pSrcMsg, pRouteAgent,
                         cb, sendNodes ) ;
      if ( rc )
      {
         rtnCoordClearRequest( cb, sendNodes ) ;
      }
      PD_RC_CHECK( rc, PDERROR, "Failed to send the request(rc=%d)", rc );

      rc = rtnCoordGetReply( cb, sendNodes, replyQue,
                             MAKE_REPLY_TYPE( opCode ) ) ;
      PD_RC_CHECK( rc, PDWARNING, "Failed to insert on data-node, "
                   "get reply failed(rc=%d)", rc ) ;

      rc = processReply( replyQue, successGroupList, cb ) ;
      PD_RC_CHECK( rc, PDWARNING, "Failed to process the reply(rc=%d)", rc ) ;

   done:
      PD_TRACE_EXITRC ( SDB_RTNCOINS_INSTOGROUPS, rc ) ;
      return rc;
   error:
      goto done;
   }
コード例 #5
0
   INT32 rtnCoordTransCommit::executeOnDataGroup( MsgHeader *pMsg,
                                                  pmdEDUCB *cb,
                                                  INT64 &contextID,
                                                  rtnContextBuf *buf )
   {
      INT32 rc = SDB_OK ;
      INT32 rcTmp = SDB_OK ;
      netMultiRouteAgent *pAgent = pmdGetKRCB()->getCoordCB()->getRouteAgent() ;
      REQUESTID_MAP requestIdMap ;
      REPLY_QUE replyQue;
      DpsTransNodeMap *pNodeMap = cb->getTransNodeLst();
      DpsTransNodeMap::iterator iterMap = pNodeMap->begin();

      while( iterMap != pNodeMap->end() )
      {
         rcTmp = rtnCoordSendRequestToNode( (void *)pMsg, iterMap->second,
                                            pAgent, cb, requestIdMap ) ;
         if ( rcTmp )
         {
            rc = rc ? rc : rcTmp ;
            PD_LOG ( PDWARNING, "Failed to send commit request to the "
                     "node[%s], rc: %d",
                     routeID2String( iterMap->second ).c_str(),
                     rcTmp ) ;
         }
         ++iterMap ;
      }

      rcTmp = rtnCoordGetReply( cb, requestIdMap, replyQue,
                                MAKE_REPLY_TYPE( pMsg->opCode ) ) ;
      if ( rcTmp )
      {
         rc = rc ? rc : rcTmp ;
         PD_LOG( PDERROR, "Failed to get the reply, rc: %d", rcTmp ) ;
      }

      while ( !replyQue.empty() )
      {
         MsgOpReply *pReply = NULL;
         pReply = (MsgOpReply *)(replyQue.front());
         replyQue.pop();
         rcTmp = pReply->flags ;

         if ( rcTmp != SDB_OK )
         {
            rc = rc ? rc : rcTmp;
            PD_LOG( PDERROR, "Data node[%s] commit transaction failed, rc: %d",
                    routeID2String( pReply->header.routeID ).c_str(),
                    rcTmp ) ;
         }
         SDB_OSS_FREE( pReply ) ;
      }

      if ( rc )
      {
         goto error ;
      }
   done:
      return rc ;
   error:
      goto done ;
   }
コード例 #6
0
ファイル: rtnCoordQuery.cpp プロジェクト: 247687009/SequoiaDB
   // PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCOQUERY_QUERYTODNGROUP, "rtnCoordQuery::queryToDataNodeGroup" )
   INT32 rtnCoordQuery::queryToDataNodeGroup( CHAR *pBuffer,
                                              CoordGroupList &groupLst,
                                              CoordGroupList &sendGroupLst,
                                              netMultiRouteAgent *pRouteAgent,
                                              pmdEDUCB *cb,
                                              rtnContextCoord *pContext,
                                              BOOLEAN sendToPrimary,
                                              std::set<INT32> *ignoreRCList )
   {
      INT32 rc = SDB_OK;
      INT32 rcTmp = SDB_OK;
      PD_TRACE_ENTRY ( SDB_RTNCOQUERY_QUERYTODNGROUP ) ;
      BOOLEAN isNeedRetry = FALSE;
      BOOLEAN hasRetry = FALSE;
      MsgHeader *pHead = (MsgHeader *)pBuffer;
      SINT32 resCode = MAKE_REPLY_TYPE(pHead->opCode);
      BOOLEAN takeOver = FALSE ;

      do
      {
         hasRetry = isNeedRetry;
         isNeedRetry = FALSE;
         REQUESTID_MAP sendNodes;
         rcTmp= rtnCoordSendRequestToNodeGroups( pBuffer, groupLst,
                                                 sendToPrimary, pRouteAgent,
                                                 cb, sendNodes );
         if ( rcTmp != SDB_OK )
         {
            PD_LOG ( PDERROR, "Failed to query on data-node, send request "
                     "failed(rc=%d)", rcTmp ) ;
            if ( SDB_OK == rc )
            {
               rc = rcTmp;
            }
         }

         REPLY_QUE replyQue;
         rcTmp = rtnCoordGetReply( cb, sendNodes, replyQue, resCode ) ;
         if ( rcTmp != SDB_OK )
         {
            PD_LOG ( PDWARNING, "Failed to query on data-node, get reply "
                     "failed(rc=%d)", rcTmp );
            if ( SDB_APP_INTERRUPT == rcTmp || SDB_OK == rc )
            {
               rc = rcTmp;
            }
         }

         while ( !replyQue.empty() )
         {
            MsgOpReply *pReply   = NULL;
            takeOver             = FALSE ;
            pReply               = (MsgOpReply *)(replyQue.front());
            rcTmp                = pReply->flags;
            replyQue.pop();
            UINT32 groupID = pReply->header.routeID.columns.groupID;

            if ( rcTmp != SDB_OK )
            {
               if ( SDB_DMS_EOC == rcTmp ||
                    ( ignoreRCList != NULL &&
                      ignoreRCList->find( rcTmp ) != ignoreRCList->end() ) )
               {
                  sendGroupLst[ groupID ] = groupID;
                  groupLst.erase( groupID );
                  rcTmp = SDB_OK;
               }
               else
               {
                  cb->getCoordSession()->removeLastNode( groupID );
                  if ( SDB_CLS_FULL_SYNC == rcTmp )
                  {
                     rtnCoordUpdateNodeStatByRC( pReply->header.routeID,
                                                 rcTmp );
                  }
                  if ( !hasRetry )
                  {
                     if ( SDB_CLS_FULL_SYNC == rcTmp )
                     {
                        isNeedRetry = TRUE;
                     }
                     else if ( SDB_CLS_NOT_PRIMARY == rcTmp && sendToPrimary )
                     {
                        CoordGroupInfoPtr groupInfoTmp ;
                        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;
                           }
                        }
                        isNeedRetry = TRUE ;
                     }
                  }
               }
            }
            else
            {
               rcTmp = pContext->addSubContext( pReply, takeOver );
               if ( SDB_OK == rcTmp )
               {
                  sendGroupLst[ groupID ] = groupID;
                  groupLst.erase( groupID );
               }
            }

            if ( rcTmp != SDB_OK )
            {
               if ( SDB_OK == rc || SDB_CLS_COORD_NODE_CAT_VER_OLD == rc )
               {
                  rc = rcTmp;
               }
               PD_LOG( PDERROR, "Failed to query on data node"
                       "(groupID=%u, nodeID=%u, serviceID=%u, rc=%d)",
                       pReply->header.routeID.columns.groupID,
                       pReply->header.routeID.columns.nodeID,
                       pReply->header.routeID.columns.serviceID,
                       rcTmp );
            }
            if ( !takeOver )
            {
               SDB_OSS_FREE( pReply ) ;
            }
         }

         if ( rc != SDB_OK )
         {
            PD_LOG ( PDERROR, "Failed to query on data-node(rc=%d)", rc ) ;
            break;
         }
      }while ( isNeedRetry ) ;

      PD_TRACE_EXITRC ( SDB_RTNCOQUERY_QUERYTODNGROUP, rc ) ;
      return rc;
   }
コード例 #7
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;
   }