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 ; }
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 ; }