virtual OSS_INLINE INT32 _defaultMsgFunc ( NET_HANDLE handle, MsgHeader* msg ) { PD_LOG( PDWARNING, "[%s]Recieve unknow msg[type:[%d]%u, len:%u]", name(), IS_REPLY_TYPE( msg->opCode ) ? 1 : 0, GET_REQUEST_TYPE( msg->opCode ), msg->messageLength ); return SDB_CLS_UNKNOW_MSG; }
OSS_INLINE INT32 _pmdObjBase::dispatchMsg( NET_HANDLE handle, MsgHeader* msg, INT32 *pTime ) { _bProcess = TRUE ; INT32 rc = SDB_OK; time_t bTime = 0 ; INT32 diffTime = 0 ; const _msgMap* msgMap = NULL; for (msgMap = getMsgMap(); msgMap != NULL; msgMap = (*msgMap->pfnGetBaseMap)()) { UINT32 index = 0; while ( msgMap->entries[index].msgSig != sig_end ) { if ( msgMap->entries[index].msgSig == sig_msg && msgMap->entries[index].msgType <= (UINT32)(msg->opCode) && msgMap->entries[index].msgEndType >= (UINT32)(msg->opCode) ) { bTime = time( NULL ) ; rc = (this->*(msgMap->entries[index].pMsgFn))( handle, msg ) ; diffTime = (INT32)(time( NULL ) - bTime) ; if ( SDB_OK != rc ) { PD_LOG( PDDEBUG, "[%s]Process func[%s] failed[rc = %d]", name(), msgMap->entries[index].pFncName, rc ) ; } goto done; } index++; } } bTime = time( NULL ) ; rc = _defaultMsgFunc( handle, msg ) ; diffTime = (INT32)(time( NULL ) - bTime) ; done: _bProcess = FALSE ; if ( pTime ) { *pTime = diffTime ; } else if ( diffTime > 10 ) { PD_LOG( PDDEBUG, "[%s] Process msg[opCode:[%d]%d, requestID: %lld, " "TID: %d, Len: %d] over %d seconds", name(), IS_REPLY_TYPE(msg->opCode), GET_REQUEST_TYPE(msg->opCode), msg->requestID, msg->TID, msg->messageLength, diffTime ) ; } return rc; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__CLSCATCLR_REMOVE, "_clsCatalogCaller::remove" ) void _clsCatalogCaller::remove( _MsgInternalReplyHeader *header ) { SDB_ASSERT( NULL != header, "header should not be NULL" ) ; PD_TRACE_ENTRY ( SDB__CLSCATCLR_REMOVE ); callerMeta::iterator itr = _meta.find( header->header.opCode ) ; if ( _meta.end() != itr && SDB_OK == header->res ) { PD_LOG( PDEVENT, "response is ok, remove msg[(%d)%d]", IS_REPLY_TYPE( header->header.opCode ), GET_REQUEST_TYPE( header->header.opCode ) ) ; itr->second.timeout = CLS_CALLER_NO_SEND ; } PD_TRACE_EXIT ( SDB__CLSCATCLR_REMOVE ); return ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_NETMLTRTAGT_HNDMSG, "netMultiRouteAgent::handleMsg" ) INT32 netMultiRouteAgent::handleMsg( const NET_HANDLE &handle, const _MsgHeader *header, const CHAR *msg ) { INT32 rc = SDB_OK; PD_TRACE_ENTRY ( SDB_NETMLTRTAGT_HNDMSG ); CHAR *pMsgRsp = (CHAR *)SDB_OSS_MALLOC( header->messageLength ); PD_CHECK( pMsgRsp, SDB_OOM, error, PDERROR, "Memory malloc failed(size = %d)", header->messageLength ) ; ossMemcpy( pMsgRsp, msg, header->messageLength ); { ossScopedLock _lock( &_mutex, SHARED ) ; COORD_SESSION_MAP::iterator it = _sessionMap.find( header->TID ); if ( _sessionMap.end() != it ) { it->second->postEvent( pmdEDUEvent( PMD_EDU_EVENT_MSG, PMD_EDU_MEM_ALLOC, pMsgRsp ) ) ; } else { PD_LOG( PDWARNING, "Recieve expired msg[opCode:[%d]%d, TID:%d," "ReqID:%lld] from node[%d:%d:%d]", IS_REPLY_TYPE( header->opCode ), GET_REQUEST_TYPE( header->opCode ), header->TID, header->requestID, header->routeID.columns.groupID, header->routeID.columns.nodeID, header->routeID.columns.serviceID ) ; rc = SDB_SYS ; goto error ; } } done: PD_TRACE_EXITRC ( SDB_NETMLTRTAGT_HNDMSG, rc ); return rc ; error: if ( pMsgRsp ) { SDB_OSS_FREE( pMsgRsp ) ; } goto done ; }
INT32 _pmdDataProcessor::processMsg( MsgHeader *msg, rtnContextBuf &contextBuff, INT64 &contextID, BOOLEAN &needReply ) { INT32 rc = SDB_OK ; SDB_ASSERT( getSession(), "Must attach session at first" ) ; if ( MSG_AUTH_VERIFY_REQ == msg->opCode ) { rc = getClient()->authenticate( msg ) ; } else if ( MSG_BS_INTERRUPTE == msg->opCode ) { rc = _onInterruptMsg( msg, getDPSCB() ) ; } else if ( MSG_BS_INTERRUPTE_SELF == msg->opCode ) { rc = _onInterruptSelfMsg() ; } else if ( MSG_BS_DISCONNECT == msg->opCode ) { rc = _onDisconnectMsg() ; } else { if ( !getClient()->isAuthed() ) { rc = getClient()->authenticate( "", "" ) ; if ( rc ) { goto done ; } } switch( msg->opCode ) { case MSG_BS_MSG_REQ : rc = _onMsgReqMsg( msg ) ; break ; case MSG_BS_UPDATE_REQ : rc = _onUpdateReqMsg( msg, getDPSCB() ) ; break ; case MSG_BS_INSERT_REQ : rc = _onInsertReqMsg( msg ) ; break ; case MSG_BS_QUERY_REQ : rc = _onQueryReqMsg( msg, getDPSCB(), contextBuff, contextID ) ; break ; case MSG_BS_DELETE_REQ : rc = _onDelReqMsg( msg, getDPSCB() ) ; break ; case MSG_BS_GETMORE_REQ : rc = _onGetMoreReqMsg( msg, contextBuff, contextID ) ; break ; case MSG_BS_KILL_CONTEXT_REQ : rc = _onKillContextsReqMsg( msg ) ; break ; case MSG_BS_SQL_REQ : rc = _onSQLMsg( msg, contextID ) ; break ; case MSG_BS_TRANS_BEGIN_REQ : rc = _onTransBeginMsg() ; break ; case MSG_BS_TRANS_COMMIT_REQ : rc = _onTransCommitMsg( getDPSCB() ) ; break ; case MSG_BS_TRANS_ROLLBACK_REQ : rc = _onTransRollbackMsg( getDPSCB() ) ; break ; case MSG_BS_AGGREGATE_REQ : rc = _onAggrReqMsg( msg, contextID ) ; break ; case MSG_BS_LOB_OPEN_REQ : rc = _onOpenLobMsg( msg, getDPSCB(), contextID, contextBuff ) ; break ; case MSG_BS_LOB_WRITE_REQ: rc = _onWriteLobMsg( msg ) ; break ; case MSG_BS_LOB_READ_REQ: rc = _onReadLobMsg( msg, contextBuff ) ; break ; case MSG_BS_LOB_CLOSE_REQ: rc = _onCloseLobMsg( msg ) ; break ; case MSG_BS_LOB_REMOVE_REQ: rc = _onRemoveLobMsg( msg, getDPSCB() ) ; break ; default : PD_LOG( PDWARNING, "Session[%s] recv unknow msg[type:[%d]%d, " "len: %d, tid: %d, routeID: %d.%d.%d, reqID: %lld]", getSession()->sessionName(), IS_REPLY_TYPE(msg->opCode), GET_REQUEST_TYPE(msg->opCode), msg->messageLength, msg->TID, msg->routeID.columns.groupID, msg->routeID.columns.nodeID, msg->routeID.columns.serviceID, msg->requestID ) ; rc = SDB_INVALIDARG ; break ; } } done: return rc ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__NETEVNHND__RDCALLBK, "_netEventHandler::_readCallback" ) void _netEventHandler::_readCallback( const boost::system::error_code & error ) { PD_TRACE_ENTRY ( SDB__NETEVNHND__RDCALLBK ) ; if ( error ) { if ( error.value() == boost::system::errc::operation_canceled || error.value() == boost::system::errc::no_such_file_or_directory ) { PD_LOG ( PDINFO, "connection aborted, node:%d, %d, %d", _id.columns.groupID, _id.columns.nodeID, _id.columns.serviceID ) ; } else { PD_LOG ( PDERROR, "Error received, node:%d, %d, %d, err=%d", _id.columns.groupID, _id.columns.nodeID, _id.columns.serviceID, error.value() ) ; } goto error_close ; } if ( NET_EVENT_HANDLER_STATE_HEADER == _state ) { if ( ( UINT32 )MSG_SYSTEM_INFO_LEN == (UINT32)_header.messageLength ) { if ( SDB_OK != _allocateBuf( sizeof(MsgSysInfoRequest) )) { goto error_close ; } _hasRecvMsg = TRUE ; ossMemcpy( _buf, &_header, sizeof( MsgSysInfoRequest ) ) ; _frame->handleMsg( shared_from_this() ) ; _state = NET_EVENT_HANDLER_STATE_HEADER ; asyncRead() ; goto done ; } else if ( sizeof(_MsgHeader) > (UINT32)_header.messageLength || SDB_MAX_MSG_LENGTH < (UINT32)_header.messageLength ) { PD_LOG( PDERROR, "Error header[len: %d, opCode: (%d)%d, TID:%d] " "received, node:%d, %d, %d", _header.messageLength, IS_REPLY_TYPE(_header.opCode) ? 1 : 0, GET_REQUEST_TYPE(_header.opCode), _header.TID, _id.columns.groupID, _id.columns.nodeID, _id.columns.serviceID ) ; goto error_close ; } else { if ( FALSE == _hasRecvMsg ) { _hasRecvMsg = TRUE ; _state = NET_EVENT_HANDLER_STATE_HEADER_LAST ; asyncRead() ; _state = NET_EVENT_HANDLER_STATE_HEADER ; goto done ; } PD_LOG( PDDEBUG, "msg header: [len:%d], [opCode: [%d]%d], " "[TID:%d], [groupID:%d], [nodeID:%d], " "[ADDR:%s], [PORT:%d]", _header.messageLength, IS_REPLY_TYPE(_header.opCode)?1:0, GET_REQUEST_TYPE(_header.opCode), _header.TID, _header.routeID.columns.groupID, _header.routeID.columns.nodeID, remoteAddr().c_str(), remotePort() ) ; if ( MSG_INVALID_ROUTEID == _id.value ) { if ( MSG_INVALID_ROUTEID != _header.routeID.value ) { _id = _header.routeID ; _frame->_addRoute( shared_from_this() ) ; } } } if ( (UINT32)sizeof(_MsgHeader) == (UINT32)_header.messageLength ) { if ( SDB_OK != _allocateBuf( sizeof(_MsgHeader) )) { goto error_close ; } ossMemcpy( _buf, &_header, sizeof( _MsgHeader ) ) ; _frame->handleMsg( shared_from_this() ) ; _state = NET_EVENT_HANDLER_STATE_HEADER ; asyncRead() ; goto done ; } #if defined (_LINUX) try { boost::asio::detail::socket_option::boolean<IPPROTO_TCP, TCP_QUICKACK> quickack( TRUE ) ; _sock.set_option( quickack ) ; } catch ( boost::system::system_error &e ) { PD_LOG ( PDERROR, "Failed to quick ack: %s", e.what() ) ; } #endif // _LINUX _state = NET_EVENT_HANDLER_STATE_BODY ; asyncRead() ; } else { _frame->handleMsg( shared_from_this() ) ; _state = NET_EVENT_HANDLER_STATE_HEADER ; asyncRead() ; } done: PD_TRACE_EXIT ( SDB__NETEVNHND__RDCALLBK ) ; return ; error_close: if ( _isConnected ) { close() ; } _frame->handleClose( shared_from_this(), _id ) ; _frame->_erase( handle() ) ; goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_PMDCBMGREP, "pmdCBMgrEntryPoint" ) INT32 pmdCBMgrEntryPoint ( pmdEDUCB *cb, void *pData ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB_PMDCBMGREP ); _pmdObjBase *pObj = ( _pmdObjBase* )pData ; pmdEDUMgr *pEDUMgr = cb->getEDUMgr() ; pmdEDUEvent eventData; INT32 timeSpan = 0 ; INT32 maxMsgTime = pObj->getMaxProcMsgTime() ; INT32 maxEventTime = pObj->getMaxProcEventTime() ; INT32 *pMsgTimeSpan = maxMsgTime >= 0 ? &timeSpan : NULL ; INT32 *pEventTimeSpan = maxEventTime >= 0 ? &timeSpan : NULL ; pObj->attachCB( cb ) ; rc = pEDUMgr->activateEDU( cb->getID() ) ; if ( SDB_OK != rc ) { PD_LOG ( PDERROR, "Failed to active EDU" ) ; goto error ; } while ( !cb->isDisconnected() ) { if ( cb->waitEvent( eventData, OSS_ONE_SEC ) ) { if ( PMD_EDU_EVENT_TERM == eventData._eventType ) { PD_LOG ( PDDEBUG, "EDU[%lld, %s] is terminated", cb->getID(), getEDUName( cb->getType() ) ) ; } else if ( PMD_EDU_EVENT_MSG == eventData._eventType ) { pObj->dispatchMsg( (NET_HANDLE)eventData._userData, (MsgHeader*)(eventData._Data), pMsgTimeSpan ) ; if ( pMsgTimeSpan && timeSpan > maxMsgTime ) { MsgHeader *pMsg = (MsgHeader*)(eventData._Data) ; PD_LOG( PDWARNING, "[%s] Process msg[opCode:[%d]%d, " "requestID: %lld, TID: %d, Len: %d] over %d seconds", pObj->name(), IS_REPLY_TYPE(pMsg->opCode), GET_REQUEST_TYPE(pMsg->opCode), pMsg->requestID, pMsg->TID, pMsg->messageLength, timeSpan ) ; } } else { pObj->dispatchEvent ( &eventData, pEventTimeSpan ) ; if ( pEventTimeSpan && timeSpan > maxEventTime ) { PD_LOG( PDWARNING, "[%s] Process event[type:%d] over %d " "seconds", pObj->name(), eventData._eventType, timeSpan ) ; } } pmdEduEventRelase( eventData, cb ) ; eventData.reset () ; } } done: pObj->detachCB( cb ) ; PD_TRACE_EXITRC ( SDB_PMDCBMGREP, rc ); return rc ; error: goto done ; }