예제 #1
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCOQUERY_GETNODEGROUPS, "rtnCoordQuery::getNodeGroups" )
   INT32 rtnCoordQuery::getNodeGroups( const CoordCataInfoPtr &cataInfo,
                                       BSONObj &queryObj,
                                       const CoordGroupList &sendGroupLst,
                                       CoordGroupList &groupLst )
   {
      INT32 rc = SDB_OK;
      PD_TRACE_ENTRY ( SDB_RTNCOQUERY_GETNODEGROUPS ) ;

      cataInfo->getGroupByMatcher( queryObj, groupLst ) ;
      PD_CHECK( groupLst.size() > 0, SDB_CAT_NO_MATCH_CATALOG, error, PDERROR,
               "failed to get match groups" );
      {
      CoordGroupList::const_iterator iterList
                              = sendGroupLst.begin();
      while( iterList != sendGroupLst.end() )
      {
         groupLst.erase( iterList->first );
         ++iterList;
      }
      }

   done:
      PD_TRACE_EXITRC ( SDB_RTNCOQUERY_GETNODEGROUPS, rc ) ;
      return rc;
   error:
      goto done;
   }
예제 #2
0
 INT32 rtnCoordDelete::getNodeGroups( const CoordCataInfoPtr &cataInfo,
                         bson::BSONObj &deleteObj,
                         CoordGroupList &sendGroupLst,
                         CoordGroupList &groupLst )
 {
    INT32 rc = SDB_OK;
    PD_TRACE_ENTRY ( SDB_RTNCODEL_GETNODEGROUPS ) ;
    cataInfo->getGroupByMatcher( deleteObj, groupLst );
    if ( groupLst.size() <= 0 )
    {
       rc = SDB_CAT_NO_MATCH_CATALOG;
    }
    else
    {
       CoordGroupList::iterator iter = sendGroupLst.begin();
       while( iter != sendGroupLst.end() )
       {
          groupLst.erase( iter->first );
          ++iter;
       }
    }
    PD_TRACE_EXITRC ( SDB_RTNCODEL_GETNODEGROUPS, rc ) ;
    return rc;
 }
예제 #3
0
 // PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCODEL_DELTODNGROUP, "rtnCoordDelete::deleteToDataNodeGroup" )
 INT32 rtnCoordDelete::deleteToDataNodeGroup( CHAR *pBuffer,
                                              CoordGroupList &groupLst,
                                              CoordGroupList &sendGroupLst,
                                              netMultiRouteAgent *pRouteAgent,
                                              pmdEDUCB *cb )
 {
    INT32 rc = SDB_OK;
    PD_TRACE_ENTRY ( SDB_RTNCODEL_DELTODNGROUP ) ;
    BOOLEAN isNeedRetry = FALSE;
    BOOLEAN hasRetry = FALSE;
    MsgOpDelete *pDelMsg = (MsgOpDelete *)pBuffer;
    do
    {
       hasRetry = isNeedRetry;
       isNeedRetry = FALSE;
       REQUESTID_MAP sendNodes;
       if ( cb->isTransaction() )
       {
          pDelMsg->header.opCode = MSG_BS_TRANS_DELETE_REQ;
       }
       rc = rtnCoordSendRequestToNodeGroups( pBuffer, groupLst, TRUE,
                                             pRouteAgent, cb, sendNodes );
       if ( rc != SDB_OK )
       {
          rtnCoordClearRequest( cb, sendNodes );
          PD_LOG ( PDERROR, "failed to delete on data-node,"
                   "send request failed(rc=%d)");
          break;
       }
       REPLY_QUE replyQue;
       rc = rtnCoordGetReply( cb, sendNodes, replyQue,
                      MAKE_REPLY_TYPE(pDelMsg->header.opCode) );
       if ( rc != SDB_OK )
       {
          PD_LOG ( PDWARNING, "failed to delete on data-node,"
                   "get reply failed(rc=%d)", rc );
          break;
       }
       while ( !replyQue.empty() )
       {
          MsgOpReply *pReply = NULL;
          pReply = (MsgOpReply *)(replyQue.front());
          replyQue.pop();
          INT32 rcTmp = pReply->flags;
          if ( SDB_OK == rc || SDB_CLS_COORD_NODE_CAT_VER_OLD == rc )
          {
             if ( SDB_OK != rcTmp )
             {
                if ( SDB_CLS_NOT_PRIMARY == rcTmp
                   && !hasRetry )
                {
                   CoordGroupInfoPtr groupInfoTmp;
                   rcTmp = rtnCoordGetGroupInfo( cb,
                      pReply->header.routeID.columns.groupID,
                      TRUE, groupInfoTmp );
                   if ( SDB_OK == rcTmp )
                   {
                      isNeedRetry = TRUE;
                   }
                }
                if ( rcTmp )
                {
                   rc = rcTmp ;
                   PD_LOG ( PDERROR, "failed to delete 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,
                            rc );
                }
             }
             else
             {
                UINT32 groupID = pReply->header.routeID.columns.groupID ;
                sendGroupLst[groupID] = groupID;
                groupLst.erase( groupID );
             }
          }
          if ( NULL != pReply )
          {
             SDB_OSS_FREE( pReply );
          }
       }
    }while ( isNeedRetry );
    PD_TRACE_EXITRC ( SDB_RTNCODEL_DELTODNGROUP, rc ) ;
    return rc;
 }
예제 #4
0
   INT32 rtnCoordInsert::insertToMainCL( const CoordCataInfoPtr &cataInfo,
                                         CHAR *pReceiveBuffer,
                                         CHAR *pInsertor, INT32 count,
                                         netMultiRouteAgent *pRouteAgent,
                                         pmdEDUCB *cb,
                                         GroupSubCLMap &groupSubCLMap )
   {
      INT32 rc = SDB_OK ;
      INT32 filler = 0 ;
      GroupInsertMsgMap groupMsgMap ;
      CoordGroupList successGroupList ;
      std::vector< BSONObj > subCLInfoCache ;

      if ( groupSubCLMap.size() == 0 )
      {
         rc = shardDataByGroup( cataInfo, count, pInsertor, cb,
                                groupSubCLMap ) ;
      }
      else
      {
         rc = reshardData( cataInfo, cb, groupSubCLMap );
      }
      PD_RC_CHECK( rc, PDERROR, "Failed to shard the data(rc=%d)", rc ) ;

      if ( cb->isTransaction() )
      {
         CoordGroupList groupLst;
         GroupSubCLMap::iterator iterMap = groupSubCLMap.begin();
         while( iterMap != groupSubCLMap.end() )
         {
            groupLst[ iterMap->first ] = iterMap->first;
            ++iterMap ;
         }
         rc = buildTransSession( groupLst, pRouteAgent, cb ) ;
         PD_RC_CHECK( rc, PDERROR, "Failed to build transaction "
                      "session(rc=%d)", rc ) ;
      }

      {
         CHAR *pHeadRemain = pReceiveBuffer + sizeof( MsgHeader );
         INT32 remainLen = pInsertor - pHeadRemain ;
         rc = buildInsertMsg( pHeadRemain, remainLen, groupSubCLMap,
                              subCLInfoCache, &filler, groupMsgMap );
         PD_RC_CHECK( rc, PDERROR, "Failed to build the message(rc=%d)",
                      rc ) ;
      }

      rc = insertToGroups( groupMsgMap, (MsgOpInsert *)pReceiveBuffer,
                           pRouteAgent, cb, successGroupList ) ;
      if ( rc != SDB_OK )
      {
         CoordGroupList::iterator iterSuc = successGroupList.begin() ;
         while( iterSuc != successGroupList.end() )
         {
            groupSubCLMap.erase( iterSuc->first );
            ++iterSuc ;
         }
         PD_LOG( PDWARNING, "failed to insert the data(rc=%d)", rc );
         goto error ;
      }
      else
      {
         groupSubCLMap.clear();
      }

   done:
      return rc;
   error:
      goto done;
   }
예제 #5
0
   INT32 rtnCoordInsert::insertToNormalCL( const CoordCataInfoPtr &cataInfo,
                                           CHAR *pReceiveBuffer,
                                           CHAR *pInsertor, INT32 count,
                                           netMultiRouteAgent *pRouteAgent,
                                           pmdEDUCB *cb,
                                           GroupObjsMap &groupObjsMap,
                                           BOOLEAN &hasSendSomeData )
   {
      INT32 rc = SDB_OK;
      INT32 filler = 0;
      GroupInsertMsgMap groupMsgMap;
      CoordGroupList successGroupList;

      if ( groupObjsMap.size() == 0 )
      {
         rc = shardDataByGroup( cataInfo, count, pInsertor, groupObjsMap ) ;
      }
      else
      {
         rc = reshardData( cataInfo, groupObjsMap ) ;
      }
      PD_RC_CHECK( rc, PDERROR, "Failed to shard the data by group(rc=%d)",
                   rc ) ;

      if ( cb->isTransaction() )
      {
         CoordGroupList groupLst ;
         GroupObjsMap::iterator iterGroup ;
         iterGroup = groupObjsMap.begin();
         while( iterGroup != groupObjsMap.end() )
         {
            groupLst[ iterGroup->first ] = iterGroup->first ;
            ++iterGroup ;
         }
         rc = buildTransSession( groupLst, pRouteAgent, cb ) ;
         PD_RC_CHECK( rc, PDERROR,
                      "Failed to build transaction session(rc=%d)",
                      rc ) ;
      }

      if ( groupObjsMap.size() == 1 && !hasSendSomeData )
      {
         GroupObjsMap::iterator iterMap = groupObjsMap.begin();
         rc = insertToAGroup( pReceiveBuffer, iterMap->first,
                              pRouteAgent, cb );
         PD_RC_CHECK( rc, PDERROR,
                      "Failed to insert on group(groupID:%u, rc=%d)",
                      iterMap->first, rc );
         successGroupList[iterMap->first] = iterMap->first ;
      }
      else
      {
         CHAR *pHeadRemain = pReceiveBuffer + sizeof( MsgHeader );
         INT32 remainLen = pInsertor - pHeadRemain;
         rc = buildInsertMsg( pHeadRemain, remainLen, groupObjsMap,
                              &filler, groupMsgMap ) ;
         PD_RC_CHECK( rc, PDERROR,"Failed to build the message(rc=%d)", rc );

         rc = insertToGroups( groupMsgMap, (MsgOpInsert *)pReceiveBuffer,
                              pRouteAgent, cb, successGroupList ) ;
         if ( successGroupList.size() != 0 )
         {
            hasSendSomeData = TRUE ;
         }
         if ( rc != SDB_OK )
         {
            CoordGroupList::iterator iterSuc = successGroupList.begin();
            while( iterSuc != successGroupList.end() )
            {
               groupObjsMap.erase( iterSuc->first ) ;
               ++iterSuc ;
            }
            PD_LOG( PDWARNING, "Failed to insert the data(rc=%d)", rc ) ;
            goto error ;
         }
         else
         {
            groupObjsMap.clear() ;
         }
      }

   done:
      return rc ;
   error:
      goto done ;
   }
예제 #6
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCOINS_EXECUTE, "rtnCoordInsert::execute" )
   INT32 rtnCoordInsert::execute( CHAR *pReceiveBuffer,
                                  SINT32 packSize,
                                  pmdEDUCB *cb,
                                  MsgOpReply &replyHeader,
                                  rtnContextBuf *buf )
   {
      INT32 rc = SDB_OK;
      PD_TRACE_ENTRY ( SDB_RTNCOINS_EXECUTE ) ;
      pmdKRCB *pKrcb                   = pmdGetKRCB();
      CoordCB *pCoordcb                = pKrcb->getCoordCB();
      netMultiRouteAgent *pRouteAgent  = pCoordcb->getRouteAgent();
      rtnCoordOperator *pRollbackOperator = NULL;

      MsgHeader *pHeader               = (MsgHeader *)pReceiveBuffer;
      replyHeader.header.messageLength = sizeof( MsgOpReply );
      replyHeader.header.opCode        = MSG_BS_INSERT_RES;
      replyHeader.header.requestID     = pHeader->requestID;
      replyHeader.header.routeID.value = 0;
      replyHeader.header.TID           = pHeader->TID;
      replyHeader.contextID            = -1;
      replyHeader.flags                = SDB_OK;
      replyHeader.numReturned          = 0;
      replyHeader.startFrom            = 0;
      MsgOpInsert *pSrcMsg = (MsgOpInsert *)pReceiveBuffer;
      BOOLEAN isNeedRefreshCata = FALSE;
      GroupObjsMap groupObjsMap;
      BOOLEAN hasSendSomeData = FALSE;
      GroupSubCLMap groupSubCLMap;

      INT32 flag = 0;
      CHAR *pCollectionName = NULL;
      CHAR *pInsertor = NULL;
      INT32 count = 0;
      rc = msgExtractInsert( pReceiveBuffer, &flag,
                             &pCollectionName, &pInsertor, count ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to parse insert request" );
      pSrcMsg->header.TID = cb->getTID();
      if ( cb->isTransaction() )
      {
         pSrcMsg->header.opCode = MSG_BS_TRANS_INSERT_REQ;
      }
      else
      {
         pSrcMsg->header.opCode = MSG_BS_INSERT_REQ;
      }

      while ( TRUE )
      {
         CoordCataInfoPtr cataInfo;
         rc = rtnCoordGetCataInfo( cb, pCollectionName, isNeedRefreshCata,
                                   cataInfo );
         PD_RC_CHECK( rc, PDERROR,
                      "Failed to get the catalog info(collection name:%s)",
                      pCollectionName );

         pSrcMsg->header.routeID.value = 0;
         pSrcMsg->version = cataInfo->getVersion();

         if ( !cataInfo->isSharded() )
         {
            CoordGroupList groupLst;
            cataInfo->getGroupLst( groupLst );
            PD_CHECK( groupLst.size() > 0, SDB_SYS, error,
                      PDERROR, "invalid catalog-info, no group-info" );
            rc = buildTransSession( groupLst, pRouteAgent, cb );
            PD_RC_CHECK( rc, PDERROR,
                         "Failed to build transaction session(rc=%d)",
                         rc );

            CoordGroupList::iterator iterLst = groupLst.begin();
            rc = insertToAGroup( pReceiveBuffer, iterLst->first, pRouteAgent, cb );
         }//end of if ( !cataInfo->isSharded() )
         else if( !cataInfo->isMainCL() )
         {
            rc = insertToNormalCL( cataInfo, pReceiveBuffer, pInsertor,
                                   count, pRouteAgent, cb, groupObjsMap,
                                   hasSendSomeData ) ;
         }//end of else if( !cataInfo->isMainCL() )
         else
         {
            rc = insertToMainCL( cataInfo, pReceiveBuffer, pInsertor,
                                 count, pRouteAgent, cb, groupSubCLMap ) ;
         }
         if ( SDB_OK != rc )
         {
            if ( !isNeedRefreshCata
                 && ( (!cb->isTransaction() && rtnCoordWriteRetryRC( rc ))
                      || SDB_CLS_COORD_NODE_CAT_VER_OLD == rc
                      || SDB_CLS_NO_CATALOG_INFO == rc
                      || SDB_CAT_NO_MATCH_CATALOG == rc ))
            {
               isNeedRefreshCata = TRUE;
               continue;
            }
            if ( SDB_CLS_COORD_NODE_CAT_VER_OLD == rc )
            {
               rc = SDB_CAT_NO_MATCH_CATALOG;
            }
            PD_RC_CHECK ( rc, PDERROR, "Failed to insert the record to "
                          "data-node, rc = %d", rc ) ;
         }
         break;
      }
      if ( cb->isTransaction() )
      {
         rc = rc ? rc : cb->getTransRC();
      }
      if ( rc )
      {
         goto error;
      }
   done:
      PD_TRACE_EXITRC ( SDB_RTNCOINS_EXECUTE, rc ) ;
      return rc;
   error:
      if ( cb->isTransaction() )
      {
         pRollbackOperator
               = pCoordcb->getProcesserFactory()->getOperator( MSG_BS_TRANS_ROLLBACK_REQ );
         if ( pRollbackOperator )
         {
            pRollbackOperator->execute( pReceiveBuffer, packSize,
                                       cb, replyHeader, NULL );
         }
      }
      replyHeader.flags = rc;
      goto done;
   }
예제 #7
0
   // 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;
   }