// PD_TRACE_DECLARE_FUNCTION ( SDB__CLSCATCLR_CALL, "_clsCatalogCaller::call" ) INT32 _clsCatalogCaller::call( MsgHeader *header ) { SDB_ASSERT( NULL != header, "header should not be NULL" ) ; INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__CLSCATCLR_CALL ); _clsCataCallerMeta &meta = _meta[MAKE_REPLY_TYPE(header->opCode)] ; if ( (SINT32)meta.bufLen < header->messageLength ) { if ( NULL != meta.header ) { SDB_OSS_FREE( meta.header ) ; meta.bufLen = 0 ; } meta.header = ( MsgHeader *)SDB_OSS_MALLOC( header->messageLength ) ; if ( NULL == meta.header ) { PD_LOG ( PDERROR, "Failed to allocate memory for header" ) ; rc = SDB_OOM ; goto error ; } meta.bufLen = header->messageLength ; } ossMemcpy( meta.header, header, header->messageLength ) ; PD_LOG( PDEVENT, "send msg[%d] to catalog node.", meta.header->opCode ) ; pmdGetKRCB()->getClsCB()->sendToCatlog( meta.header ) ; meta.timeout = 0 ; done: PD_TRACE_EXITRC ( SDB__CLSCATCLR_CALL, rc ); return rc ; error: goto done ; }
INT32 _mongoSession::_onMsgBegin( MsgHeader *msg ) { _replyHeader.contextID = 0 ; _replyHeader.numReturned = 0 ; _replyHeader.startFrom = 0 ; _replyHeader.header.opCode = MAKE_REPLY_TYPE(msg->opCode) ; _replyHeader.header.requestID = msg->requestID ; _replyHeader.header.TID = msg->TID ; _replyHeader.header.routeID = engine::pmdGetNodeID() ; if ( MSG_BS_INTERRUPTE == msg->opCode || MSG_BS_INTERRUPTE_SELF == msg->opCode || MSG_BS_DISCONNECT == msg->opCode ) { _needReply = FALSE ; } else if ( MSG_BS_INSERT_REQ == msg->opCode || MSG_BS_DELETE_REQ == msg->opCode || MSG_BS_UPDATE_REQ == msg->opCode ) { _needReply = FALSE ; } else { _needReply = TRUE ; } MON_START_OP( _pEDUCB->getMonAppCB() ) ; return SDB_OK ; }
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_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; }
BOOLEAN _mongoSession::_preProcessMsg( msgParser &parser, engine::IResource *resource, engine::rtnContextBuf &buff ) { BOOLEAN handled = FALSE ; mongoDataPacket &packet = parser.dataPacket() ; if ( OP_CMD_ISMASTER == parser.currentOption() ) { handled = TRUE ; fap::mongo::buildIsMasterReplyMsg( resource, buff ) ; } else if ( OP_CMD_GETNONCE == parser.currentOption() ) { handled = TRUE ; bson::BSONObj obj ; obj.init( _inBuffer.data() ) ; buff = engine::rtnContextBuf( obj ) ; } else if ( OP_CMD_GETLASTERROR == parser.currentOption() ) { handled = TRUE ; fap::mongo::buildGetLastErrorReplyMsg( _errorInfo, buff ) ; } else if ( OP_CMD_NOT_SUPPORTED == parser.currentOption() ) { handled = TRUE ; fap::mongo::buildNotSupportReplyMsg( _contextBuff, packet.all.firstElementFieldName() ) ; } else if ( OP_CMD_PING == parser.currentOption() ) { handled = TRUE ; fap::mongo::buildPingReplyMsg( _contextBuff ) ; } if ( handled ) { _replyHeader.contextID = -1 ; _replyHeader.numReturned = 1 ; _replyHeader.startFrom = 0 ; _replyHeader.header.opCode = MAKE_REPLY_TYPE(packet.opCode) ; _replyHeader.header.requestID = packet.requestId ; _replyHeader.header.TID = 0 ; _replyHeader.header.routeID.value = 0 ; _replyHeader.flags = SDB_OK ; } return handled ; }
INT32 _mongoSession::_onMsgBegin( MsgHeader *msg ) { _replyHeader.contextID = -1 ; _replyHeader.numReturned = 0 ; _replyHeader.startFrom = 0 ; _replyHeader.header.opCode = MAKE_REPLY_TYPE(msg->opCode) ; _replyHeader.header.requestID = msg->requestID ; _replyHeader.header.TID = msg->TID ; _replyHeader.header.routeID = engine::pmdGetNodeID() ; MON_START_OP( _pEDUCB->getMonAppCB() ) ; return SDB_OK ; }
INT32 _pmdCoordProcessor::processMsg( MsgHeader *msg, rtnContextBuf &contextBuff, INT64 &contextID, BOOLEAN &needReply ) { INT32 rc = SDB_OK ; ossMemset( &_replyHeader, 0, sizeof( _replyHeader ) ) ; _replyHeader.header.messageLength = sizeof( MsgOpReply ) ; _replyHeader.header.opCode = MAKE_REPLY_TYPE( msg->opCode ) ; _replyHeader.header.requestID = msg->requestID ; _replyHeader.header.routeID.value = pmdGetNodeID().value ; _replyHeader.header.TID = msg->TID ; _replyHeader.contextID = -1 ; _replyHeader.flags = SDB_OK ; _replyHeader.numReturned = 0 ; _replyHeader.startFrom = 0 ; rc = _processCoordMsg( msg, _replyHeader, contextBuff ) ; if ( SDB_COORD_UNKNOWN_OP_REQ == rc ) { contextBuff.release() ; rc = _pmdDataProcessor::processMsg( msg, contextBuff, contextID, needReply ) ; } else if ( SDB_OK == rc ) { contextID = _replyHeader.contextID ; } if ( rc ) { if ( SDB_APP_INTERRUPT == rc ) { PD_LOG ( PDINFO, "Agent is interrupt" ) ; } else if ( SDB_DMS_EOC != rc ) { PD_LOG ( PDERROR, "Error processing Agent request, rc=%d", rc ) ; } } return rc ; }
//PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCOINS_INSTOGROUPS, "rtnCoordInsert::insertToGroups" ) INT32 rtnCoordInsert::insertToGroups( const GroupInsertMsgMap &groupMsgMap, MsgOpInsert *pSrcMsg, netMultiRouteAgent *pRouteAgent, pmdEDUCB *cb, CoordGroupList &successGroupList ) { INT32 rc = SDB_OK; PD_TRACE_ENTRY ( SDB_RTNCOINS_INSTOGROUPS ) ; SINT32 opCode; if ( cb->isTransaction() ) { opCode = MSG_BS_TRANS_INSERT_REQ; } else { opCode = MSG_BS_INSERT_REQ; } REQUESTID_MAP sendNodes; REPLY_QUE replyQue; rc = sendToGroups( groupMsgMap, pSrcMsg, pRouteAgent, cb, sendNodes ) ; if ( rc ) { rtnCoordClearRequest( cb, sendNodes ) ; } PD_RC_CHECK( rc, PDERROR, "Failed to send the request(rc=%d)", rc ); rc = rtnCoordGetReply( cb, sendNodes, replyQue, MAKE_REPLY_TYPE( opCode ) ) ; PD_RC_CHECK( rc, PDWARNING, "Failed to insert on data-node, " "get reply failed(rc=%d)", rc ) ; rc = processReply( replyQue, successGroupList, cb ) ; PD_RC_CHECK( rc, PDWARNING, "Failed to process the reply(rc=%d)", rc ) ; done: PD_TRACE_EXITRC ( SDB_RTNCOINS_INSTOGROUPS, rc ) ; return rc; error: goto done; }
BOOLEAN _mongoSession::_preProcessMsg( const mongoParser &parser, engine::IResource *resource, engine::rtnContextBuf &buff ) { BOOLEAN handled = FALSE ; if ( OP_CMD_ISMASTER == parser.opType ) { handled = TRUE ; fap::mongo::buildIsMasterMsg( resource, buff ) ; } else if ( OP_CMD_GETNONCE == parser.opType ) { handled = TRUE ; fap::mongo::buildGetNonceMsg( buff ) ; } else if ( OP_CMD_GETLASTERROR == parser.opType ) { handled = TRUE ; fap::mongo::buildGetLastErrorMsg( _errorInfo, buff ) ; } else if ( OP_CMD_NOT_SUPPORTED ) { fap::mongo::buildNotSupportMsg( _contextBuff ) ; } if ( handled ) { _replyHeader.contextID = 0 ; _replyHeader.numReturned = 1 ; _replyHeader.startFrom = 0 ; _replyHeader.header.opCode = MAKE_REPLY_TYPE(parser.opCode) ; _replyHeader.header.requestID = parser.id ; _replyHeader.header.TID = 0 ; _replyHeader.header.routeID.value = 0 ; } return handled ; }
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_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; }