Ejemplo 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;
   }
Ejemplo 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;
 }
Ejemplo 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;
   }
Ejemplo 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 ;
   }
Ejemplo n.º 5
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;
   }