Пример #1
0
INT32 _msgBuffer::write( const bson::BSONObj &obj, BOOLEAN align, INT32 bytes )
{
   INT32 rc   = SDB_OK ;
   INT32 size = 0 ;        // new size to realloc
   INT32 num  = 0 ;        // number of memory block
   UINT32 objsize = obj.objsize() ;
   if( objsize > _capacity - _size )
   {
      num = ( objsize + _size ) / MEMERY_BLOCK_SIZE + 1 ;
      size = num * MEMERY_BLOCK_SIZE ;

      rc = realloc( _data, size ) ;
      if( SDB_OK != rc )
      {
         goto error ;
      }
   }

   ossMemcpy( _data + _size, obj.objdata(), objsize ) ;
   if ( align )
   {
      _size += ossRoundUpToMultipleX( objsize, bytes ) ;
   }
   else
   {
      _size += objsize ;
   }

done:
   return rc ;
error:
   goto done ;
}
Пример #2
0
int MongoBase::Insert(std::string name,bson::BSONObj& doc,int flag /* = 0 */)
{
	return this->doInsert(name.c_str(),name.size(),flag,doc.objdata(),doc.objsize());
}
Пример #3
0
int MongoBase::Update(std::string name,int flag,bson::BSONObj& selector,bson::BSONObj& updator)
{
	return this->doUpdate(name.c_str(),name.size(),flag,selector.objdata(),selector.objsize(),updator.objdata(),updator.objsize());
}
Пример #4
0
int MongoBase::Query(MongoQuery* reply,std::string name,bson::BSONObj& query,bson::BSONObj& selector,int flag /* = 0 */,int skip /* = 0 */,int number /* = 100 */)
{
	int session = this->doQuery(name.c_str(),name.size(),query.objdata(),query.objsize(),selector.objdata(),selector.objsize(),flag,skip,number);
	_queryCallBack[session] = boost::bind(&MongoBase::QueryReply,this,reply,_1,_2);
	return session;
}
Пример #5
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__MTHSELECTOR__BUILDCSV, "_mthSelector::_buildCSV" )
   INT32 _mthSelector::_buildCSV( const bson::BSONObj &obj,
                                  bson::BSONObj &csv )
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY( SDB__MTHSELECTOR__BUILDCSV ) ;
      BOOLEAN result = FALSE ;
      INT32 stringLength = 0 ;

      // in the first round, let's allocate memory
      if ( 0 == _stringOutputBufferSize )
      {
         rc = mthDoubleBufferSize ( &_stringOutputBuffer,
                                     _stringOutputBufferSize ) ;
         PD_RC_CHECK ( rc, PDERROR,
                       "Failed to append string, rc = %d", rc ) ;
      }
      _stringOutputBuffer[FIRST_ELEMENT_STARTING_POS-6] = String ;
      _stringOutputBuffer[FIRST_ELEMENT_STARTING_POS-5] = '\0' ;

      while ( _stringOutputBufferSize < MAX_SELECTOR_BUFFER_THRESHOLD )
      {
         result = rawbson2csv ( obj.objdata(),
               &_stringOutputBuffer[FIRST_ELEMENT_STARTING_POS],
                _stringOutputBufferSize-FIRST_ELEMENT_STARTING_POS ) ;
         if ( result )
         {
            break ;
         }
         else
         {
            rc = mthDoubleBufferSize ( &_stringOutputBuffer,
                                       _stringOutputBufferSize ) ;
            PD_RC_CHECK ( rc, PDERROR,
                          "Failed to double buffer, rc = %d", rc ) ;
         }
      }

      if ( _stringOutputBufferSize >= MAX_SELECTOR_BUFFER_THRESHOLD )
      {
         PD_LOG ( PDERROR,
                  "string output buffer size is greater than threshold" ) ;
         rc = SDB_INVALIDARG ;
         goto error ;
      }

      stringLength =
               ossStrlen ( &_stringOutputBuffer[FIRST_ELEMENT_STARTING_POS] ) ;
      // assign object length, 1 for 0 at the end, 1 for the eoo
      *(INT32*)_stringOutputBuffer = FIRST_ELEMENT_STARTING_POS + 2 +
                                        stringLength ;
      _stringOutputBuffer[ *(INT32*)_stringOutputBuffer -1 ] = EOO ;
      // assign string length, 1 for 0 at the end
      *(INT32*)(&_stringOutputBuffer[FIRST_ELEMENT_STARTING_POS-4]) =
               stringLength + 1 ;
      // it should not cause memory leak even if there's previous owned
      // buffer because _stringOutputBuffer is owned by context, and we don't
      // touch holder in BSONObj, so smart pointer should still holding the
      // original buffer it owns
      csv.init ( _stringOutputBuffer ) ;
   done:
      PD_TRACE_EXITRC( SDB__MTHSELECTOR__BUILDCSV, rc ) ;
      return rc ;
   error:
      goto done ;
   }