Пример #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
   // 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;
   }