INT32 restAdaptor::setOPResult( pmdRestSession *pSession, INT32 result, const BSONObj &info ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY( SDB__RESTADP_SETOPR ) ; SDB_ASSERT ( pSession, "pSession is NULL" ) ; httpConnection *pHttpCon = pSession->getRestConn() ; if( COM_GETFILE != pHttpCon->_common ) { std::string str = info.toString( FALSE, TRUE ) ; INT32 bufferSize = ossStrlen( str.c_str() ) ; if( TRUE == pHttpCon->_isChunk ) { if( FALSE == pHttpCon->_isSendHttpHeader ) { pHttpCon->_isSendHttpHeader = TRUE ; rc = _setResponseType( pSession ) ; if( rc ) { PD_LOG ( PDERROR, "Failed to set respone type, rc=%d", rc ) ; goto error ; } rc = _sendHttpHeader( pSession, HTTP_OK ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to send http header, rc=%d", rc ) ; goto error ; } } rc = _sendHttpChunk( pSession, str.c_str(), bufferSize ) ; if( rc ) { PD_LOG ( PDERROR, "Failed to send http chunk, rc=%d", rc ) ; goto error ; } } else { CHAR *pBuffer = NULL ; INT32 tempSize = 0 ; httpResponse httpRe ; rc = pSession->allocBuff( bufferSize + 1, &pBuffer, tempSize ) ; if ( rc ) { PD_LOG ( PDERROR, "Unable to allocate %d bytes memory, rc=%d", bufferSize + 1, rc ) ; goto error ; } ossMemcpy( pBuffer, str.c_str(), bufferSize ) ; pBuffer[ bufferSize ] = 0 ; pHttpCon->_firstRecordSize = bufferSize ; httpRe.pBuffer = pBuffer ; httpRe.len = bufferSize ; pHttpCon->_responseBody[0] = httpRe ; } } done: PD_TRACE_EXITRC( SDB__RESTADP_SETOPR, rc ) ; return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__NETEVNHND_ASYNCRD, "_netEventHandler::asyncRead" ) void _netEventHandler::asyncRead() { PD_TRACE_ENTRY ( SDB__NETEVNHND_ASYNCRD ) ; if ( NET_EVENT_HANDLER_STATE_HEADER == _state || NET_EVENT_HANDLER_STATE_HEADER_LAST == _state ) { _isInAsync = TRUE ; if ( !_isConnected ) { PD_LOG( PDWARNING, "Connection[routeID: %u,%u,%u; Handel: %u] " "already closed", _id.columns.groupID, _id.columns.nodeID, _id.columns.serviceID, _handle ) ; goto error ; } if ( NET_EVENT_HANDLER_STATE_HEADER_LAST == _state ) { async_read( _sock, buffer( (CHAR*)&_header + sizeof(MsgSysInfoRequest), sizeof(_MsgHeader) - sizeof(MsgSysInfoRequest) ), boost::bind(&_netEventHandler::_readCallback, shared_from_this(), boost::asio::placeholders::error ) ) ; } else if ( FALSE == _hasRecvMsg ) { async_read( _sock, buffer(&_header, sizeof(MsgSysInfoRequest)), boost::bind(&_netEventHandler::_readCallback, shared_from_this(), boost::asio::placeholders::error )) ; } else { async_read( _sock, buffer(&_header, sizeof(_MsgHeader)), boost::bind(&_netEventHandler::_readCallback, shared_from_this(), boost::asio::placeholders::error )) ; } } else { UINT32 len = _header.messageLength ; if ( SDB_OK != _allocateBuf( len ) ) { goto error ; } ossMemcpy( _buf, &_header, sizeof( _MsgHeader ) ) ; _isInAsync = TRUE ; if ( !_isConnected ) { PD_LOG( PDWARNING, "Connection[routeID: %u,%u,%u; Handel: %u] " "already closed", _id.columns.groupID, _id.columns.nodeID, _id.columns.serviceID, _handle ) ; goto error ; } async_read( _sock, buffer( (CHAR *)((ossValuePtr)_buf + sizeof(_MsgHeader)), len - sizeof(_MsgHeader)), boost::bind( &_netEventHandler::_readCallback, shared_from_this(), boost::asio::placeholders::error ) ) ; } done: _isInAsync = FALSE ; PD_TRACE_EXIT ( SDB__NETEVNHND_ASYNCRD ) ; return ; error: _isInAsync = FALSE ; if ( _isConnected ) { close() ; } _frame->handleClose( shared_from_this(), _id ) ; _frame->_erase( handle() ) ; 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__MIGWORKER__GETBSON, "migWorker::_getBsonFromQueue" ) INT32 migWorker::_getBsonFromQueue( pmdEDUCB *eduCB, BSONObj &obj ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__MIGWORKER__GETBSON ); INT32 tempRc = SDB_OK ; UINT32 offset = 0 ; UINT32 size = 0 ; UINT32 line = 0 ; UINT32 column = 0 ; UINT32 startBlock = 0 ; UINT32 endBlock = 0 ; _master->popFromQueue ( eduCB, offset, size, line, column ) ; if ( 0 == offset && 0 == size && 0 == line && 0 == column ) { rc = SDB_MIG_END_OF_QUEUE ; goto done ; } if ( MIG_PARSER_JSON == _master->_fileType ) { tempRc = fromjson ( _master->getBuffer() + offset, obj ) ; } else if ( MIG_PARSER_CSV == _master->_fileType ) { rc = _csvParser.csv2bson( _master->getBuffer() + offset, size, &obj ) ; if ( rc ) { rc = SDB_UTIL_PARSE_JSON_INVALID ; PD_LOG ( PDERROR, "Failed to convert Bson, rc=%d", rc ) ; goto error ; } } else { rc = SDB_MIG_UNKNOW_FILE_TYPE ; PD_LOG ( PDERROR, "unknow file type" ) ; goto error ; } if ( tempRc ) { _master->sendMsgToClient ( "Error: error " "in json format, line %u, column %u", line, column ) ; } rc = _master->getBlockFromPointer ( offset, size, startBlock, endBlock ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to get block from pointer, rc=%d", rc ) ; goto error ; } for ( UINT32 i = startBlock; i <= endBlock; ++i ) { _master->bucketDec( i ) ; } done: if ( tempRc ) { rc = tempRc ; } PD_TRACE_EXITRC ( SDB__MIGWORKER__GETBSON, rc ); return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__NETEVNHND_SETOPT, "_netEventHandler::setOpt" ) void _netEventHandler::setOpt() { PD_TRACE_ENTRY ( SDB__NETEVNHND_SETOPT ); _isConnected = TRUE ; try { _sock.set_option( tcp::no_delay(TRUE) ) ; _sock.set_option( tcp::socket::keep_alive(TRUE) ) ; #if defined (_LINUX) INT32 keepAlive = 1 ; INT32 keepIdle = 15 ; INT32 keepInterval = 5 ; INT32 keepCount = 3 ; INT32 res = SDB_OK ; struct timeval sendtimeout ; sendtimeout.tv_sec = 1 ; sendtimeout.tv_usec = 0 ; SOCKET nativeSock = _sock.native() ; res = setsockopt( nativeSock, SOL_SOCKET, SO_KEEPALIVE, ( void *)&keepAlive, sizeof(keepAlive) ) ; if ( SDB_OK != res ) { PD_LOG( PDERROR, "failed to set keepalive of sock[%d]," "err:%d", nativeSock, res ) ; } res = setsockopt( nativeSock, SOL_TCP, TCP_KEEPIDLE, ( void *)&keepIdle, sizeof(keepIdle) ) ; if ( SDB_OK != res ) { PD_LOG( PDERROR, "failed to set keepidle of sock[%d]," "err:%d", nativeSock, res ) ; } res = setsockopt( nativeSock, SOL_TCP, TCP_KEEPINTVL, ( void *)&keepInterval, sizeof(keepInterval) ) ; if ( SDB_OK != res ) { PD_LOG( PDERROR, "failed to set keepintvl of sock[%d]," "err:%d", nativeSock, res ) ; } res = setsockopt( nativeSock, SOL_TCP, TCP_KEEPCNT, ( void *)&keepCount, sizeof(keepCount) ) ; if ( SDB_OK != res ) { PD_LOG( PDERROR, "failed to set keepcnt of sock[%d]," "err:%d", nativeSock, res ) ; } res = setsockopt( nativeSock, SOL_SOCKET, SO_SNDTIMEO, ( CHAR * )&sendtimeout, sizeof(struct timeval) ) ; if ( SDB_OK != res ) { PD_LOG( PDERROR, "failed to set sndtimeout of sock[%d]," "err:%d", nativeSock, res ) ; } #endif } catch( std::exception &e ) { PD_LOG( PDERROR, "failed to set no delay:%s", e.what() ) ; } PD_TRACE_EXIT ( SDB__NETEVNHND_SETOPT ); return ; }
// 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 ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__MIGLOADJSONPS__INITIALIZE, "migMaster::initialize" ) INT32 migMaster::initialize ( setParameters *pParameters ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__MIGLOADJSONPS__INITIALIZE ); _utilParserParamet parserPara ; UINT32 startOffset = 0 ; UINT32 fieldsSize = 0 ; _pParameters = pParameters ; _sock = _pParameters->clientSock ; _fileType = _pParameters->fileType ; _blockSize = _pParameters->bufferSize/_pParameters->bucketNum ; _exitSignal = FALSE ; if ( MIG_PARSER_JSON == _pParameters->fileType ) { _parser = SDB_OSS_NEW _utilJSONParser() ; } else if ( MIG_PARSER_CSV == _pParameters->fileType ) { _parser = SDB_OSS_NEW _utilCSVParser() ; } else { rc = SDB_MIG_UNKNOW_FILE_TYPE ; PD_LOG ( PDERROR, "Unknow file type" ) ; goto error ; } PD_CHECK ( _parser, SDB_OOM, error, PDERROR, "Failed to new _parser" ) ; _ppBucket = (_bucket**)SDB_OSS_MALLOC ( sizeof(_bucket*) * _pParameters->bucketNum ) ; PD_CHECK ( _ppBucket, SDB_OOM, error, PDERROR, "Failed to allocate bucket pointer array" ) ; ossMemset ( _ppBucket, 0, sizeof(_bucket*) * _pParameters->bucketNum ) ; for ( UINT32 i = 0; i < _pParameters->bucketNum; ++i ) { _ppBucket[i] = SDB_OSS_NEW _bucket() ; PD_CHECK ( _ppBucket[i], SDB_OOM, error, PDERROR, "Failed to allocate bucket pointer array" ) ; } _parser->setDel ( _pParameters->delCFR[0], _pParameters->delCFR[1], _pParameters->delCFR[2] ) ; parserPara.fileName = _pParameters->pFileName ; parserPara.bufferSize = _pParameters->bufferSize ; parserPara.blockNum = _pParameters->bucketNum ; rc = _parser->initialize( &parserPara ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to init utilParseJSONs, rc = %d", rc ) ; if ( SDB_IO == rc || SDB_FNE == rc ) { sendMsgToClient ( "Failed to open file %s, rc=%d", _pParameters->pFileName, rc ) ; } goto error ; } _buffer = _parser->getBuffer() ; _delChar = _pParameters->delCFR[0] ; _delField = _pParameters->delCFR[1] ; _delRecord = _pParameters->delCFR[2] ; _autoAddField = TRUE ; _autoCompletion = FALSE ; _isHeaderline = _pParameters->headerline ; if ( _isHeaderline ) { rc = _parser->getNextRecord ( startOffset, fieldsSize ) ; if ( rc ) { if ( rc == SDB_EOF ) { if ( 0 == fieldsSize ) { goto done ; } } else { PD_LOG ( PDERROR, "Failed to _parser getNextRecord, rc=%d", rc ) ; goto error ; } } } if ( _pParameters->pFieldArray ) { _pFields = _pParameters->pFieldArray ; _fieldsSize = ossStrlen( _pFields ) ; } else { _pFields = _buffer + startOffset ; _fieldsSize = fieldsSize ; } done: PD_TRACE_EXITRC ( SDB__MIGLOADJSONPS__INITIALIZE, rc ); return rc ; error: goto done ; }
INT32 _rtnIXScanner::resumeScan( BOOLEAN isReadOnly ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__RTNIXSCAN_RESUMESCAN ) ; if ( !_indexCB ) { PD_LOG ( PDERROR, "Failed to allocate memory for indexCB" ) ; rc = SDB_OOM ; goto error ; } if ( !_indexCB->isInitialized() ) { rc = SDB_RTN_INDEX_NOTEXIST ; goto done ; } if ( _indexCB->getFlag() != IXM_INDEX_FLAG_NORMAL ) { rc = SDB_IXM_UNEXPECTED_STATUS ; goto done ; } if ( !_init || _curIndexRID.isNull() || _savedObj.isEmpty() ) { rc = SDB_OK ; goto done ; } if ( !isReadOnly ) { goto done ; } if ( !_indexCB->isStillValid ( _indexOID ) || _indexLID != _indexCB->getLogicalID() ) { rc = SDB_RTN_INDEX_NOTEXIST ; goto done ; } { ixmExtent indexExtent ( _curIndexRID._extent, _su->index() ) ; CHAR *dataBuffer = NULL ; if ( indexExtent.isStillValid( _indexCB->getMBID() ) ) { dataBuffer = indexExtent.getKeyData ( _curIndexRID._slot ) ; } if ( dataBuffer ) { try { BSONObj curObj = ixmKey(dataBuffer).toBson() ; if ( curObj.shallowEqual(_savedObj) ) { dmsRecordID onDiskRID = indexExtent.getRID ( _curIndexRID._slot ) ; if ( onDiskRID == _savedRID ) { _savedRID.reset() ; goto done ; } } } catch ( std::exception &e ) { PD_LOG ( PDERROR, "Failed to convert buffer to bson from " "current rid: %d,%d: %s", _curIndexRID._extent, _curIndexRID._slot, e.what() ) ; rc = SDB_SYS ; goto error ; } } { rc = relocateRID () ; if ( rc ) { PD_LOG ( PDERROR, "Failed to relocate RID, rc: %d", rc ) ; goto error ; } } } done : PD_TRACE_EXITRC ( SDB__RTNIXSCAN_RESUMESCAN, rc ) ; return rc ; error : goto done ; }
INT32 _qgmPlFilter::_fetchNext( qgmFetchOut &next ) { PD_TRACE_ENTRY( SDB__QGMPLFILTER__FETCHNEXT ) ; INT32 rc = SDB_OK ; qgmFetchOut fetch ; _qgmPlan *in = input( 0 ) ; if ( 0 <= _return && _return <= _currentReturn ) { close() ; rc = SDB_DMS_EOC ; goto error ; } while ( TRUE ) { rc = in->fetchNext( fetch ) ; if ( SDB_OK != rc && SDB_DMS_EOC != rc ) { goto error ; } else if ( SDB_DMS_EOC == rc ) { break ; } else { /// do noting. } /// match if ( NULL != _condition ) { BOOLEAN r = FALSE ; rc = _matcher.match( fetch, r ) ; if ( SDB_OK != rc ) { goto error ; } else if ( !r ) { continue ; } else { /// do nothing. } } /// skip if ( 0 < _skip && ++_currentSkip <= _skip ) { continue ; } /// get needed fields. if ( !_selector.empty() ) { rc = _selector.select( fetch, next.obj ) ; if ( SDB_OK != rc ) { goto error ; } } else { next.obj = fetch.mergedObj() ; } if ( !_merge ) { /// if sub input is a join, can _alias be empty? next.alias = _alias.empty()? fetch.alias : _alias ; } ++_currentReturn ; break ; } done: PD_TRACE_EXITRC( SDB__QGMPLFILTER__FETCHNEXT, rc ) ; return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( COORD_CMDSTATBASE_EXE, "_coordCMDStatisticsBase::execute" ) INT32 _coordCMDStatisticsBase::execute( MsgHeader *pMsg, pmdEDUCB *cb, INT64 &contextID, rtnContextBuf *buf ) { INT32 rc = SDB_OK; PD_TRACE_ENTRY ( COORD_CMDSTATBASE_EXE ) ; SDB_RTNCB *pRtncb = pmdGetKRCB()->getRTNCB() ; contextID = -1 ; coordQueryOperator queryOpr( isReadOnly() ) ; rtnContextCoord *pContext = NULL ; coordQueryConf queryConf ; coordSendOptions sendOpt ; queryConf._openEmptyContext = openEmptyContext() ; CHAR *pHint = NULL ; rc = msgExtractQuery( (CHAR*)pMsg, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &pHint ); PD_RC_CHECK ( rc, PDERROR, "Execute failed, failed to parse query " "request, rc: %d", rc ) ; try { BSONObj boHint( pHint ) ; BSONElement ele = boHint.getField( FIELD_NAME_COLLECTION ) ; PD_CHECK ( ele.type() == String, SDB_INVALIDARG, error, PDERROR, "Execute failed, failed to get the field(%s)", FIELD_NAME_COLLECTION ) ; queryConf._realCLName = ele.str() ; } catch( std::exception &e ) { PD_RC_CHECK ( rc, PDERROR, "Execute failed, occured unexpected " "error:%s", e.what() ) ; } rc = queryOpr.init( _pResource, cb, getTimeout() ) ; if ( rc ) { PD_LOG( PDERROR, "Init query operator failed, rc: %d", rc ) ; goto error ; } rc = queryOpr.queryOrDoOnCL( pMsg, cb, &pContext, sendOpt, &queryConf, buf ) ; PD_RC_CHECK( rc, PDERROR, "Query failed, rc: %d", rc ) ; rc = generateResult( pContext, cb ) ; PD_RC_CHECK( rc, PDERROR, "Failed to execute statistics, rc: %d", rc ) ; contextID = pContext->contextID() ; pContext->reopen() ; done: PD_TRACE_EXITRC ( COORD_CMDSTATBASE_EXE, rc ) ; return rc; error: if ( pContext ) { pRtncb->contextDelete( pContext->contextID(), cb ) ; } goto done ; }
INT32 _rtnIXScanner::advance ( dmsRecordID &rid, BOOLEAN isReadOnly ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__RTNIXSCAN_ADVANCE ) ; monAppCB * pMonAppCB = _cb ? _cb->getMonAppCB() : NULL ; begin: SDB_ASSERT ( _indexCB, "_indexCB can't be NULL, call resumeScan first" ) ; if ( !_init ) { dmsExtentID rootExtent = _indexCB->getRoot() ; ixmExtent root ( rootExtent, _su->index() ) ; rc = root.keyLocate ( _curIndexRID, BSONObj(),0,FALSE, _listIterator.cmp(), _listIterator.inc(), _order, _direction, _cb ) ; if ( rc ) { PD_LOG ( PDERROR, "failed to locate first key, rc: %d", rc ) ; goto error ; } _init = TRUE ; } else { if ( _curIndexRID.isNull() ) { return SDB_IXM_EOC ; } ixmExtent indexExtent ( _curIndexRID._extent, _su->index() ) ; if ( _savedRID.isNull() ) { rc = indexExtent.advance ( _curIndexRID, _direction ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to advance to next key, rc: %d", rc ) ; goto error ; } } else if ( !isReadOnly ) { dmsRecordID onDiskRID = indexExtent.getRID ( _curIndexRID._slot ) ; if ( onDiskRID.isNull() ) { rc = relocateRID () ; if ( rc ) { PD_LOG ( PDERROR, "Failed to relocate RID, rc: %d", rc ) ; goto error ; } } else if ( onDiskRID == _savedRID ) { CHAR *dataBuffer = indexExtent.getKeyData ( _curIndexRID._slot ); if ( dataBuffer ) { try { _curKeyObj = ixmKey(dataBuffer).toBson() ; DMS_MON_OP_COUNT_INC( pMonAppCB, MON_INDEX_READ, 1 ) ; DMS_MON_CONTEXT_COUNT_INC ( _pMonCtxCB, MON_INDEX_READ, 1 ) ; if ( _curKeyObj.shallowEqual(_savedObj) ) { rc = indexExtent.advance ( _curIndexRID, _direction ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to advance, rc: %d", rc ) ; goto error ; } } else { rc = relocateRID () ; if ( rc ) { PD_LOG ( PDERROR, "Failed to relocate RID, rc: :%d", rc ) ; goto error ; } } } catch ( std::exception &e ) { PD_LOG ( PDERROR, "Failed to convert buffer to bson from " "current rid: %d,%d: %s", _curIndexRID._extent, _curIndexRID._slot, e.what() ) ; rc = SDB_SYS ; goto error ; } } // if ( dataBuffer ) else { PD_LOG ( PDERROR, "Unable to get buffer" ) ; rc = SDB_SYS ; goto error ; } } // if ( onDiskRID == _savedRID ) else { rc = relocateRID () ; if ( rc ) { PD_LOG ( PDERROR, "Failed to relocate RID, rc: %d", rc ) ; goto error ; } } } // if ( !isReadOnly ) else { _savedRID.reset() ; } } while ( TRUE ) { if ( _curIndexRID.isNull() ) { return SDB_IXM_EOC ; } ixmExtent indexExtent ( _curIndexRID._extent, _su->index() ) ; CHAR *dataBuffer = indexExtent.getKeyData ( _curIndexRID._slot ) ; if ( !dataBuffer ) { PD_LOG ( PDERROR, "Failed to get buffer from current rid: %d,%d", _curIndexRID._extent, _curIndexRID._slot ) ; rc = SDB_SYS ; goto error ; } try { try { _curKeyObj = ixmKey(dataBuffer).toBson() ; DMS_MON_OP_COUNT_INC( pMonAppCB, MON_INDEX_READ, 1 ) ; DMS_MON_CONTEXT_COUNT_INC ( _pMonCtxCB, MON_INDEX_READ, 1 ) ; } catch ( std::exception &e ) { PD_RC_CHECK ( SDB_SYS, PDERROR, "Failed to convert from buffer " "to bson, rid: %d,%d: %s", _curIndexRID._extent, _curIndexRID._slot, e.what() ) ; } rc = _listIterator.advance ( _curKeyObj ) ; if ( -2 == rc ) { rc = SDB_IXM_EOC ; goto done ; } else if ( rc >= 0 ) { rc = indexExtent.keyAdvance ( _curIndexRID, _curKeyObj, rc, _listIterator.after(), _listIterator.cmp(), _listIterator.inc(), _order, _direction, _cb ) ; PD_RC_CHECK ( rc, PDERROR, "Failed to advance, rc = %d", rc ) ; continue ; } else { _savedRID = indexExtent.getRID ( _curIndexRID._slot ) ; if ( _savedRID.isNull() || _dupBuffer.end() != _dupBuffer.find ( _savedRID ) ) { _savedRID.reset() ; goto begin ; } /*if ( _dupBuffer.size() >= _dedupBufferSize ) { rc = SDB_IXM_DEDUP_BUF_MAX ; goto error ; }*/ _dupBuffer.insert ( _savedRID ) ; rid = _savedRID ; if ( !isReadOnly ) { _savedObj = _curKeyObj.getOwned() ; } else { _savedRID.reset() ; } rc = SDB_OK ; break ; } } // try catch ( std::exception &e ) { PD_RC_CHECK ( SDB_SYS, PDERROR, "exception during advance index tree: %s", e.what() ) ; } } // while ( TRUE ) done : PD_TRACE_EXITRC( SDB__RTNIXSCAN_ADVANCE, rc ) ; return rc ; error : goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( COORD_GETCOUNT_GENRESULT, "_coordCMDGetCount::generateResult" ) INT32 _coordCMDGetCount::generateResult( rtnContext *pContext, pmdEDUCB *cb ) { INT32 rc = SDB_OK; PD_TRACE_ENTRY ( COORD_GETCOUNT_GENRESULT ) ; SINT64 totalCount = 0 ; rtnContextBuf buffObj ; while( TRUE ) { rc = pContext->getMore( 1, buffObj, cb ) ; if ( rc ) { if ( SDB_DMS_EOC == rc ) { rc = SDB_OK ; break ; } else { PD_LOG ( PDERROR, "Failed to generate count result" "get data failed, rc: %d", rc ) ; goto error ; } } try { BSONObj boTmp( buffObj.data() ) ; BSONElement beTotal = boTmp.getField( FIELD_NAME_TOTAL ) ; PD_CHECK( beTotal.isNumber(), SDB_INVALIDARG, error, PDERROR, "Failed to get the field(%s)", FIELD_NAME_TOTAL ) ; totalCount += beTotal.number() ; } catch ( std::exception &e ) { rc = SDB_SYS ; PD_RC_CHECK( rc, PDERROR, "Failed to generate count result," "occured unexpected error:%s", e.what() ); } } try { rc = pContext->append( BSON( FIELD_NAME_TOTAL << totalCount ) ) ; PD_RC_CHECK( rc, PDERROR, "Failed to generate count result," "append the data failed, rc: %d", rc ) ; } catch ( std::exception &e ) { rc = SDB_SYS ; PD_RC_CHECK( rc, PDERROR, "Failed to generate count result," "occured unexpected error:%s", e.what() ) ; } done: PD_TRACE_EXITRC ( COORD_GETCOUNT_GENRESULT, rc ) ; return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( COORD_GETINDEX_GENRESULT, "_coordCMDGetIndexes::generateResult" ) INT32 _coordCMDGetIndexes::generateResult( rtnContext *pContext, pmdEDUCB *cb ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( COORD_GETINDEX_GENRESULT ) ; CoordIndexMap indexMap ; rtnContextBuf buffObj ; while( TRUE ) { rc = pContext->getMore( 1, buffObj, cb ) ; if ( rc ) { if ( SDB_DMS_EOC == rc ) { rc = SDB_OK ; break ; } else { PD_LOG ( PDERROR, "Failed to get index data, rc: %d", rc ) ; goto error ; } } try { BSONObj boTmp( buffObj.data() ) ; BSONObj boIndexDef ; BSONElement ele ; string strIndexName ; CoordIndexMap::iterator iter ; ele = boTmp.getField( IXM_FIELD_NAME_INDEX_DEF ) ; PD_CHECK ( ele.type() == Object, SDB_INVALIDARG, error, PDERROR, "Failed to get the field(%s)", IXM_FIELD_NAME_INDEX_DEF ) ; boIndexDef = ele.embeddedObject() ; ele = boIndexDef.getField( IXM_NAME_FIELD ) ; PD_CHECK ( ele.type() == String, SDB_INVALIDARG, error, PDERROR, "Failed to get the field(%s)", IXM_NAME_FIELD ) ; strIndexName = ele.valuestr() ; iter = indexMap.find( strIndexName ) ; if ( indexMap.end() == iter ) { indexMap[ strIndexName ] = boTmp.getOwned() ; } else { BSONObjIterator newIter( boIndexDef ) ; BSONObj boOldDef ; ele = iter->second.getField( IXM_FIELD_NAME_INDEX_DEF ) ; PD_CHECK ( ele.type() == Object, SDB_INVALIDARG, error, PDERROR, "Failed to get the field(%s)", IXM_FIELD_NAME_INDEX_DEF ) ; boOldDef = ele.embeddedObject() ; BSONElement beTmp1, beTmp2 ; while( newIter.more() ) { beTmp1 = newIter.next() ; if ( 0 == ossStrcmp( beTmp1.fieldName(), "_id" ) ) { continue ; } beTmp2 = boOldDef.getField( beTmp1.fieldName() ) ; if ( 0 != beTmp1.woCompare( beTmp2 ) ) { PD_LOG( PDWARNING, "Corrupted index(name:%s, define1:%s, " "define2:%s)", strIndexName.c_str(), boIndexDef.toString().c_str(), boOldDef.toString().c_str() ) ; break ; } } } } catch ( std::exception &e ) { PD_RC_CHECK( rc, PDERROR, "Failed to get index, occured unexpected" "error:%s", e.what() ) ; } } { CoordIndexMap::iterator iterMap = indexMap.begin(); while( iterMap != indexMap.end() ) { rc = pContext->append( iterMap->second ) ; PD_RC_CHECK( rc, PDERROR, "Failed to get index, append the data " "failed(rc=%d)", rc ) ; ++iterMap ; } } done: PD_TRACE_EXITRC ( COORD_GETINDEX_GENRESULT, rc ) ; return rc ; error: goto done ; }
INT32 restAdaptor::sendResponse( pmdRestSession *pSession, HTTP_RESPONSE_CODE rspCode ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY( SDB__RESTADP_SENDRE ) ; SDB_ASSERT ( pSession, "pSession is NULL" ) ; CHAR httpBodySize[256] = { 0 } ; httpConnection *pHttpCon = pSession->getRestConn() ; std::vector<httpResponse>::iterator it ; httpResponse httpRe ; if( TRUE == pHttpCon->_isChunk ) { rc = pSession->sendData( REST_STRING_CHUNKED_END, REST_STRING_CHUNKED_END_SIZE, _timeout ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to send data, rc=%d", rc ) ; goto error ; } } else { if( HTTP_OK == rspCode ) { ossSnprintf( httpBodySize, 255, "%d", pHttpCon->_firstRecordSize + pHttpCon->_responseSize ); rc = appendHttpHeader( pSession, REST_STRING_CONLEN, httpBodySize ); if ( rc ) { PD_LOG ( PDERROR, "Failed to call append http header, rc=%d", rc ) ; goto error ; } rc = _setResponseType( pSession ) ; if( rc ) { PD_LOG ( PDERROR, "Failed to set respone type, rc=%d", rc ) ; goto error ; } } else { ossSnprintf( httpBodySize, 255, "0" ) ; rc = appendHttpHeader( pSession, REST_STRING_CONLEN, httpBodySize ); if ( rc ) { PD_LOG ( PDERROR, "Failed to call append http header, rc=%d", rc ) ; goto error ; } } rc = _sendHttpHeader( pSession, rspCode ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to send http header, rc=%d", rc ) ; goto error ; } if( HTTP_OK == rspCode ) { for( it = pHttpCon->_responseBody.begin(); it != pHttpCon->_responseBody.end(); ++it ) { httpRe = (*(it)) ; rc = pSession->sendData( httpRe.pBuffer, httpRe.len, _timeout ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to send data, rc=%d", rc ) ; goto error ; } } } } done: PD_TRACE_EXITRC( SDB__RESTADP_SENDRE, rc ) ; return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( COORD_EVAL_EXE, "_coordCMDEval::execute" ) INT32 _coordCMDEval::execute( MsgHeader *pMsg, pmdEDUCB *cb, INT64 &contextID, rtnContextBuf *buf ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY( COORD_EVAL_EXE ) ; spdSession *session = NULL ; contextID = -1 ; CHAR *pQuery = NULL ; BSONObj procedures ; spdCoordDownloader downloader( this, cb ) ; BSONObj runInfo ; rc = msgExtractQuery( (CHAR*)pMsg, NULL, NULL, NULL, NULL, &pQuery, NULL, NULL, NULL ); if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to extract eval msg:%d", rc) ; goto error ; } try { procedures = BSONObj( pQuery ) ; PD_LOG( PDDEBUG, "eval:%s", procedures.toString().c_str() ) ; } catch ( std::exception &e ) { PD_LOG( PDERROR, "unexpected err happened:%s", e.what() ) ; rc = SDB_SYS ; goto error ; } session = SDB_OSS_NEW _spdSession() ; if ( NULL == session ) { PD_LOG( PDERROR, "failed to allocate mem." ) ; rc = SDB_OOM ; goto error ; } rc = session->eval( procedures, &downloader, cb ) ; if ( SDB_OK != rc ) { const BSONObj &errmsg = session->getErrMsg() ; if ( !errmsg.isEmpty() ) { *buf = rtnContextBuf( errmsg.getOwned() ) ; } PD_LOG( PDERROR, "failed to eval store procedure:%d", rc ) ; goto error ; } if ( FMP_RES_TYPE_VOID != session->resType() ) { rc = _buildContext( session, cb, contextID ) ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to prepare reply msg:%d", rc ) ; goto error ; } } runInfo = BSON( FIELD_NAME_RTYPE << session->resType() ) ; *buf = rtnContextBuf( runInfo ) ; done: if ( -1 == contextID ) { SAFE_OSS_DELETE( session ) ; } PD_TRACE_EXITRC( COORD_EVAL_EXE, rc ) ; return rc ; error: if ( contextID >= 0 ) { pmdGetKRCB()->getRTNCB()->contextDelete( contextID, cb ) ; contextID = -1 ; } goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__IXMKEYGEN__GETKEYS, "_ixmKeyGenerator::_getKeys" ) INT32 _getKeys( vector<const CHAR *> &fieldNames, const BSONObj &obj, BSONObjSet &keys, BSONElement *arrEle ) const { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__IXMKEYGEN__GETKEYS ); #define IXM_DEFAULT_FIELD_NUM 3 BSONElement eleOnStack[IXM_DEFAULT_FIELD_NUM] ; BSONElement *keyEles = NULL ; const CHAR *arrEleName = NULL ; UINT32 arrElePos = 0 ; UINT32 eooNum = 0 ; if ( IXM_DEFAULT_FIELD_NUM < fieldNames.size() ) { keyEles = new(std::nothrow) BSONElement[fieldNames.size()] ; if ( NULL == keyEles ) { PD_LOG( PDERROR, "failed to allocalte mem." ) ; rc = SDB_OOM ; goto error ; } } else { keyEles = ( BSONElement* )eleOnStack ; } for ( UINT32 i = 0; i < fieldNames.size(); i++ ) { const CHAR *name = fieldNames.at( i ) ; SDB_ASSERT( '\0' != name[0], "can not be empty" ) ; BSONElement &e = keyEles[i] ; e = obj.getFieldDottedOrArray( name ) ; if ( e.eoo() ) { ++eooNum ; continue ; } else if ( Array == e.type() ) { if ( !arrEle->eoo() ) { PD_LOG( PDERROR, "At most one array can be in the key:", arrEle->fieldName(), e.fieldName() ) ; rc = SDB_IXM_MULTIPLE_ARRAY ; goto error ; } else { *arrEle = e ; arrEleName = name ; arrElePos = i ; } } else { continue ; } } if ( fieldNames.size() == eooNum ) { rc = SDB_OK ; goto done ; } else if ( !arrEle->eoo() ) { rc = _genKeyWithArrayEle( keyEles, fieldNames.size(), arrEle, arrEleName, arrElePos, keys ) ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to gen keys with array element:%d", rc ) ; goto error ; } } else { rc = _genKeyWithNormalEle( keyEles, fieldNames.size(), keys ) ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to gen keys with normal element:%d", rc ) ; goto error ; } } done: if ( IXM_DEFAULT_FIELD_NUM < fieldNames.size() && NULL != keyEles ) { delete []keyEles ; } PD_TRACE_EXITRC ( SDB__IXMKEYGEN__GETKEYS, rc ); return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__DMS_LOBDIRECTOUTBUF_DOIT, "_dmsLobDirectOutBuffer::doit" ) INT32 _dmsLobDirectOutBuffer::doit( const tuple **pTuple ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY( SDB__DMS_LOBDIRECTOUTBUF_DOIT ) ; rc = prepare() ; if ( rc ) { goto error ; } if ( _aligned ) { INT32 offset1 = -1 ; INT32 offset2 = -1 ; UINT32 readLen = 0 ; INT64 fOffset = 0 ; if ( _t.offset != _usrOffset ) { offset1 = _t.offset ; } if ( _t.size != _usrSize ) { offset2 = _t.offset + _t.size - OSS_FILE_DIRECT_IO_ALIGNMENT ; } if ( offset1 >= 0 && offset2 >= 0 && offset2 - offset1 <= DMS_SEQ_READ_FAN_THRESHOLD && _pageID >= 0 && 0 == ( _newestMask & UTIL_WRITE_NEWEST_BOTH ) ) { UINT32 len = OSS_FILE_DIRECT_IO_ALIGNMENT + offset2 - offset1 ; fOffset = _pFile->pageID2Offset( _pageID, (UINT32)offset1 ) ; rc = _pFile->readRaw( fOffset, len, _t.buf, readLen, _cb, TRUE ) ; if ( rc ) { PD_LOG( PDERROR, "Read date[PageID:%u, Offset:%u, Len:%u] " "failed, rc: %d", _pageID, offset1, len, rc ) ; goto error ; } offset1 = -1 ; offset2 = -1 ; } if ( offset1 >= 0 ) { if ( OSS_BIT_TEST( _newestMask, UTIL_WRITE_NEWEST_HEADER ) ) { ossMemset( _t.buf, 0, _usrOffset - offset1 ) ; } else { fOffset = _pFile->pageID2Offset( _pageID, (UINT32)offset1 ) ; rc = _pFile->readRaw( fOffset, OSS_FILE_DIRECT_IO_ALIGNMENT, _t.buf, readLen, _cb, TRUE ) ; if ( rc ) { PD_LOG( PDERROR, "Read date[PageID:%u, Offset:%u, Len:%u] " "failed, rc: %d", _pageID, offset1, OSS_FILE_DIRECT_IO_ALIGNMENT, rc ) ; goto error ; } } } if ( offset2 >= 0 ) { if ( OSS_BIT_TEST( _newestMask, UTIL_WRITE_NEWEST_TAIL ) ) { ossMemset( _t.buf + offset2 - _t.offset, 0, _t.size - ( _usrSize + _usrOffset - _t.offset ) ) ; } else { fOffset = _pFile->pageID2Offset( _pageID, (UINT32)offset2 ) ; rc = _pFile->readRaw( fOffset, OSS_FILE_DIRECT_IO_ALIGNMENT, _t.buf + offset2 - _t.offset, readLen, _cb, TRUE ) ; if ( rc ) { PD_LOG( PDERROR, "Read date[PageID:%u, Offset:%u, Len:%u] " "failed, rc: %d", _pageID, offset2, OSS_FILE_DIRECT_IO_ALIGNMENT, rc ) ; goto error ; } } } ossMemcpy( _t.buf + _usrOffset - _t.offset, _usrBuf, _usrSize ) ; } if ( pTuple ) { *pTuple = &_t ; } done: PD_TRACE_EXITRC( SDB__DMS_LOBDIRECTOUTBUF_DOIT, rc ) ; return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__IXMKEYGEN__GENKEYSWITHARRELE, "_ixmKeyGenerator::_genKeyWithArrayEle" ) INT32 _genKeyWithArrayEle( BSONElement *keyEles, UINT32 eleNum, const BSONElement *arrElement, const CHAR *arrEleName, UINT32 arrElePos, BSONObjSet &keys ) const { PD_TRACE_ENTRY ( SDB__IXMKEYGEN__GENKEYSWITHARRELE ); INT32 rc = SDB_OK ; BSONObj arrObj = arrElement->embeddedObject() ; if ( arrObj.firstElement().eoo() ) { keyEles[arrElePos] = *arrElement ; rc = _genKeyWithNormalEle( keyEles, eleNum, keys ) ; if ( SDB_OK != rc ) { goto error ; } } if ( '\0' == *arrEleName ) { BSONObjIterator itr( arrObj ) ; BSONElement &e = keyEles[arrElePos] ; while ( itr.more() ) { e = itr.next() ; rc = _genKeyWithNormalEle( keyEles, eleNum, keys ) ; if ( SDB_OK != rc ) { goto error ; } } } else { BSONObjIterator itr( arrObj ) ; while ( itr.more() ) { const CHAR *dottedName = arrEleName ; BSONElement next = itr.next() ; if ( Object == next.type() ) { BSONElement e = next.embeddedObject() .getFieldDottedOrArray( dottedName ) ; if ( Array == e.type() ) { rc = _genKeyWithArrayEle(keyEles, eleNum, &e, dottedName, arrElePos, keys) ; if ( SDB_OK != rc ) { goto error ; } else { continue ; } } else { keyEles[arrElePos] = e ; } } else { keyEles[arrElePos] = BSONElement() ; } rc = _genKeyWithNormalEle( keyEles, eleNum, keys ) ; if ( SDB_OK != rc ) { goto error ; } } } done: PD_TRACE_EXITRC( SDB__IXMKEYGEN__GENKEYSWITHARRELE, rc ) ; return rc ; error: goto done ; }
INT32 _qgmPlNLJoin::_fetchNext( qgmFetchOut &next ) { PD_TRACE_ENTRY( SDB__QGMPLNLJOIN__FETCHNEXT ) ; INT32 rc = SDB_OK ; qgmFetchOut fetch ; do { if ( _innerEnd ) { rc = _outer->fetchNext( _outerF ) ; if ( SDB_OK != rc ) { goto error ; } rc = _modifyInnerCondition( _outerF.obj ) ; if ( SDB_OK != rc ) { goto error ; } rc = _inner->execute( _eduCB ) ; if ( SDB_OK != rc ) { goto error ; } _innerEnd = FALSE ; _notMatched = TRUE ; _innerF->obj = BSONObj() ; } rc = _inner->fetchNext( *_innerF ) ; if ( SDB_DMS_EOC == rc ) { _innerEnd = TRUE ; if ( SQL_GRAMMAR::INNERJOIN == _joinType ) { _innerF->obj = BSONObj() ; continue ; } else { if ( _notMatched ) { rc = SDB_OK ; break ; } else { continue ; } } } else if ( SDB_OK != rc ) { goto error ; } else { if ( _notMatched ) { _notMatched = FALSE ; } break ; } } while ( TRUE ) ; fetch.alias = *_outerAlias ; fetch.obj = _outerF.obj ; fetch.next = _innerF ; fetch.next->obj = _innerF->obj ; fetch.next->alias = *_innerAlias ; if ( !_merge ) { next.alias = fetch.alias ; next.obj = fetch.obj ; next.next = fetch.next ; } else { next.obj = fetch.mergedObj() ; } done: PD_TRACE_EXITRC( SDB__QGMPLNLJOIN__FETCHNEXT, rc ) ; return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__SDB_DMSCB_DUMPINFO2, "_SDB_DMSCB::dumpInfo" ) void _SDB_DMSCB::dumpInfo ( std::set<monCollectionSpace> &csList, BOOLEAN sys ) { PD_TRACE_ENTRY ( SDB__SDB_DMSCB_DUMPINFO2 ); dmsStorageUnit *su = NULL ; INT64 totalDataFreeSize = 0 ; INT64 totalIndexFreeSize = 0 ; INT64 totalLobFreeSize = 0 ; ossScopedLock _lock(&_mutex, SHARED) ; #if defined (_WINDOWS) std::map<const CHAR*, dmsStorageUnitID, cmp_cscb>::const_iterator it ; #elif defined (_LINUX) std::map<const CHAR*, dmsStorageUnitID>::const_iterator it ; #endif for ( it = _cscbNameMap.begin(); it != _cscbNameMap.end(); it++ ) { dmsStorageUnitID suID = (*it).second ; SDB_DMS_CSCB *cscb = _cscbVec[suID] ; if ( !cscb ) { continue ; } su = cscb->_su ; SDB_ASSERT ( su, "storage unit pointer can't be NULL" ) ; if ( !sys && dmsIsSysCSName(cscb->_name) ) { continue ; } else if ( dmsIsSysCSName(cscb->_name) && 0 == ossStrcmp(cscb->_name, SDB_DMSTEMP_NAME ) ) { continue ; } monCollectionSpace cs ; dmsStorageUnitStat statInfo ; su->getStatInfo( statInfo ) ; totalDataFreeSize = su->totalFreeSize( DMS_SU_DATA ) + statInfo._totalDataFreeSpace ; totalIndexFreeSize = su->totalFreeSize( DMS_SU_INDEX ) + statInfo._totalIndexFreeSpace ; totalLobFreeSize = su->totalFreeSize( DMS_SU_LOB ) ; ossMemset ( cs._name, 0, sizeof(cs._name) ) ; ossStrncpy ( cs._name, cscb->_name, DMS_COLLECTION_SPACE_NAME_SZ); cs._pageSize = su->getPageSize() ; cs._lobPageSize = su->getLobPageSize() ; cs._totalSize = su->totalSize() ; cs._clNum = statInfo._clNum ; cs._totalRecordNum = statInfo._totalCount ; cs._freeSize = totalDataFreeSize + totalIndexFreeSize + totalLobFreeSize ; cs._totalDataSize = su->totalSize( DMS_SU_DATA ) ; cs._freeDataSize = totalDataFreeSize ; cs._totalIndexSize = su->totalSize( DMS_SU_INDEX ) ; cs._freeIndexSize = totalIndexFreeSize ; cs._totalLobSize = su->totalSize( DMS_SU_LOB ) ; cs._freeLobSize = totalLobFreeSize ; su->dumpInfo ( cs._collections, sys ) ; csList.insert ( cs ) ; } PD_TRACE_EXIT ( SDB__SDB_DMSCB_DUMPINFO2 ); }
// PD_TRACE_DECLARE_FUNCTION ( SDB__MIGLOADJSONPS__RUN, "migMaster::run" ) INT32 migMaster::run( pmdEDUCB *cb ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__MIGLOADJSONPS__RUN ); UINT32 startOffset = 0 ; UINT32 size = 0 ; UINT32 startBlock = 0 ; UINT32 endBlock = 0 ; pmdKRCB *krcb = pmdGetKRCB () ; pmdEDUMgr *eduMgr = krcb->getEDUMgr () ; SDB_DMSCB *dmsCB = krcb->getDMSCB () ; EDUID agentEDU = PMD_INVALID_EDUID ; BOOLEAN writable = FALSE ; BOOLEAN noClearFlag = FALSE ; dmsMBContext *mbContext = NULL ; UINT32 line = 0 ; UINT32 column = 0 ; UINT32 success = 0 ; UINT32 failure = 0 ; UINT16 clFlag = 0 ; dmsStorageUnitID suID = DMS_INVALID_CS ; dmsStorageUnit *su = NULL ; initWorker dataWorker ; pmdEDUEvent event ; dmsStorageLoadOp dmsLoadExtent ; sendMsgToClient ( "Load start" ) ; rc = dmsCB->writable( cb ) ; if ( rc ) { PD_LOG ( PDERROR, "Database is not writable, rc = %d", rc ) ; goto error; } writable = TRUE; rc = rtnCollectionSpaceLock ( _pParameters->pCollectionSpaceName, dmsCB, FALSE, &su, suID ) ; if ( rc ) { if ( SDB_DMS_CS_NOTEXIST == rc ) { sendMsgToClient ( "Error: collection space not exist" ) ; } PD_LOG ( PDERROR, "Failed to lock collection space, rc=%d", rc ) ; goto error ; } dmsLoadExtent.init ( su ) ; rc = su->data()->getMBContext( &mbContext, _pParameters->pCollectionName, EXCLUSIVE ) ; if ( rc ) { if ( SDB_DMS_NOTEXIST == rc ) { sendMsgToClient ( "Error: collection not exist" ) ; } PD_LOG ( PDERROR, "Failed to lock collection, rc=%d", rc ) ; goto error ; } clFlag = mbContext->mb()->_flag ; if ( DMS_IS_MB_DROPPED( clFlag ) ) { PD_LOG( PDERROR, "Collection is droped" ) ; rc = SDB_COLLECTION_LOAD ; sendMsgToClient ( "Collection is droped" ) ; goto error ; } else if ( DMS_IS_MB_LOAD ( clFlag ) ) { PD_LOG( PDERROR, "Collection is loading" ) ; rc = SDB_COLLECTION_LOAD ; sendMsgToClient ( "Collection is loading" ) ; noClearFlag = TRUE ; goto error ; } dmsLoadExtent.setFlagLoad ( mbContext->mb() ) ; dmsLoadExtent.setFlagLoadLoad ( mbContext->mb() ) ; mbContext->mbUnlock() ; dataWorker.pMaster = this ; dataWorker.masterEDUID = cb->getID() ; dataWorker.pSu = su ; dataWorker.clLID = mbContext->clLID() ; dataWorker.collectionID = mbContext->mbID() ; for ( UINT32 i = 0; i < _pParameters->workerNum ; ++i ) { eduMgr->startEDU ( EDU_TYPE_LOADWORKER, &dataWorker, &agentEDU ) ; } while ( TRUE ) { rc = _checkErrAndRollback ( cb, &dmsLoadExtent, mbContext, success, failure ) ; if ( SDB_TIMEOUT != rc && rc ) { PD_LOG ( PDERROR, "Failed to call _checkErrAndRollback, rc=%d", rc ) ; goto error ; } rc = _parser->getNextRecord ( startOffset, size, &line, &column, _ppBucket ) ; if ( rc ) { if ( rc == SDB_EOF ) { rc = _stopAndWaitWorker ( cb, success, failure ) ; PD_RC_CHECK ( rc, PDERROR, "Failed to call _stopAndWaitWorker, rc=%d", rc ) ; break ; } sendMsgToClient ( "Error: Parse Json error in line: %u," " column: %u", line, column ) ; PD_LOG ( PDERROR, "Failed to parseJSONs getNextRecord,rc=%d", rc ) ; goto error1 ; } rc = getBlockFromPointer ( startOffset, size, startBlock, endBlock ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to get block from pointer, rc=%d", rc ) ; goto error1 ; } for ( UINT32 i = startBlock; i <= endBlock; ++i ) { _ppBucket[i]->inc() ; } pushToQueue ( startOffset, size, line, column ) ; } // while ( !cb->isForced() ) sendMsgToClient ( "build index" ) ; rc = dmsLoadExtent.loadBuildPhase ( mbContext, cb, _pParameters->isAsynchronous, this, &success, &failure ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to load data, rc=%d", rc ) ; goto error ; } done: if ( su && mbContext && !noClearFlag ) { rc = mbContext->mbLock( EXCLUSIVE ) ; if ( SDB_OK == rc ) { if ( dmsLoadExtent.isFlagLoadLoad ( mbContext->mb() ) ) { dmsLoadExtent.clearFlagLoadLoad ( mbContext->mb() ) ; } if ( dmsLoadExtent.isFlagLoadBuild ( mbContext->mb() ) ) { dmsLoadExtent.clearFlagLoadBuild ( mbContext->mb() ) ; } if ( dmsLoadExtent.isFlagLoad ( mbContext->mb() ) ) { dmsLoadExtent.clearFlagLoad ( mbContext->mb() ) ; } } else { PD_LOG ( PDERROR, "Failed to lock collection, rc=%d", rc ) ; } } sendMsgToClient ( "success json: %u, failure json: %u", success, failure ) ; sendMsgToClient ( "Load end" ) ; if ( su && mbContext ) { su->data()->releaseMBContext( mbContext ) ; } if ( DMS_INVALID_CS != suID ) { dmsCB->suUnlock ( suID ) ; } if ( writable ) { dmsCB->writeDown( cb ); } PD_TRACE_EXITRC ( SDB__MIGLOADJSONPS__RUN, rc ); return rc ; error: goto done ; error1: _stopAndWaitWorker ( cb, success, failure ) ; sendMsgToClient ( "Error: rollback all data" ) ; failure += success ; success = 0 ; rc = dmsLoadExtent.loadRollbackPhase ( mbContext ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to rollback, rc=%d", rc ) ; sendMsgToClient ( "Error: Failed to rollback, rc = %d", rc ) ; goto error ; } goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__SDB_DMSCB__CSCBNMREMV, "_SDB_DMSCB::_CSCBNameRemove" ) INT32 _SDB_DMSCB::_CSCBNameRemove ( const CHAR *pName, _pmdEDUCB *cb, SDB_DPSCB *dpsCB, BOOLEAN onlyEmpty, SDB_DMS_CSCB *&pCSCB ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__SDB_DMSCB__CSCBNMREMV ); dmsStorageUnitID suID ; UINT32 csLID = ~0 ; dpsTransCB *pTransCB = pmdGetKRCB()->getTransCB(); BOOLEAN isTransLocked = FALSE; BOOLEAN isReserved = FALSE; UINT32 logRecSize = 0; dpsMergeInfo info ; dpsLogRecord &record = info.getMergeBlock().record(); #if defined (_WINDOWS) std::map<const CHAR*, dmsStorageUnitID, cmp_cscb>::const_iterator it ; #elif defined (_LINUX) std::map<const CHAR*, dmsStorageUnitID>::const_iterator it ; #endif std::vector<SDB_DMS_CSCB*> *pVecCscb = NULL ; pCSCB = NULL ; _mutex.get_shared () ; if ( _cscbNameMap.end() == (it = _cscbNameMap.find( pName ))) { _mutex.release_shared () ; rc = SDB_DMS_CS_NOTEXIST ; goto error ; } suID = (*it).second ; _mutex.release_shared () ; if ( NULL != dpsCB ) { rc = dpsCSDel2Record( pName, record ) ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to build record:%d",rc ) ; goto error ; } rc = dpsCB->checkSyncControl( record.alignedLen(), cb ) ; PD_RC_CHECK( rc, PDERROR, "Check sync control failed, rc: %d", rc ) ; logRecSize = record.alignedLen() ; rc = pTransCB->reservedLogSpace( logRecSize, cb ); PD_RC_CHECK( rc, PDERROR, "failed to reserved log space(length=%u)", logRecSize ); isReserved = TRUE ; } retry : if ( SDB_OK != _latchVec[suID]->lock_w( OSS_ONE_SEC ) ) { rc = SDB_LOCK_FAILED ; goto error ; } if ( !_mutex.try_get() ) { _latchVec[suID]->release_w () ; goto retry ; } _latchVec[suID]->release_w () ; if ( _cscbNameMap.end() == (it = _cscbNameMap.find(pName)) || suID != (*it).second ) { _mutex.release () ; rc = SDB_DMS_CS_NOTEXIST ; goto error ; } if ( _cscbVec[suID] ) { pVecCscb = &_cscbVec ; } else if ( _delCscbVec[suID] ) { pVecCscb = &_delCscbVec ; } if ( pVecCscb ) { pCSCB = (*pVecCscb)[ suID ] ; SDB_ASSERT ( pCSCB->_su, "su can't be null" ) ; if ( onlyEmpty && 0 != pCSCB->_su->data()->getCollectionNum() ) { _mutex.release () ; rc = SDB_DMS_CS_NOT_EMPTY ; goto error ; } csLID = pCSCB->_su->LogicalCSID() ; if ( cb ) { rc = pTransCB->transLockTryX( cb, csLID ); if ( rc ) { _mutex.release () ; PD_LOG ( PDERROR, "Failed to lock collection-space(rc=%d)", rc ) ; goto error ; } isTransLocked = TRUE ; } (*pVecCscb)[suID] = NULL ; } _cscbNameMap.erase(pName) ; _freeList.push_back ( suID ) ; if ( dpsCB ) { info.setInfoEx( csLID, ~0, DMS_INVALID_EXTENT, cb ) ; rc = dpsCB->prepare ( info ) ; if ( rc ) { _mutex.release () ; PD_LOG ( PDERROR, "Failed to insert cscrt into log, rc = %d", rc ) ; goto error ; } dpsCB->writeData( info ) ; } _mutex.release () ; done : if ( isTransLocked ) { pTransCB->transLockRelease( cb, csLID ); } if ( isReserved ) { pTransCB->releaseLogSpace( logRecSize, cb ); } PD_TRACE_EXITRC ( SDB__SDB_DMSCB__CSCBNMREMV, rc ); return rc ; error : pCSCB = NULL ; goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__MIGWORKER__IMPORT, "migWorker::importData" ) INT32 migWorker::importData ( EDUID masterEDUID, dmsStorageUnit *su, UINT16 collectionID, UINT32 clLID, BOOLEAN isAsynchr, pmdEDUCB *cb ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__MIGWORKER__IMPORT ); pmdKRCB *krcb = pmdGetKRCB () ; pmdEDUMgr *eduMgr = krcb->getEDUMgr() ; BOOLEAN isLast = FALSE ; BOOLEAN isFirst = TRUE ; BSONObj record ; dmsStorageLoadOp dmsLoadExtent ; _workerReturn *workRe = NULL ; _dmsMBContext *mbContext = NULL ; SDB_ASSERT ( su, "su is NULL" ) ; dmsLoadExtent.init ( su ) ; workRe = SDB_OSS_NEW _workerReturn() ; if ( !workRe ) { rc = SDB_OOM ; PD_LOG ( PDERROR, "memory error" ) ; goto error ; } rc = su->data()->getMBContext( &mbContext, collectionID, clLID, DMS_INVALID_CLID, -1 ) ; if ( rc ) { PD_LOG( PDERROR, "Failed to get dms mb context, rc: %d", rc ) ; goto error ; } workRe->success = 0 ; workRe->failure = 0 ; workRe->rc = 0 ; rc = _csvParser.init( _master->_autoAddField, _master->_autoCompletion, _master->_isHeaderline, _master->_delChar, _master->_delField, _master->_delRecord ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to csv parser initialize, rc=%d", rc ) ; goto error ; } rc = _csvParser.parseHeader( _master->_pFields, _master->_fieldsSize ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to parse csv header, rc=%d", rc ) ; goto error ; } while ( !_master->_exitSignal && !cb->isInterrupted() && !cb->isDisconnected() ) { rc = _getBsonFromQueue ( cb, record ) ; if ( rc ) { if ( SDB_MIG_END_OF_QUEUE == rc ) { isLast = TRUE ; rc = SDB_OK ; if ( isFirst ) { goto done ; } } else if ( SDB_INVALIDARG == rc ) { ++workRe->failure ; continue ; } else { PD_LOG ( PDERROR, "Failed to get bson from queue, rc=%d", rc ) ; goto error ; } } rc = dmsLoadExtent.pushToTempDataBlock( mbContext, cb, record, isLast, isAsynchr ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to import to block, rc=%d", rc ) ; goto error ; } if ( isLast ) { goto done ; } ++workRe->success ; isFirst = FALSE ; } goto error ; done: if ( su && mbContext ) { su->data()->releaseMBContext( mbContext ) ; } workRe->rc = rc ; rc = eduMgr->postEDUPost ( masterEDUID, PMD_EDU_EVENT_MSG, PMD_EDU_MEM_ALLOC, workRe ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to postEDUPost, rc=%d", rc ) ; } PD_TRACE_EXITRC ( SDB__MIGWORKER__IMPORT, rc ); return rc ; error: _master->_exitSignal = TRUE ; if ( workRe ) { workRe->failure += workRe->success ; workRe->success = 0 ; } goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__SDB_DMSCB__CSCBNMREMVP1, "_SDB_DMSCB::_CSCBNameRemoveP1" ) INT32 _SDB_DMSCB::_CSCBNameRemoveP1 ( const CHAR *pName, _pmdEDUCB *cb, SDB_DPSCB *dpsCB ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__SDB_DMSCB__CSCBNMREMVP1 ); dmsStorageUnitID suID ; SDB_DMS_CSCB *pCSCB = NULL; #if defined (_WINDOWS) std::map<const CHAR*, dmsStorageUnitID, cmp_cscb>::iterator it ; #elif defined (_LINUX) std::map<const CHAR*, dmsStorageUnitID>::iterator it ; #endif _mutex.get_shared () ; if ( _cscbNameMap.end() == (it = _cscbNameMap.find( pName ))) { _mutex.release_shared () ; rc = SDB_DMS_CS_NOTEXIST ; goto error ; } suID = (*it).second ; _mutex.release_shared () ; retry : if ( SDB_OK != _latchVec[suID]->lock_w( OSS_ONE_SEC ) ) { rc = SDB_LOCK_FAILED ; goto error ; } if ( !_mutex.try_get() ) { _latchVec[suID]->release_w () ; goto retry ; } _latchVec[suID]->release_w () ; if ( _cscbNameMap.end() == (it = _cscbNameMap.find(pName)) || suID != (*it).second ) { _mutex.release () ; rc = SDB_DMS_CS_NOTEXIST ; goto error ; } if ( _cscbVec[suID] ) { pCSCB = _cscbVec[suID] ; SDB_ASSERT ( pCSCB->_name, "cs-name can't be null" ); _delCscbVec[ suID ] = pCSCB; _cscbVec[suID] = NULL; } else { if ( _delCscbVec[suID] ) { rc = SDB_DMS_CS_DELETING; } else { SDB_ASSERT( FALSE, "faint, why cs is in map?" ); PD_LOG( PDWARNING, "couldn't find the cscb(name:%s)", pName ); _cscbNameMap.erase( it ); rc = SDB_DMS_CS_NOTEXIST ; } _mutex.release () ; goto error ; } _mutex.release () ; done : PD_TRACE_EXITRC ( SDB__SDB_DMSCB__CSCBNMREMVP1, rc ); return rc ; error : goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__NETEVNHND_SYNCCONN, "_netEventHandler::syncConnect" ) INT32 _netEventHandler::syncConnect( const CHAR *hostName, const CHAR *serviceName ) { SDB_ASSERT( NULL != hostName, "hostName should not be NULL" ) ; SDB_ASSERT( NULL != serviceName, "serviceName should not be NULL" ) ; INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__NETEVNHND_SYNCCONN ); if ( _isConnected ) { close() ; } _isAcitve = TRUE ; /* try { boost::system::error_code ec ; tcp::resolver::query query ( tcp::v4(), hostName, serviceName ) ; tcp::resolver resolver ( _frame->ioservice() ) ; tcp::resolver::iterator itr = resolver.resolve ( query ) ; ip::tcp::endpoint endpoint = *itr ; _sock.open( tcp::v4()) ; _sock.connect( endpoint, ec ) ; if ( ec ) { if ( boost::asio::error::would_block == ec ) { rc = _complete( _sock.native() ) ; if ( SDB_OK != rc ) { _sock.close() ; PD_LOG ( PDWARNING, "Failed to connect to %s: %s: timeout", hostName, serviceName ) ; goto error ; } } else { PD_LOG ( PDWARNING, "Failed to connect to %s: %s: %s", hostName, serviceName, ec.message().c_str()) ; rc = SDB_NET_CANNOT_CONNECT ; _sock.close() ; goto error ; } } } catch ( boost::system::system_error &e ) { PD_LOG ( PDWARNING, "Failed to connect to %s: %s: %s", hostName, serviceName, e.what() ) ; rc = SDB_NET_CANNOT_CONNECT ; _sock.close() ; goto error ; } */ UINT16 port = 0 ; rc = ossGetPort( serviceName, port ) ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to get port :%s", serviceName ) ; goto error ; } { _ossSocket sock( hostName, port ) ; rc = sock.initSocket() ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to init socket:%d", rc ) ; goto error ; } sock.closeWhenDestruct( FALSE ) ; rc = sock.connect() ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to connect remote[%s:%s], rc:%d", hostName, serviceName, rc ) ; goto error ; } try { _sock.assign( tcp::v4(), sock.native() ) ; } catch ( std::exception &e ) { PD_LOG( PDERROR, "unexpected err happened:%s", e.what() ) ; rc = SDB_SYS ; sock.close() ; _sock.close() ; goto error ; } } setOpt() ; done: PD_TRACE_EXITRC ( SDB__NETEVNHND_SYNCCONN, rc ); return rc ; error: goto done ; }
// PD_TRACE_DECLARE_FUNCTION ( SDB__SDB_DMSCB__CSCBNMREMVP2, "_SDB_DMSCB::_CSCBNameRemoveP2" ) INT32 _SDB_DMSCB::_CSCBNameRemoveP2 ( const CHAR *pName, _pmdEDUCB *cb, SDB_DPSCB *dpsCB, SDB_DMS_CSCB *&pCSCB ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY ( SDB__SDB_DMSCB__CSCBNMREMVP2 ); dmsStorageUnitID suID ; UINT32 csLID = ~0 ; #if defined (_WINDOWS) std::map<const CHAR*, dmsStorageUnitID, cmp_cscb>::iterator it ; #elif defined (_LINUX) std::map<const CHAR*, dmsStorageUnitID>::iterator it ; #endif pCSCB = NULL ; { ossScopedLock _lock(&_mutex, EXCLUSIVE) ; if ( _cscbNameMap.end() == (it = _cscbNameMap.find(pName)) ) { SDB_ASSERT( FALSE, "faint, why the cs is not in map?" ); rc = SDB_DMS_CS_NOTEXIST ; goto error ; } suID = (*it).second ; if ( _delCscbVec[suID] ) { pCSCB = _delCscbVec[suID] ; SDB_ASSERT ( pCSCB->_su, "su can't be null" ) ; csLID = pCSCB->_su->LogicalCSID () ; _delCscbVec[suID] = NULL ; } _cscbNameMap.erase(it) ; _freeList.push_back ( suID ) ; if ( dpsCB ) { dpsMergeInfo info ; info.setInfoEx( csLID, ~0, DMS_INVALID_EXTENT, cb ) ; dpsLogRecord &record = info.getMergeBlock().record(); rc = dpsCSDel2Record( pName, record ) ; PD_RC_CHECK( rc, PDERROR, "failed to build record:%d", rc ); rc = dpsCB->prepare ( info ) ; if ( rc ) { _mutex.release () ; PD_LOG ( PDERROR, "Failed to insert cscrt into log, rc = %d", rc ) ; goto error ; } dpsCB->writeData( info ) ; } } done : PD_TRACE_EXITRC ( SDB__SDB_DMSCB__CSCBNMREMVP2, rc ); return rc ; error : pCSCB = NULL ; goto done ; }
// 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 ; } _lastRecvTick = pmdGetDBTick() ; _lastBeatTick = _lastRecvTick ; 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__SDB_DMSCB_ADDCS, "_SDB_DMSCB::addCollectionSpace" ) INT32 _SDB_DMSCB::addCollectionSpace(const CHAR * pName, UINT32 topSequence, _dmsStorageUnit * su, _pmdEDUCB *cb, SDB_DPSCB *dpsCB ) { INT32 rc = SDB_OK ; dmsStorageUnitID suID ; SDB_DMS_CSCB *cscb = NULL ; BOOLEAN isReserved = FALSE; UINT32 logRecSize = 0; dpsMergeInfo info ; dpsLogRecord &record = info.getMergeBlock().record(); INT32 pageSize = 0 ; INT32 lobPageSz = 0 ; dpsTransCB *pTransCB = pmdGetKRCB()->getTransCB(); PD_TRACE_ENTRY ( SDB__SDB_DMSCB_ADDCS ); ossScopedLock _lock(&_mutex, EXCLUSIVE) ; if ( !pName || !su ) { rc = SDB_INVALIDARG ; goto error ; } rc = _CSCBNameLookup( pName, &cscb ) ; if ( SDB_OK == rc ) { rc = SDB_DMS_CS_EXIST; goto error; } else if ( rc != SDB_DMS_CS_NOTEXIST ) { goto error; } pageSize = su->getPageSize() ; lobPageSz = su->getLobPageSize() ; if ( NULL != dpsCB ) { rc = dpsCSCrt2Record( pName, pageSize, lobPageSz, record ) ; if ( SDB_OK != rc ) { PD_LOG( PDERROR, "failed to build record:%d",rc ) ; goto error ; } rc = dpsCB->checkSyncControl( record.alignedLen(), cb ) ; PD_RC_CHECK( rc, PDERROR, "Check sync control failed, rc: %d", rc ) ; logRecSize = record.alignedLen() ; rc = pTransCB->reservedLogSpace( logRecSize, cb ); PD_RC_CHECK( rc, PDERROR, "failed to reserved log space(length=%u)", logRecSize ); isReserved = TRUE ; } rc = _CSCBNameInsert ( pName, topSequence, su, suID ) ; if ( SDB_OK == rc ) { INT32 tempRC = SDB_OK ; tempRC = _joinPageCleanSU ( suID ) ; if ( tempRC ) { PD_LOG ( PDWARNING, "Failed to join storage unit to page clean history, " "rc = %d", tempRC ) ; } } if ( SDB_OK == rc && dpsCB ) { UINT32 suLID = su->LogicalCSID() ; info.setInfoEx( suLID, ~0, DMS_INVALID_EXTENT, cb ) ; rc = dpsCB->prepare ( info ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to insert cscrt into log, rc = %d", rc ) ; goto error ; } dpsCB->writeData( info ) ; } done : if ( isReserved ) { pTransCB->releaseLogSpace( logRecSize, cb ); } PD_TRACE_EXITRC ( SDB__SDB_DMSCB_ADDCS, rc ); return rc ; error : goto done ; }
// 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; }
INT32 restAdaptor::recvRequestBody( pmdRestSession *pSession, HTTP_PARSE_COMMON &common, CHAR **ppPath, INT32 &pathSize ) { INT32 rc = SDB_OK ; PD_TRACE_ENTRY( SDB__RESTADP_RECVREQBO ) ; SDB_ASSERT ( pSession, "pSession is NULL" ) ; SDB_ASSERT ( ppPath, "ppPath is NULL" ) ; httpConnection *pHttpCon = pSession->getRestConn() ; CHAR *pBuffer = NULL ; const CHAR *pContentLength = NULL ; CHAR *pUrl = NULL ; INT32 bodySize = 0 ; INT32 sumBodySize = 0 ; INT32 curRecvSize = 0 ; INT32 receivedSize = 0 ; INT32 tempSize = 0 ; INT32 urlSize = 0 ; rc = getHttpHeader( pSession, REST_STRING_CONLEN, &pContentLength ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to get http header, rc=%d", rc ) ; goto error ; } if ( pContentLength ) { bodySize = ossAtoi( pContentLength ) ; if ( bodySize > 0 ) { if ( bodySize > _maxHttpBodySize ) { rc = SDB_REST_RECV_SIZE ; PD_LOG ( PDERROR, "http body size %d greater than %d", bodySize, _maxHttpBodySize ) ; goto error ; } rc = pSession->allocBuff( bodySize + 1, &(pHttpCon->_pBodyBuf), sumBodySize ) ; if ( rc ) { PD_LOG ( PDERROR, "Unable to allocate %d bytes memory, rc=%d", bodySize, rc ) ; goto error ; } pBuffer = pHttpCon->_pBodyBuf ; pBuffer[bodySize] = 0 ; if ( pHttpCon->_pPartBody ) { ossMemcpy( pHttpCon->_pBodyBuf, pHttpCon->_pPartBody, pHttpCon->_partSize ) ; receivedSize = pHttpCon->_partSize ; } rc = pSession->recvData( pBuffer + receivedSize, bodySize - receivedSize, _timeout, TRUE, &curRecvSize, 0 ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to recv, rc=%d", rc ) ; goto error ; } receivedSize += curRecvSize ; urlSize = urlDecodeSize( pBuffer, receivedSize ) ; rc = pSession->allocBuff( urlSize + 1, &pUrl, tempSize ) ; if ( rc ) { PD_LOG ( PDERROR, "Unable to allocate %d bytes memory, rc=%d", urlSize + 1, rc ) ; goto error ; } urlDecode( pBuffer, receivedSize, &pUrl, urlSize ) ; pUrl[ urlSize ] = 0 ; _parse_http_query( pHttpCon, pUrl, urlSize ) ; } } rc = _convertMsg( pSession, common, ppPath, pathSize ) ; if ( rc ) { PD_LOG ( PDERROR, "Failed to build msg, rc=%d", rc ) ; goto error ; } pHttpCon->_common = common ; done: PD_TRACE_EXITRC( SDB__RESTADP_RECVREQBO, rc ) ; return rc ; error: goto done ; }