INT32 rtnCoordDelete::buildOpMsg( const CoordCataInfoPtr &cataInfo, const CoordSubCLlist &subCLList, CHAR *pSrcMsg, CHAR *&pDstMsg, INT32 &bufferSize ) { INT32 rc = SDB_OK; INT32 flag; CHAR *pCollectionName = NULL; CHAR *pDeletor = NULL; CHAR *pHint = NULL; BSONObj boDeletor; BSONObj boHint; rc = msgExtractDelete( pSrcMsg, &flag, &pCollectionName, &pDeletor, &pHint ); PD_RC_CHECK( rc, PDERROR, "failed to parse delete request(rc=%d)", rc ); try { boDeletor = BSONObj( pDeletor ); boHint = BSONObj( pHint ); BSONArrayBuilder babSubCL; CoordSubCLlist::const_iterator iterCL = subCLList.begin(); while( iterCL != subCLList.end() ) { babSubCL.append( *iterCL ); ++iterCL; } BSONObjBuilder bobNewDeletor; bobNewDeletor.appendElements( boDeletor ); bobNewDeletor.appendArray( CAT_SUBCL_NAME, babSubCL.arr() ); BSONObj boNewDeletor = bobNewDeletor.obj(); rc = msgBuildDeleteMsg( &pDstMsg, &bufferSize, pCollectionName, flag, 0, &boNewDeletor, &boHint ); PD_RC_CHECK( rc, PDERROR, "failed to build delete request(rc=%d)", rc ); { MsgOpDelete *pReqMsg = (MsgOpDelete *)pDstMsg; MsgOpDelete *pSrcReq = (MsgOpDelete *)pSrcMsg; pReqMsg->version = cataInfo->getVersion(); pReqMsg->w = pSrcReq->w; } } catch ( std::exception &e ) { PD_RC_CHECK( SDB_INVALIDARG, PDERROR, "occur unexpected error:%s", e.what() ); } done: return rc; error: goto done; }
BSONObj rtnCoordDelete::_buildNewDeletor( const BSONObj &deletor, const CoordSubCLlist &subCLList ) { BSONObjBuilder builder ; BSONArrayBuilder babSubCL ; CoordSubCLlist::const_iterator iterCL = subCLList.begin(); while( iterCL != subCLList.end() ) { babSubCL.append( *iterCL ) ; ++iterCL ; } builder.appendElements( deletor ) ; builder.appendArray( CAT_SUBCL_NAME, babSubCL.arr() ) ; return builder.obj() ; }
BSONObj _coordDeleteOperator::_buildNewDeletor( const BSONObj &deletor, const CoordSubCLlist &subCLList ) { BSONObjBuilder builder( deletor.objsize() + subCLList.size() * COORD_SUBCL_NAME_DFT_LEN ) ; builder.appendElements( deletor ) ; /* Append array, as { SubCLName : [ "a.a", "b.a" ] } */ BSONArrayBuilder babSubCL( builder.subarrayStart( CAT_SUBCL_NAME ) ) ; CoordSubCLlist::const_iterator iterCL = subCLList.begin(); while( iterCL != subCLList.end() ) { babSubCL.append( *iterCL ) ; ++iterCL ; } babSubCL.done() ; return builder.obj() ; }