Example #1
0
   // 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;
   }
Example #2
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCOINS_SENDTOGROUPS, "sendToGroups" )
   INT32 rtnCoordInsert::sendToGroups( const GroupInsertMsgMap &groupMsgMap,
                                       MsgOpInsert *pSrcMsg,
                                       netMultiRouteAgent *pRouteAgent,
                                       pmdEDUCB *cb,
                                       REQUESTID_MAP &sendNodes )
   {
      INT32 rc = SDB_OK;
      PD_TRACE_ENTRY ( SDB_RTNCOINS_SENDTOGROUPS ) ;
      SDB_ASSERT( pSrcMsg != NULL, "pSrcMsg can't be null!" );

      GroupInsertMsgMap::const_iterator iterMap = groupMsgMap.begin();
      INT32 headLen = ossRoundUpToMultipleX( offsetof(MsgOpInsert, name) +
                                             ossStrlen ( pSrcMsg->name ) + 1,
                                             4 ) ;
      while( iterMap != groupMsgMap.end() )
      {
         BSONObj boInsertor;
         CoordGroupList groupLst;
         groupLst[iterMap->first] = iterMap->first;
         if ( iterMap->second.dataList.size() == 0 )
         {
            ++iterMap ;
            continue ;
         }

         pSrcMsg->header.messageLength = headLen + iterMap->second.dataLen ;
         pSrcMsg->header.routeID.value = 0;
         rc = rtnCoordSendRequestToNodeGroups( (MsgHeader *)pSrcMsg,
                                               groupLst, TRUE, pRouteAgent,
                                               cb, iterMap->second.dataList,
                                               sendNodes ) ;
         PD_RC_CHECK( rc, PDERROR, "Failed to send the insert request to "
                      "group(goupID=%u)", iterMap->first ) ;
         ++iterMap ;
      }

   done:
      PD_TRACE_EXITRC ( SDB_RTNCOINS_SENDTOGROUPS, rc ) ;
      return rc ;
   error:
      goto done ;
   }
Example #3
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;
   }