INT32 _pmdDataProcessor::_onDelReqMsg( MsgHeader * msg, SDB_DPSCB *dpsCB ) { INT32 rc = SDB_OK ; INT32 flags = 0 ; CHAR *pCollectionName = NULL ; CHAR *pDeletorBuffer = NULL ; CHAR *pHintBuffer = NULL ; rc = msgExtractDelete ( (CHAR *)msg , &flags, &pCollectionName, &pDeletorBuffer, &pHintBuffer ) ; PD_RC_CHECK( rc, PDERROR, "Session[%s] extract delete msg failed, rc: %d", getSession()->sessionName(), rc ) ; try { BSONObj deletor ( pDeletorBuffer ) ; BSONObj hint ( pHintBuffer ) ; MON_SAVE_OP_DETAIL( eduCB()->getMonAppCB(), msg->opCode, "CL:%s, Deletor:%s, Hint:%s", pCollectionName, deletor.toString().c_str(), hint.toString().c_str() ) ; PD_LOG ( PDDEBUG, "Session[%s] Delete: deletor: %s\nhint: %s", getSession()->sessionName(), deletor.toString().c_str(), hint.toString().c_str() ) ; rc = rtnDelete( pCollectionName, deletor, hint, flags, eduCB(), _pDMSCB, dpsCB ) ; } catch ( std::exception &e ) { PD_LOG ( PDERROR, "Session[%s] Failed to create deletor for " "DELETE: %s", getSession()->sessionName(), e.what () ) ; rc = SDB_INVALIDARG ; goto error ; } done: return rc ; error: goto done ; }
//PD_TRACE_DECLARE_FUNCTION ( COORD_OPERATORDEL_EXE, "_coordDeleteOperator::execute" ) INT32 _coordDeleteOperator::execute( MsgHeader *pMsg, pmdEDUCB *cb, INT64 &contextID, rtnContextBuf *buf ) { INT32 rc = SDB_OK ; INT32 rcTmp = SDB_OK ; PD_TRACE_ENTRY ( COORD_OPERATORDEL_EXE ) ; coordSendOptions sendOpt( TRUE ) ; coordSendMsgIn inMsg( pMsg ) ; coordProcessResult result ; ROUTE_RC_MAP nokRC ; result._pNokRC = &nokRC ; coordCataSel cataSel ; MsgRouteID errNodeID ; BSONObj boDeletor ; MsgOpDelete *pDelMsg = (MsgOpDelete *)pMsg ; INT32 oldFlag = pDelMsg->flags ; pDelMsg->flags |= FLG_DELETE_RETURNNUM ; contextID = -1 ; INT32 flag = 0; CHAR *pCollectionName = NULL ; CHAR *pDeletor = NULL ; CHAR *pHint = NULL ; rc = msgExtractDelete( (CHAR*)pMsg, &flag, &pCollectionName, &pDeletor, &pHint ) ; if( rc ) { PD_LOG( PDERROR,"Failed to parse delete request, rc: %d", rc ) ; pCollectionName = NULL ; goto error ; } try { boDeletor = BSONObj( pDeletor ) ; } catch ( std::exception &e ) { PD_RC_CHECK( SDB_INVALIDARG, PDERROR, "Delete failed, received unexpected error: %s", e.what() ) ; } MON_SAVE_OP_DETAIL( cb->getMonAppCB(), pMsg->opCode, "Collection:%s, Deletor:%s, Hint:%s, " "Flag:0x%08x(%u)", pCollectionName, boDeletor.toString().c_str(), BSONObj(pHint).toString().c_str(), oldFlag, oldFlag ) ; rc = cataSel.bind( _pResource, pCollectionName, cb, FALSE, TRUE ) ; if ( rc ) { PD_LOG( PDERROR, "Get or update collection[%s]'s catalog info " "failed, rc: %d", pCollectionName, rc ) ; goto error ; } retry: pDelMsg->version = cataSel.getCataPtr()->getVersion() ; pDelMsg->w = 0 ; rcTmp = doOpOnCL( cataSel, boDeletor, inMsg, sendOpt, cb, result ) ; if ( SDB_OK == rcTmp && nokRC.empty() ) { goto done ; } else if ( checkRetryForCLOpr( rcTmp, &nokRC, cataSel, inMsg.msg(), cb, rc, &errNodeID, TRUE ) ) { nokRC.clear() ; _groupSession.getGroupCtrl()->incRetry() ; goto retry ; } else { PD_LOG( PDERROR, "Delete failed on node[%s], rc: %d", routeID2String( errNodeID ).c_str(), rc ) ; goto error ; } done: if ( oldFlag & FLG_DELETE_RETURNNUM ) { contextID = _recvNum ; } if ( pCollectionName ) { PD_AUDIT_OP( AUDIT_DML, MSG_BS_DELETE_REQ, AUDIT_OBJ_CL, pCollectionName, rc, "DeletedNum:%u, Deletor:%s, Hint:%s, Flag:0x%08x(%u)", _recvNum, boDeletor.toString().c_str(), BSONObj(pHint).toString().c_str(), oldFlag, oldFlag ) ; } PD_TRACE_EXITRC ( COORD_OPERATORDEL_EXE, rc ) ; return rc ; error: if ( buf && nokRC.size() > 0 ) { *buf = rtnContextBuf( coordBuildErrorObj( _pResource, rc, cb, &nokRC ) ) ; } goto done ; }
INT32 _coordDeleteOperator::_prepareMainCLOp( coordCataSel &cataSel, coordSendMsgIn &inMsg, coordSendOptions &options, pmdEDUCB *cb, coordProcessResult &result ) { INT32 rc = SDB_OK ; MsgOpDelete *pDelMsg = ( MsgOpDelete* )inMsg.msg() ; INT32 flag = 0 ; CHAR *pCollectionName = NULL; CHAR *pDeletor = NULL; CHAR *pHint = NULL; CoordGroupSubCLMap &grpSubCl = cataSel.getGroup2SubsMap() ; CoordGroupSubCLMap::iterator it ; inMsg.data()->clear() ; rc = msgExtractDelete( (CHAR*)inMsg.msg(), &flag, &pCollectionName, &pDeletor, &pHint ) ; PD_RC_CHECK( rc, PDERROR, "Failed to parse delete request, rc: %d", rc ) ; try { BSONObj boDeletor( pDeletor ) ; BSONObj boHint( pHint ) ; BSONObj boNew ; CHAR *pBuff = NULL ; UINT32 buffLen = 0 ; UINT32 buffPos = 0 ; it = grpSubCl.begin() ; while( it != grpSubCl.end() ) { CoordSubCLlist &subCLLst = it->second ; netIOVec &iovec = inMsg._datas[ it->first ] ; netIOV ioItem ; ioItem.iovBase = (const CHAR*)inMsg.msg() + sizeof( MsgHeader ) ; ioItem.iovLen = ossRoundUpToMultipleX ( offsetof(MsgOpDelete, name) + pDelMsg->nameLength + 1, 4 ) - sizeof( MsgHeader ) ; iovec.push_back( ioItem ) ; boNew = _buildNewDeletor( boDeletor, subCLLst ) ; UINT32 roundLen = ossRoundUpToMultipleX( boNew.objsize(), 4 ) ; if ( buffPos + roundLen > buffLen ) { UINT32 alignLen = ossRoundUpToMultipleX( roundLen, DMS_PAGE_SIZE4K ) ; rc = cb->allocBuff( alignLen, &pBuff, &buffLen ) ; PD_RC_CHECK( rc, PDERROR, "Alloc buff[%u] failed, rc: %d", alignLen, rc ) ; _vecBlock.push_back( pBuff ) ; buffPos = 0 ; } ossMemcpy( &pBuff[ buffPos ], boNew.objdata(), boNew.objsize() ) ; ioItem.iovBase = &pBuff[ buffPos ] ; ioItem.iovLen = roundLen ; buffPos += roundLen ; iovec.push_back( ioItem ) ; ioItem.iovBase = boHint.objdata() ; ioItem.iovLen = boHint.objsize() ; iovec.push_back( ioItem ) ; ++it ; } } catch( std::exception &e ) { PD_LOG( PDERROR, "Parse delete message occur exception: %s", e.what() ) ; rc = SDB_SYS ; goto error ; } done: return rc ; error: _clearBlock( cb ) ; goto done ; }
//PD_TRACE_DECLARE_FUNCTION ( SDB_RTNCODEL_EXECUTE, "rtnCoordDelete::execute" ) INT32 rtnCoordDelete::execute( MsgHeader *pMsg, pmdEDUCB *cb, INT64 &contextID, rtnContextBuf *buf ) { INT32 rc = SDB_OK ; INT32 rcTmp = SDB_OK ; PD_TRACE_ENTRY ( SDB_RTNCODEL_EXECUTE ) ; pmdKRCB *pKrcb = pmdGetKRCB() ; CoordCB *pCoordcb = pKrcb->getCoordCB() ; netMultiRouteAgent *pRouteAgent = pCoordcb->getRouteAgent() ; // process define rtnSendOptions sendOpt( TRUE ) ; rtnSendMsgIn inMsg( pMsg ) ; rtnProcessResult result ; ROUTE_RC_MAP nokRC ; result._pNokRC = &nokRC ; CoordCataInfoPtr cataInfo ; MsgRouteID errNodeID ; UINT64 deleteNum = 0 ; inMsg._pvtData = ( CHAR* )&deleteNum ; inMsg._pvtType = PRIVATE_DATA_NUMBERLONG ; BSONObj boDeletor ; // fill default-reply(delete success) MsgOpDelete *pDelMsg = (MsgOpDelete *)pMsg ; INT32 oldFlag = pDelMsg->flags ; pDelMsg->flags |= FLG_DELETE_RETURNNUM ; contextID = -1 ; INT32 flag = 0; CHAR *pCollectionName = NULL ; CHAR *pDeletor = NULL ; CHAR *pHint = NULL ; rc = msgExtractDelete( (CHAR*)pMsg, &flag, &pCollectionName, &pDeletor, &pHint ) ; if( rc ) { PD_LOG( PDERROR,"Failed to parse delete request, rc: %d", rc ) ; pCollectionName = NULL ; goto error ; } try { boDeletor = BSONObj( pDeletor ) ; } catch ( std::exception &e ) { PD_RC_CHECK( SDB_INVALIDARG, PDERROR, "Delete failed, received unexpected error:%s", e.what() ) ; } // add last op info MON_SAVE_OP_DETAIL( cb->getMonAppCB(), pMsg->opCode, "Collection:%s, Deletor:%s, Hint:%s, " "Flag:0x%08x(%u)", pCollectionName, boDeletor.toString().c_str(), BSONObj(pHint).toString().c_str(), oldFlag, oldFlag ) ; rc = rtnCoordGetCataInfo( cb, pCollectionName, FALSE, cataInfo ) ; PD_RC_CHECK( rc, PDERROR, "Delete failed, failed to get the " "catalogue info(collection name: %s), rc: %d", pCollectionName, rc ) ; retry: do { pDelMsg->version = cataInfo->getVersion() ; pDelMsg->w = 0 ; if ( cataInfo->isMainCL() ) { rcTmp = doOpOnMainCL( cataInfo, boDeletor, inMsg, sendOpt, pRouteAgent, cb, result ) ; } else { rcTmp = doOpOnCL( cataInfo, boDeletor, inMsg, sendOpt, pRouteAgent, cb, result ) ; } }while( FALSE ) ; if ( SDB_OK == rcTmp && nokRC.empty() ) { goto done ; } else if ( checkRetryForCLOpr( rcTmp, &nokRC, inMsg.msg(), sendOpt._retryTimes, cataInfo, cb, rc, &errNodeID, TRUE ) ) { nokRC.clear() ; ++sendOpt._retryTimes ; goto retry ; } else { PD_LOG( PDERROR, "Delete failed on node[%s], rc: %d", routeID2String( errNodeID ).c_str(), rc ) ; goto error ; } done: if ( oldFlag & FLG_DELETE_RETURNNUM ) { contextID = deleteNum ; } if ( pCollectionName ) { /// AUDIT PD_AUDIT_OP( AUDIT_DML, MSG_BS_DELETE_REQ, AUDIT_OBJ_CL, pCollectionName, rc, "DeletedNum:%u, Deletor:%s, Hint:%s, Flag:0x%08x(%u)", deleteNum, boDeletor.toString().c_str(), BSONObj(pHint).toString().c_str(), oldFlag, oldFlag ) ; } PD_TRACE_EXITRC ( SDB_RTNCODEL_EXECUTE, rc ) ; return rc ; error: goto done ; }
INT32 rtnCoordDelete::_prepareMainCLOp( CoordCataInfoPtr &cataInfo, CoordGroupSubCLMap &grpSubCl, rtnSendMsgIn &inMsg, rtnSendOptions &options, netMultiRouteAgent *pRouteAgent, pmdEDUCB *cb, rtnProcessResult &result, ossValuePtr &outPtr ) { INT32 rc = SDB_OK ; MsgOpDelete *pDelMsg = ( MsgOpDelete* )inMsg.msg() ; INT32 flag = 0 ; CHAR *pCollectionName = NULL; CHAR *pDeletor = NULL; CHAR *pHint = NULL; BSONObj boDeletor ; BSONObj boHint ; BSONObj boNew ; CHAR *pBuff = NULL ; INT32 buffLen = 0 ; INT32 buffPos = 0 ; vector<CHAR*> *pBlock = NULL ; CoordGroupSubCLMap::iterator it ; outPtr = (ossValuePtr)0 ; inMsg.data()->clear() ; rc = msgExtractDelete( (CHAR*)inMsg.msg(), &flag, &pCollectionName, &pDeletor, &pHint ) ; PD_RC_CHECK( rc, PDERROR, "Failed to parse delete request, rc: %d", rc ) ; boDeletor = BSONObj( pDeletor ) ; boHint = BSONObj( pHint ) ; pBlock = new vector< CHAR* >( 16 ) ; if ( !pBlock ) { PD_LOG( PDERROR, "Alloc vector failed" ) ; rc = SDB_OOM ; goto error ; } it = grpSubCl.begin() ; while( it != grpSubCl.end() ) { CoordSubCLlist &subCLLst = it->second ; netIOVec &iovec = inMsg._datas[ it->first ] ; netIOV ioItem ; // 1. first vec ioItem.iovBase = (CHAR*)inMsg.msg() + sizeof( MsgHeader ) ; ioItem.iovLen = ossRoundUpToMultipleX ( offsetof(MsgOpDelete, name) + pDelMsg->nameLength + 1, 4 ) - sizeof( MsgHeader ) ; iovec.push_back( ioItem ) ; // 2. new deletor vec boNew = _buildNewDeletor( boDeletor, subCLLst ) ; // 2.1 add to buff INT32 roundLen = ossRoundUpToMultipleX( boNew.objsize(), 4 ) ; if ( buffPos + roundLen > buffLen ) { INT32 alignLen = ossRoundUpToMultipleX( roundLen, DMS_PAGE_SIZE4K ) ; rc = cb->allocBuff( alignLen, &pBuff, buffLen ) ; PD_RC_CHECK( rc, PDERROR, "Alloc buff[%d] failed, rc: %d", alignLen, rc ) ; pBlock->push_back( pBuff ) ; buffPos = 0 ; } ossMemcpy( &pBuff[ buffPos ], boNew.objdata(), boNew.objsize() ) ; ioItem.iovBase = &pBuff[ buffPos ] ; ioItem.iovLen = roundLen ; buffPos += roundLen ; iovec.push_back( ioItem ) ; // 3. hinter vec ioItem.iovBase = boHint.objdata() ; ioItem.iovLen = boHint.objsize() ; iovec.push_back( ioItem ) ; ++it ; } outPtr = ( ossValuePtr )pBlock ; done: return rc ; error: if ( pBlock ) { for ( INT32 i = 0 ; i < (INT32)pBlock->size() ; ++i ) { cb->releaseBuff( (*pBlock)[ i ] ) ; } delete pBlock ; pBlock = NULL ; } goto done ; }