INT32 rtnCoordTransCommit::executeOnDataGroup( CHAR * pMsg, netMultiRouteAgent * pRouteAgent, pmdEDUCB * cb ) { INT32 rc = SDB_OK; REQUESTID_MAP requestIdMap; REPLY_QUE replyQue; MsgHeader *pMsgHead = (MsgHeader *)pMsg; DpsTransNodeMap *pNodeMap = cb->getTransNodeLst(); DpsTransNodeMap::iterator iterMap = pNodeMap->begin(); while( iterMap != pNodeMap->end() ) { rc = rtnCoordSendRequestToNode( (void *)pMsg, iterMap->second, pRouteAgent, cb, requestIdMap ); if ( rc ) { rtnCoordClearRequest( cb, requestIdMap ); } PD_RC_CHECK( rc, PDERROR, "failed to send the request to the node" "(groupID=%u, nodeID=%u, rc=%d). ", iterMap->second.columns.groupID, iterMap->second.columns.nodeID, rc ); ++iterMap; } rc = rtnCoordGetReply( cb, requestIdMap, replyQue, MAKE_REPLY_TYPE( pMsgHead->opCode ) ) ; PD_RC_CHECK( rc, PDERROR, "failed to get the reply(rc=%d)", rc ); while ( !replyQue.empty() ) { MsgOpReply *pReply = NULL; pReply = (MsgOpReply *)(replyQue.front()); replyQue.pop(); INT32 rcTmp = pReply->flags; if ( rcTmp != SDB_OK ) { rc = rc ? rc : rcTmp; PD_LOG( PDERROR, "failed to execute on data node(rc=%d, groupID=%u, nodeID=%u)", rcTmp, pReply->header.routeID.columns.groupID, pReply->header.routeID.columns.nodeID ); } SDB_OSS_FREE( pReply ); } if ( rc ) { goto error; } done: return rc; error: goto done; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_COORDSN_CHECKREMOTEROUTEID, "CoordSession::checkRemoteRouteID" ) INT32 CoordSession::checkRemoteRouteID( const MsgRouteID & routeID ) { INT32 rc = SDB_OK; PD_TRACE_ENTRY ( SDB_COORDSN_CHECKREMOTEROUTEID ); netMultiRouteAgent *pRouteAgent = pmdGetKRCB()->getCoordCB()->getRouteAgent(); SDB_ASSERT( _pEduCB, "_pEduCB can't be NULL!" ); MsgCoordCheckRouteID msgReq; msgReq.header.requestID = 0; msgReq.header.messageLength = sizeof( MsgCoordCheckRouteID ); msgReq.header.opCode = MSG_COOR_CHECK_ROUTEID_REQ; msgReq.header.routeID.value = 0; msgReq.header.TID = _pEduCB->getTID(); msgReq.dstRouteID = routeID; REQUESTID_MAP requestIdMap; REPLY_QUE replyQue; rc = rtnCoordSendRequestToNodeWithoutCheck( (void *)(&msgReq), routeID, pRouteAgent, _pEduCB, requestIdMap ); PD_RC_CHECK( rc, PDERROR, "failed to send the message to the node" "(groupID=%u, nodeID=%u, serviceID=%u)", routeID.columns.groupID, routeID.columns.nodeID, routeID.columns.serviceID ); rc = rtnCoordGetReply( _pEduCB, requestIdMap, replyQue, MSG_COOR_CHECK_ROUTEID_RSP ); PD_RC_CHECK( rc, PDERROR, "failed to get reply from node" "(groupID=%u, nodeID=%u, serviceID=%u, rc=%d)", routeID.columns.groupID, routeID.columns.nodeID, routeID.columns.serviceID, rc ); while ( !replyQue.empty() ) { MsgOpReply *pReply = NULL; pReply = (MsgOpReply *)(replyQue.front()); SDB_ASSERT( pReply, "pReply can't be NULL!" ); replyQue.pop(); rc = rc ? rc : pReply->flags; SDB_OSS_FREE( pReply ); } done: PD_TRACE_EXIT ( SDB_COORDSN_CHECKREMOTEROUTEID ); return rc; error: rtnCoordClearRequest( _pEduCB, requestIdMap ); goto done; }
// 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; }
INT32 rtnCoordTransCommit::executeOnDataGroup( MsgHeader *pMsg, pmdEDUCB *cb, INT64 &contextID, rtnContextBuf *buf ) { INT32 rc = SDB_OK ; INT32 rcTmp = SDB_OK ; netMultiRouteAgent *pAgent = pmdGetKRCB()->getCoordCB()->getRouteAgent() ; REQUESTID_MAP requestIdMap ; REPLY_QUE replyQue; DpsTransNodeMap *pNodeMap = cb->getTransNodeLst(); DpsTransNodeMap::iterator iterMap = pNodeMap->begin(); while( iterMap != pNodeMap->end() ) { rcTmp = rtnCoordSendRequestToNode( (void *)pMsg, iterMap->second, pAgent, cb, requestIdMap ) ; if ( rcTmp ) { rc = rc ? rc : rcTmp ; PD_LOG ( PDWARNING, "Failed to send commit request to the " "node[%s], rc: %d", routeID2String( iterMap->second ).c_str(), rcTmp ) ; } ++iterMap ; } rcTmp = rtnCoordGetReply( cb, requestIdMap, replyQue, MAKE_REPLY_TYPE( pMsg->opCode ) ) ; if ( rcTmp ) { rc = rc ? rc : rcTmp ; PD_LOG( PDERROR, "Failed to get the reply, rc: %d", rcTmp ) ; } while ( !replyQue.empty() ) { MsgOpReply *pReply = NULL; pReply = (MsgOpReply *)(replyQue.front()); replyQue.pop(); rcTmp = pReply->flags ; if ( rcTmp != SDB_OK ) { rc = rc ? rc : rcTmp; PD_LOG( PDERROR, "Data node[%s] commit transaction failed, rc: %d", routeID2String( pReply->header.routeID ).c_str(), rcTmp ) ; } SDB_OSS_FREE( pReply ) ; } if ( rc ) { goto error ; } done: return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCOINS_PROREPLY, "rtnCoordInsert::processReply" ) INT32 rtnCoordInsert::processReply( REPLY_QUE &replyQue, CoordGroupList &successGroupList, pmdEDUCB *cb ) { INT32 rc = SDB_OK; PD_TRACE_ENTRY ( SDB_RTNCOINS_PROREPLY ) ; while ( !replyQue.empty() ) { MsgOpReply *pReply = NULL; pReply = (MsgOpReply *)(replyQue.front()); replyQue.pop(); if ( NULL == pReply ) { PD_LOG ( PDWARNING, "reply is null"); continue; } INT32 rcTmp = pReply->flags; if ( SDB_OK == rcTmp ) { successGroupList[pReply->header.routeID.columns.groupID] = pReply->header.routeID.columns.groupID; } else { PD_LOG ( PDERROR, "Failed to execute 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 ( SDB_CLS_NOT_PRIMARY == rcTmp ) { rc = rc ? rc : rcTmp ; CoordGroupInfoPtr groupInfoTmp ; rcTmp = rtnCoordGetGroupInfo( cb, pReply->header.routeID.columns.groupID, TRUE, groupInfoTmp ) ; if ( rcTmp ) { rc = rcTmp ; PD_LOG ( PDERROR, "Failed to update group " "info(groupID=%u, rc=%d)", pReply->header.routeID.columns.groupID, rc ) ; } } else if ( SDB_CLS_COORD_NODE_CAT_VER_OLD == rcTmp ) { if ( SDB_OK == rc || SDB_CLS_NOT_PRIMARY == rc ) { rc = SDB_CLS_COORD_NODE_CAT_VER_OLD ; } } else { rc = rcTmp ; } } SDB_OSS_FREE( pReply ) ; } PD_TRACE_EXITRC ( SDB_RTNCOINS_PROREPLY, rc ) ; return rc ; }
// 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; }
INT32 rtnCoordQuery::queryOnMainCL( CoordGroupSubCLMap &groupSubCLMap, MsgOpQuery *pSrc, pmdEDUCB *cb, netMultiRouteAgent *pRouteAgent, CoordGroupList &sendGroupList, rtnContextCoord *pContext ) { INT32 rc = SDB_OK; INT32 rcTmp = SDB_OK; CHAR *pBuffer = NULL; INT32 bufferSize = 0; REPLY_QUE replyQue; BOOLEAN takeOver = FALSE ; SDB_ASSERT( pContext, "pContext can't be NULL!" ); try { CoordGroupSubCLMap::iterator iterGroup; REQUESTID_MAP sendNodes; INT32 flag; CHAR *pCollectionName; SINT64 numToSkip; SINT64 numToReturn; CHAR *pQuery; CHAR *pFieldSelector; CHAR *pOrderBy; CHAR *pHint; BSONObj boQuery; BSONObj boFieldSelector; BSONObj boOrderBy; BSONObj boHint; rc = msgExtractQuery( (CHAR *)pSrc, &flag, &pCollectionName, &numToSkip, &numToReturn, &pQuery, &pFieldSelector, &pOrderBy, &pHint ); PD_RC_CHECK( rc, PDERROR, "failed to parse query message(rc=%d)", rc ); boQuery = BSONObj( pQuery ); boFieldSelector = BSONObj( pFieldSelector ); boOrderBy = BSONObj( pOrderBy ); boHint = BSONObj( pHint ); iterGroup = groupSubCLMap.begin(); while( iterGroup != groupSubCLMap.end() ) { BSONArrayBuilder babSubCL; CoordGroupInfoPtr groupInfo; CoordSubCLlist::iterator iterSubCL = iterGroup->second.begin(); while( iterSubCL != iterGroup->second.end() ) { babSubCL.append( *iterSubCL ); ++iterSubCL; } BSONObjBuilder bobNewQuery; bobNewQuery.appendElements( boQuery ); bobNewQuery.appendArray( CAT_SUBCL_NAME, babSubCL.arr() ); BSONObj boNewQuery = bobNewQuery.obj(); rc = msgBuildQueryMsg( &pBuffer, &bufferSize, pCollectionName, flag, 0, numToSkip, numToReturn, &boNewQuery, &boFieldSelector, &boOrderBy, &boHint ); PD_CHECK( SDB_OK == rc, rc, RECV_MSG, PDERROR, "Failed to build query message(rc=%d)", rc ); { MsgOpQuery *pReqMsg = (MsgOpQuery *)pBuffer; pReqMsg->version = pSrc->version; pReqMsg->w = pSrc->w; } rc = rtnCoordGetGroupInfo( cb, iterGroup->first, FALSE, groupInfo ) ; PD_CHECK( SDB_OK == rc, rc, RECV_MSG, PDERROR, "Failed to get group info(groupId=%u, rc=%d)", iterGroup->first, rc ) ; rc = rtnCoordSendRequestToOne( pBuffer, groupInfo, sendNodes, pRouteAgent, MSG_ROUTE_SHARD_SERVCIE, cb ) ; PD_CHECK( SDB_OK == rc, rc, RECV_MSG, PDERROR, "Failed to send request(rc=%d)", rc ) ; ++iterGroup; } RECV_MSG: rcTmp = rtnCoordGetReply( cb, sendNodes, replyQue, MSG_BS_QUERY_RES ) ; if ( SDB_OK != rcTmp ) { PD_LOG( PDWARNING, "failed to get reply(rcTmp=%d)", rcTmp ); if ( SDB_APP_INTERRUPT == rcTmp || SDB_OK == rc ) { rc = rcTmp; } } while( !replyQue.empty() ) { takeOver = FALSE ; MsgOpReply *pReply = NULL; pReply = (MsgOpReply *)(replyQue.front()); rcTmp = pReply->flags ; replyQue.pop(); UINT32 groupID = pReply->header.routeID.columns.groupID; if ( rcTmp != SDB_OK ) { if ( SDB_OK == rc ) { rc = rcTmp; } if ( SDB_DMS_EOC == rcTmp ) { sendGroupList[ groupID ] = groupID; groupSubCLMap.erase( groupID ); rcTmp = SDB_OK; } else { CoordGroupInfoPtr groupInfoTmp; cb->getCoordSession()->removeLastNode( groupID ); if ( SDB_CLS_FULL_SYNC == rcTmp ) { rtnCoordUpdateNodeStatByRC( pReply->header.routeID, rcTmp ); } else { 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; } } } } } else { rcTmp = pContext->addSubContext( pReply, takeOver ); if ( SDB_OK == rcTmp ) { sendGroupList[ groupID ] = groupID; groupSubCLMap.erase( groupID ); } } if ( rcTmp != SDB_OK && SDB_OK == rc ) { rc = rcTmp; } if ( !takeOver ) { SDB_OSS_FREE( pReply ); } } } catch ( std::exception &e ) { PD_RC_CHECK( SDB_INVALIDARG, PDERROR, "Occur unexpected error:%s", e.what() ) ; } done: if ( pBuffer != NULL ) { SDB_OSS_FREE( pBuffer ); pBuffer = NULL; } return rc; error: goto done; }