Exemplo n.º 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;
   }
Exemplo n.º 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;
 }
Exemplo n.º 3
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;
   }
Exemplo n.º 4
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 ;
   }