示例#1
0
 _rtnQueryOptions::~_rtnQueryOptions ()
 {
    SAFE_OSS_FREE( _fullNameBuf ) ;
    SAFE_OSS_FREE( _mainCLNameBuf ) ;
    _fullName = NULL ;
    _mainCLName = NULL ;
 }
示例#2
0
 migMaster::~migMaster()
 {
    if ( _ppBucket )
    {
       for ( UINT32 i = 0; i < _pParameters->bucketNum; ++i )
       {
          SAFE_OSS_DELETE ( _ppBucket[i] ) ;
       }
    }
    SAFE_OSS_FREE ( _ppBucket ) ;
    SAFE_OSS_DELETE ( _parser ) ;
    SAFE_OSS_FREE ( _sendMsg ) ;
 }
示例#3
0
   utilZlibInStream::~utilZlibInStream()
   {
      if ( NULL != _zbuf )
      {
         SAFE_OSS_FREE( _zbuf ) ;
      }

      if ( NULL != _zstream )
      {
         inflateEnd( _zstream ) ;
         SAFE_OSS_FREE( _zstream ) ;
      }
   }
示例#4
0
   _rtnQueryOptions &_rtnQueryOptions::operator = ( const _rtnQueryOptions &o )
   {
      _rtnReturnOptions::operator =( o ) ;

      _query = o._query ;
      _orderBy = o._orderBy ;
      _hint = o._hint ;
      _fullName = o._fullName ;
      SAFE_OSS_FREE( _fullNameBuf ) ;
      _mainCLName = o._mainCLName ;
      SAFE_OSS_FREE( _mainCLNameBuf ) ;

      return *this ;
   }
示例#5
0
   INT32 utilZlibInStream::init( utilInStream& upstream, INT32 bufSize )
   {
      INT32 rc = SDB_OK ;

      SDB_ASSERT( !_inited, "inited" ) ;

      _zbuf = (CHAR*)SDB_OSS_MALLOC( bufSize ) ;
      if ( NULL == _zbuf )
      {
         rc = SDB_OOM ;
         PD_LOG( PDERROR, "Failed to malloc zlib instream buffer, rc=%d", rc ) ;
         goto error ;
      }
      _zbufSize = bufSize ;

      _zstream = (z_stream*)SDB_OSS_MALLOC( sizeof( z_stream ) ) ;
      if ( NULL == _zstream )
      {
         rc = SDB_OOM ;
         PD_LOG( PDERROR, "Failed to malloc z_stream, rc=%d", rc ) ;
         goto error ;
      }

      _zstream->zalloc = _zlib_alloc ;
      _zstream->zfree = _zlib_free ;
      _zstream->opaque = NULL ;
      _zstream->next_in = NULL ;
      _zstream->avail_in = 0 ;

      rc = inflateInit( _zstream ) ;
      if ( Z_OK != rc )
      {
         PD_LOG( PDERROR, "Failed to init z_stream, zlib error=%d", rc ) ;
         rc = SDB_UTIL_COMPRESS_INIT_FAIL ;
         goto error;
      }

      _upstream = &upstream ;
      _inited = TRUE ;

   done:
      return rc ;
   error:
      SAFE_OSS_FREE( _zstream ) ;
      SAFE_OSS_FREE( _zbuf ) ;
      goto done ;
   }
示例#6
0
   INT32 utilJsonFile::read( ossFile& file, bson::BSONObj& data )
   {
      INT64 fileSize = 0 ;
      INT64 readSize = 0 ;
      CHAR* buf = NULL ;
      INT32 rc = SDB_OK ;

      SDB_ASSERT( file.isOpened(), "file should be opened" ) ;

      rc = file.getFileSize( fileSize ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "Failed to get file size, rc=%d", rc ) ;
         goto error ;
      }

      SDB_ASSERT( fileSize >= 0, "file size should be >= 0" ) ;

      if ( 0 == fileSize )
      {
         goto done ;
      }

      buf = (CHAR*)SDB_OSS_MALLOC( fileSize + 1 ) ; // one more byte for safe
      if ( NULL == buf )
      {
         rc = SDB_OOM ;
         PD_LOG( PDERROR, "Failed to malloc, mem size = %lld, rc=%d",
                 fileSize + 1, rc ) ;
         goto error ;
      }

      rc = file.seekAndReadN( 0, buf, fileSize, readSize ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "Failed to read from file, rc=%d", rc ) ;
         goto error ;
      }

      SDB_ASSERT( readSize == fileSize, "readSize != fileSize" ) ;
      buf[ readSize ] = '\0' ; // safe guard

      rc = bson::fromjson( buf, data ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "Failed to convert json[%s] to bson, rc=%d",
                 buf, rc ) ;
         goto error ;
      }

   done:
      SAFE_OSS_FREE( buf ) ;
      return rc ;
   error:
      goto done ;
   }
示例#7
0
 void _rtnQueryOptions::setMainCLName ( const CHAR *mainCLName )
 {
    SAFE_OSS_FREE( _mainCLNameBuf ) ;
    if ( NULL != mainCLName && '\0' != mainCLName[0] )
    {
       _mainCLName = mainCLName ;
    }
    else
    {
       _mainCLName = NULL ;
    }
 }
示例#8
0
 void _rtnQueryOptions::setCLFullName ( const CHAR *clFullName )
 {
    SAFE_OSS_FREE( _fullNameBuf ) ;
    if ( NULL != clFullName && '\0' != clFullName[0] )
    {
       _fullName = clFullName ;
    }
    else
    {
       _fullName = NULL ;
    }
 }
示例#9
0
   INT32 _rtnQueryOptions::getOwned ()
   {
      INT32 rc = SDB_OK ;

      _rtnReturnOptions::getOwned() ;

      SAFE_OSS_FREE( _fullNameBuf ) ;
      if ( NULL != _fullName )
      {
         _fullNameBuf = ossStrdup( _fullName ) ;
         if ( NULL == _fullNameBuf )
         {
            rc = SDB_OOM ;
            goto error ;
         }
      }
      _fullName = _fullNameBuf ;

      SAFE_OSS_FREE( _mainCLNameBuf ) ;
      if ( NULL != _mainCLName )
      {
         _mainCLNameBuf = ossStrdup( _mainCLName ) ;
         if ( NULL == _mainCLNameBuf )
         {
            rc = SDB_OOM ;
            goto error ;
         }
      }
      _mainCLName = _mainCLNameBuf ;

      _query = _query.getOwned() ;
      _orderBy = _orderBy.getOwned() ;
      _hint = _hint.getOwned() ;

   done:
      return rc ;
   error:
      goto done ;
   }
示例#10
0
INT32 _appendObj( CHAR delChar, bson_iterator *pIt,
                  CHAR **ppCSVBuf, INT32 *pCSVSize )
{
   INT32 rc = SDB_OK ;
   INT32 size    = 0 ;
   INT32 objSize = 0 ;
   CHAR *pBuffer = NULL ;
   CHAR *pTempBuf = NULL ;

   size = bson_sprint_length_iterator ( pIt ) ;

   if ( ppCSVBuf && size > (*pCSVSize) )
   {
      rc = SDB_OOM ;
      goto error ;
   }

   pBuffer = (CHAR *)SDB_OSS_MALLOC( size ) ;
   if ( !pBuffer )
   {
      rc = SDB_OOM ;
      goto error ;
   }
   pTempBuf = pBuffer ;
   ossMemset( pTempBuf, 0, size ) ;

   objSize = size ;
   if( !bson_sprint_iterator ( &pTempBuf,
                               &size,
                               pIt, '"' ) )
   {
      rc = SDB_OOM ;
      goto error ;
   }
   objSize -= size ;
   rc = _appendString( delChar, pBuffer, objSize,
                       ppCSVBuf, pCSVSize ) ;
   if ( rc )
   {
      goto error ;
   }
done:
   SAFE_OSS_FREE( pBuffer ) ;
   return rc ;
error:
   goto done ;
}
示例#11
0
   INT32 _clsLocalValidation::run()
   {
      INT32 rc = SDB_OK ;
      const UINT32 pLen = 512 ;
      SDB_RTNCB *rtnCB = sdbGetRTNCB() ;
      SDB_DMSCB *dmsCB = sdbGetDMSCB() ;

      CHAR *p = (CHAR *)SDB_OSS_MALLOC( pLen ) ;
      if ( NULL == p )
      {
         PD_LOG( PDERROR, "failed to allocate mem." ) ;
         rc = SDB_OOM ;
         goto error ;
      }

      *p = '\0' ;
      *( p + pLen - 1 ) = '\0' ;

      /*try
      {
         boost::thread t( func ) ;
         t.join() ;
      }
      catch( std::exception &e )
      {
         PD_LOG( PDERROR, "failed to create new thread:%s",
                 e.what() ) ;
         rc = SDB_SYS ;
         goto error ;
      }*/


      pmdUpdateValidationTick() ;

   done:
      SAFE_OSS_FREE( p ) ;
      return rc ;
   error:
      goto done ;
   }
示例#12
0
   INT32 iPmdDMNChildProc::init( ossSHMKey shmKey )
   {
      INT32 rc = SDB_OK;
      UINT32 len = 0;
#if defined (_WINDOWS)
      UINT32 keyLen = 0;
#endif
      ossMemset( _execName, 0, sizeof( _execName) );
      rc = ossGetEWD( _execName, OSS_MAX_PATHSIZE );
      PD_RC_CHECK( rc, PDERROR,
                  "failed to get working directory(rc=%d)",
                  rc );
      len = ossStrlen( _execName );
      len = len + 1 + ossStrlen( getProgramName() );
#if defined (_WINDOWS)
      len += ossStrlen(".exe");
      keyLen = ossStrlen( shmKey );
      SAFE_OSS_FREE( _shmKey );
      _shmKey = (CHAR *)SDB_OSS_MALLOC( keyLen + 1 );
      if ( _shmKey )
      {
         ossStrcpy( _shmKey, shmKey );
      }
#elif defined ( _LINUX )
      _shmKey = shmKey;
#endif
      PD_CHECK( len <= OSS_MAX_PATHSIZE, SDB_INVALIDARG, error, PDERROR,
               "length of working directory is longer than expected!" );
      ossStrncat( _execName, OSS_FILE_SEP, 1 );
      ossStrncat( _execName, getProgramName(),
                  ossStrlen( getProgramName() ) );
#if defined (_WINDOWS)
      ossStrncat( _execName, ".exe", ossStrlen(".exe") );
#endif
   done:
      return rc;
   error:
      goto done;
   }
示例#13
0
   INT32 _utilESBulkBuilder::init( UINT32 bufferSize )
   {
      INT32 rc = SDB_OK ;

      if ( 0 == bufferSize || bufferSize > UTIL_ESBULK_MAX_SIZE )
      {
         rc = SDB_INVALIDARG ;
         PD_LOG( PDERROR, "Buffer size[ %u ] is invalid", bufferSize ) ;
         goto error ;
      }

      if ( _buffer )
      {
         SDB_ASSERT( _capacity, "_capacity is 0" ) ;
         rc = SDB_INVALIDARG ;
         PD_LOG( PDERROR, "Bulk builder has been initialized already" ) ;
         goto error ;
      }

      _buffer = (CHAR *)SDB_OSS_MALLOC( bufferSize ) ;
      if ( !_buffer )
      {
         rc = SDB_OOM ;
         PD_LOG( PDERROR, "Allocate memory for bulk buffer failed, requested "
                 "size[ %d ]", bufferSize ) ;
         goto error ;
      }

      ossMemset( _buffer, 0, bufferSize ) ;
      _capacity = bufferSize ;

   done:
      return rc ;
   error:
      SAFE_OSS_FREE( _buffer ) ;
      goto done ;
   }
示例#14
0
migExport::~migExport ()
{
   if ( _isOpen )
   {
      ossClose ( _file ) ;
   }
   if ( _gCursor )
   {
      sdbCloseCursor( _gCursor ) ;
      sdbReleaseCursor( _gCursor ) ;
   }
   if ( _gCSList )
   {
      sdbCloseCursor( _gCSList ) ;
      sdbReleaseCursor( _gCSList ) ;
   }
   if ( _gCLList )
   {
      sdbCloseCursor( _gCLList ) ;
      sdbReleaseCursor( _gCLList ) ;
   }
   if ( _gCollection )
   {
      sdbReleaseCollection ( _gCollection ) ;
   }
   if ( _gCollectionSpace )
   {
      sdbReleaseCS ( _gCollectionSpace ) ;
   }
   if ( _gConnection )
   {
      sdbDisconnect ( _gConnection ) ;
      sdbReleaseConnection( _gConnection ) ;
   }
   SAFE_OSS_FREE( _pBuffer ) ;
}
示例#15
0
INT32 _appendValue( CHAR delChar, bson_iterator *pIt,
                    CHAR **ppBuffer, INT32 *pCSVSize,
                    BOOLEAN includeBinary,
                    BOOLEAN includeRegex )
{
   INT32 rc = SDB_OK ;
   bson_type type = bson_iterator_type( pIt ) ;
   INT32 tempSize = 0 ;
   INT32 base64Size = 0 ;
   INT32 binType = 0 ;
   CHAR temp[128] = { 0 } ;
   const CHAR *pTemp = NULL ;
   CHAR *pBase64 = NULL ;
   bson_timestamp_t ts;
   time_t timer ;
   struct tm psr;

   if ( type == BSON_DOUBLE || type == BSON_BOOL ||
        type == BSON_NULL || type == BSON_INT ||
        type == BSON_LONG )
   {
      rc = _appendNonString( delChar, pIt, ppBuffer, pCSVSize ) ;
      if ( rc )
      {
         goto error ;
      }
   }
   else
   {
      rc = _appendString( delChar, &delChar, 1, ppBuffer, pCSVSize ) ;
      if ( rc )
      {
         goto error ;
      }
      if ( type == BSON_TIMESTAMP )
      {
         ts = bson_iterator_timestamp( pIt ) ;
         timer = (time_t)ts.t;
         local_time( &timer, &psr ) ;
         tempSize = ossSnprintf ( temp, 64,
                                  "%04d-%02d-%02d-%02d.%02d.%02d.%06d",
                                  psr.tm_year + 1900,
                                  psr.tm_mon + 1,
                                  psr.tm_mday,
                                  psr.tm_hour,
                                  psr.tm_min,
                                  psr.tm_sec,
                                  ts.i ) ;
         rc = _appendString( delChar, temp, tempSize, ppBuffer, pCSVSize ) ;
         if ( rc )
         {
            goto error ;
         }
      }
      else if ( type == BSON_DATE )
      {
         timer = bson_iterator_date( pIt ) / 1000 ;
         local_time( &timer, &psr ) ;
         tempSize = ossSnprintf ( temp, 64, "%04d-%02d-%02d",
                                  psr.tm_year + 1900,
                                  psr.tm_mon + 1,
                                  psr.tm_mday ) ;
         rc = _appendString( delChar, temp, tempSize, ppBuffer, pCSVSize ) ;
         if ( rc )
         {
            goto error ;
         }
      }
      else if ( type == BSON_UNDEFINED )
      {
         rc = _appendString( delChar, CSV_STR_UNDEFINED,
                             CSV_STR_UNDEFINED_SIZE,
                             ppBuffer, pCSVSize ) ;
         if ( rc )
         {
            goto error ;
         }
      }
      else if ( type == BSON_MINKEY )
      {
         rc = _appendString( delChar, CSV_STR_MINKEY,
                             CSV_STR_MINKEY_SIZE, ppBuffer, pCSVSize ) ;
         if ( rc )
         {
            goto error ;
         }
      }
      else if ( type == BSON_MAXKEY )
      {
         rc = _appendString( delChar, CSV_STR_MAXKEY,
                             CSV_STR_MAXKEY_SIZE, ppBuffer, pCSVSize ) ;
         if ( rc )
         {
            goto error ;
         }
      }
      else if ( type == BSON_CODE )
      {
         pTemp = bson_iterator_code( pIt ) ;
         rc = _appendString( delChar, pTemp, ossStrlen( pTemp ),
                             ppBuffer, pCSVSize ) ;
         if ( rc )
         {
            goto error ;
         }
      }
      else if ( type == BSON_STRING || type == BSON_SYMBOL )
      {
         pTemp = bson_iterator_string( pIt ) ;
         rc = _appendString( delChar, pTemp, ossStrlen( pTemp ),
                             ppBuffer, pCSVSize ) ;
         if ( rc )
         {
            goto error ;
         }
      }
      else if ( type == BSON_BINDATA )
      {
         if( TRUE == includeBinary )
         {
            rc = _appendString( delChar, CSV_STR_LEFTBRACKET, 1, ppBuffer, pCSVSize ) ;
            if ( rc )
            {
               goto error ;
            }
            binType = (INT32)bson_iterator_bin_type( pIt ) ;
            tempSize = ossSnprintf ( temp, 64, "%d", binType ) ;
            rc = _appendString( delChar, &temp, tempSize, ppBuffer, pCSVSize ) ;
            if ( rc )
            {
               goto error ;
            }
            rc = _appendString( delChar, CSV_STR_RIGHTBRACKET, 1, ppBuffer, pCSVSize ) ;
            if ( rc )
            {
               goto error ;
            }
         }
         pTemp = bson_iterator_bin_data( pIt ) ;
         tempSize = bson_iterator_bin_len ( pIt ) ;
         base64Size = getEnBase64Size ( tempSize ) ;
         pBase64 = (CHAR *)SDB_OSS_MALLOC( base64Size ) ;
         if( NULL == pBase64 )
         {
            rc = SDB_OOM ;
            goto error ;
         }
         ossMemset( pBase64, 0, base64Size ) ;
         if ( !base64Encode( pTemp, tempSize, pBase64, base64Size ) )
         {
            rc = SDB_OOM ;
            goto error ;
         }
         rc = _appendString( delChar, pBase64, base64Size - 1,
                             ppBuffer, pCSVSize ) ;
         if ( rc )
         {
            goto error ;
         }
      }
      else if ( type == BSON_REGEX )
      {
         if( TRUE == includeRegex )
         {
            rc = _appendString( delChar, CSV_STR_BACKSLASH, 1,
                                ppBuffer, pCSVSize ) ;
            if ( rc )
            {
               goto error ;
            }
         }
         pTemp = bson_iterator_regex( pIt ) ;
         rc = _appendString( delChar, pTemp, ossStrlen( pTemp ),
                             ppBuffer, pCSVSize ) ;
         if ( rc )
         {
            goto error ;
         }
         if( TRUE == includeRegex )
         {
            rc = _appendString( delChar, CSV_STR_BACKSLASH, 1,
                                ppBuffer, pCSVSize ) ;
            if ( rc )
            {
               goto error ;
            }
            pTemp = bson_iterator_regex_opts( pIt ) ;
            rc = _appendString( delChar, pTemp, ossStrlen( pTemp ),
                                ppBuffer, pCSVSize ) ;
            if ( rc )
            {
               goto error ;
            }
         }
      }
      else if ( type == BSON_OID )
      {
         bson_oid_to_string( bson_iterator_oid( pIt ), temp ) ;
         rc = _appendString( delChar, temp, 24, ppBuffer, pCSVSize ) ;
         if ( rc )
         {
            goto error ;
         }
      }
      else
      {
         rc = _appendObj( delChar, pIt, ppBuffer, pCSVSize ) ;
         if ( rc )
         {
            goto error ;
         }
      }
      rc = _appendString( delChar, &delChar, 1, ppBuffer, pCSVSize ) ;
      if ( rc )
      {
         goto error ;
      }
   }
done:
   SAFE_OSS_FREE( pBase64 ) ;
   return rc ;
error:
   goto done ;
}
示例#16
0
   INT32 _sptClassMetaInfo::_extractTroffInfo()
   {
      INT32 rc = SDB_OK ;
      stringstream ss ;
      INT64 fileSize = 4096 ;
      CHAR *pFileBuff = NULL ;
      multimap<string, string>::iterator it ;
      MAP_FUNC_META_INFO_IT it2 ;
      
      pFileBuff = (CHAR *)SDB_OSS_MALLOC( fileSize ) ;
      if ( !pFileBuff )
      {
         rc = SDB_OOM ;
         ss << "Failed to alloc memory, rc = " << rc << ERROR_END ;
         goto error ;
      }

      for( it = _mapFiles.begin(); it != _mapFiles.end(); it++ )
      {
         sptFuncMetaInfo metaInfo ;
         string className = it->first ;
         string filePath = it->second ;
         string funcName ;
         string fullName ;
         vector<string> syntax ;
         string desc ;

         ossMemset( pFileBuff, 0, fileSize ) ;
         rc = _readFile( filePath.c_str(), &pFileBuff, &fileSize ) ;
         if ( rc )
         {
            ss << "Failed to read troff's contents from file [" 
               << filePath.c_str() << ", rc = " << rc << ERROR_END ;
            goto error ;
         }
         rc = _getFuncName( filePath, funcName ) ;
         if ( rc )
         {
            ss << "Failed to get the name of function, rc = "
               << rc << ERROR_END ;
            goto error ;
         }
         rc = _getFuncSynopsis( pFileBuff, fileSize, syntax ) ;
         if ( rc )
         {
            ss << "Failed to get the syntax of function in file[" << filePath
               << "], rc = " << rc << ERROR_END ;
            goto error ;
         }
         rc = _getFuncDesc( pFileBuff, fileSize, desc ) ;
         if ( rc )
         {
            ss << "Failed to get the description of function in file[" 
               << filePath << "], rc = " << rc << ERROR_END ;
            goto error ;
         }
         metaInfo.funcName = funcName ;
         metaInfo.syntax = syntax ;
         metaInfo.desc = desc ;
         metaInfo.funcType = SPT_FUNC_INSTANCE ;
         metaInfo.path = filePath ;
         it2 = _map_func_meta_info.find( className ) ;
         if ( it2 != _map_func_meta_info.end() )
         {
            it2->second.push_back( metaInfo ) ;
         }
         else
         {
            vector<sptFuncMetaInfo> vec ;
            vec.push_back( metaInfo ) ;
            _map_func_meta_info.insert( PAIR_FUNC_META_INFO( className, vec ) ) ;
         }
         fullName = className + SPT_CLASS_SEPARATOR + funcName ;
         _functions.push_back( fullName ) ;
      }

   done:
      if ( pFileBuff )
      {
         SAFE_OSS_FREE( pFileBuff ) ;
      }
      return rc ;
   error:
      PRINT_ERROR ;
      goto done ;
   }
示例#17
0
   INT32 utilZlibOutStream::init( utilOutStream& downstream,
                                  UTIL_COMPRESSION_LEVEL level, INT32 bufSize )
   {
      INT32 rc = SDB_OK ;
      INT32 zlevel = 0 ;

      SDB_ASSERT( !_inited, "inited" ) ;

      _zbuf = (CHAR*)SDB_OSS_MALLOC( bufSize ) ;
      if ( NULL == _zbuf )
      {
         rc = SDB_OOM ;
         PD_LOG( PDERROR, "Failed to malloc zlib outstream buffer, rc=%d", rc ) ;
         goto error ;
      }
      _zbufSize = bufSize ;

      switch( level )
      {
      case UTIL_COMP_BALANCE:
         zlevel = Z_DEFAULT_COMPRESSION ;
         break ;
      case UTIL_COMP_BEST_COMPRESSION:
         zlevel = Z_BEST_COMPRESSION ;
         break ;
      case UTIL_COMP_BEST_SPEED:
         zlevel = Z_BEST_SPEED ;
         break ;
      default:
         rc = SDB_INVALIDARG ;
         PD_LOG( PDERROR, "Invalid compression level: %d", level ) ;
         goto error ;
      }
      _level = level ;

      _zstream = (z_stream*)SDB_OSS_MALLOC( sizeof( z_stream ) ) ;
      if ( NULL == _zstream )
      {
         rc = SDB_OOM ;
         PD_LOG( PDERROR, "Failed to malloc z_stream, rc=%d", rc ) ;
         goto error ;
      }

      _zstream->zalloc = _zlib_alloc ;
      _zstream->zfree = _zlib_free ;
      _zstream->opaque = NULL ;
      _zstream->data_type = Z_BINARY ;

      rc = deflateInit( _zstream, zlevel ) ;
      if ( Z_OK != rc )
      {
         PD_LOG( PDERROR, "Failed to init z_stream, zlib error=%d", rc ) ;
         rc = SDB_UTIL_COMPRESS_INIT_FAIL ;
         goto error;
      }

      _downstream = &downstream ;
      _inited = TRUE ;

   done:
      return rc ;
   error:
      SAFE_OSS_FREE( _zstream ) ;
      SAFE_OSS_FREE( _zbuf ) ;
      goto done ;
   }
示例#18
0
   iPmdDMNChildProc::~iPmdDMNChildProc()
   {
#if defined (_WINDOWS)
      SAFE_OSS_FREE( _shmKey );
#endif
   }
示例#19
0
 _mthSelector::~_mthSelector()
 {
    SAFE_OSS_FREE( _stringOutputBuffer ) ;
 }
示例#20
0
 _omagentJob::~_omagentJob()
 {
    SAFE_OSS_FREE( _pTask ) ;
 }
示例#21
0
 ~_utilArray()
 {
    SAFE_OSS_FREE( _dynamicBuf ) ;
 }
示例#22
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__DPSLOGFILE__RESTRORE, "_dpsLogFile::_restore" )
   INT32 _dpsLogFile::_restore ()
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY ( SDB__DPSLOGFILE__RESTRORE );
      INT64 fileSize = 0 ;
      UINT64 offSet = 0 ;
      UINT64 baseOffset = 0 ;
      dpsLogRecordHeader lsnHeader ;
      CHAR *lastRecord = NULL ;
      UINT64 lastOffset = 0 ;
      UINT32 lastLen = 0 ;

      _inRestore = TRUE ;

      //Judge the length is right
      rc = ossGetFileSize( _file, &fileSize ) ;
      if ( SDB_OK != rc )
      {
         goto error ;
      }

      if ( fileSize < (INT64)( _fileSize + sizeof(dpsLogHeader) ) )
      {
         PD_LOG ( PDERROR, "DPS file size[%d] is smaller than config[%d]",
                  fileSize - sizeof(dpsLogHeader), _fileSize ) ;
         rc = SDB_DPS_FILE_SIZE_NOT_SAME ;
         goto error ;
      }

      //Init header
      rc = _readHeader() ;
      if ( SDB_OK != rc )
      {
         PD_LOG ( PDERROR, "Fail to read dps file header[rc:%d]", rc ) ;
         goto error ;
      }

      // check header info
      if ( ossStrncmp( _logHeader._eyeCatcher, DPS_LOG_HEADER_EYECATCHER,
                       sizeof( _logHeader._eyeCatcher ) ) != 0 )
      {
         PD_LOG( PDERROR, "DPS file eye catcher error" ) ;
         rc = SDB_DPS_FILE_NOT_RECOGNISE ;
         goto error ;
      }
      else if ( _logHeader._fileSize != 0 &&
                _logHeader._fileSize != _fileSize )
      {
         PD_LOG( PDERROR, "DPS file's meta size[%d] is not the same with "
                 "config[%d]", _logHeader._fileSize, _fileSize ) ;
         rc = SDB_DPS_FILE_SIZE_NOT_SAME ;
         goto error ;
      }
      else if ( _logHeader._fileNum != 0 &&
                _logHeader._fileNum != _fileNum )
      {
         PD_LOG( PDERROR, "DPS file's meta file num[%d] is not the same with "
                 "config[%d]", _logHeader._fileNum, _fileNum ) ;
         rc = SDB_INVALIDARG ;
         goto error ;
      }

      // check the real size
      if ( fileSize > (INT64)( _fileSize + sizeof(dpsLogHeader) ) )
      {
         PD_LOG( PDERROR, "DPS file real size[%d] is not the same with "
                 "config[%d]", fileSize - sizeof(dpsLogHeader),
                 _fileSize ) ;
         // start up from crash
         if ( !pmdGetStartup().isOK() )
         {
            rc = ossTruncateFile( _file, _fileSize + sizeof(dpsLogHeader) ) ;
            if ( rc )
            {
               PD_LOG( PDWARNING, "Tuncate dps file to config size failed, "
                       "rc: %d", rc ) ;
               goto error ;
            }
            PD_LOG( PDEVENT, "Tuncate dps file to config size[%d]",
                    _fileSize ) ;
         }
         else
         {
            goto error ;
         }
      }

      PD_LOG ( PDEVENT, "Header info[first lsn:%d.%lld, logID:%d]",
               _logHeader._firstLSN.version, _logHeader._firstLSN.offset,
               _logHeader._logID ) ;

      // upgrade the header
      if ( _logHeader._version != DPS_LOG_FILE_VERSION1 )
      {
         _logHeader._version = DPS_LOG_FILE_VERSION1 ;
         _logHeader._fileSize = _fileSize ;
         _logHeader._fileNum  = _fileNum ;

         rc = _flushHeader() ;
         PD_RC_CHECK( rc, PDERROR, "Failed to flush header, rc: %d", rc ) ;
      }

      if ( _logHeader._logID == DPS_INVALID_LOG_FILE_ID ||
           _logHeader._firstLSN.invalid() )
      {
         _logHeader._firstLSN.version = DPS_INVALID_LSN_VERSION ;
         _logHeader._firstLSN.offset = DPS_INVALID_LSN_OFFSET ;
         goto done ;
      }

      offSet = _logHeader._firstLSN.offset % _fileSize ;
      baseOffset = _logHeader._firstLSN.offset - offSet ;

      //analysis the file
      while ( offSet < _fileSize )
      {
         rc = read ( offSet + baseOffset , sizeof (dpsLogRecordHeader),
                     (CHAR*)&lsnHeader ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG ( PDERROR, "Failed to read lsn header[offset:%lld,rc:%d]",
                     offSet, rc ) ;
            goto error ;
         }

         if ( lsnHeader._lsn != offSet + baseOffset )
         {
            PD_LOG ( PDEVENT, "LSN is not the same[%lld!=%lld]",
                     lsnHeader._lsn, offSet + baseOffset ) ;
            break ;
         }
         else if ( offSet + lsnHeader._length > _fileSize )
         {
            PD_LOG ( PDEVENT, "LSN length[%d] is over the file "
                     "size[offSet:%lld]", lsnHeader._length, offSet ) ;
            break ;
         }
         else if ( lsnHeader._length < sizeof (dpsLogRecordHeader) )
         {
            PD_LOG ( PDEVENT, "LSN length[%d] less than min[%d], invalid LSN",
                     lsnHeader._length, sizeof (dpsLogRecordHeader) ) ;
            break ;
         }

         offSet += lsnHeader._length ;
         lastOffset = offSet ;
         lastLen = lsnHeader._length ;
      }

      /// ensure that the last record is valid.
      if ( 0 < lastLen && 0 < lastOffset )
      {
         _dpsLogRecord lr ;
         lastRecord = ( CHAR * )SDB_OSS_MALLOC( lastLen ) ;
         if ( NULL == lastRecord )
         {
            PD_LOG( PDERROR, "failed to allocate mem.") ;
            rc = SDB_OOM ;
            goto error ;
         }

         rc = read( lastOffset + baseOffset - lastLen,
                    lastLen,
                    lastRecord ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "failed to read dps record[%lld, rc:%d]",
                    offSet, rc ) ;
            goto error ;
         }

         rc = lr.load( lastRecord ) ;
         if ( SDB_DPS_CORRUPTED_LOG == rc )
         {
            /// the last record is corrupted. move to pre one.
            offSet -= lastLen ;
            rc = SDB_OK ;
            const dpsLogRecordHeader *corruptedHeader =
                           ( const dpsLogRecordHeader * )lastRecord ;
            PD_LOG( PDEVENT, "last log record(lsn:%lld) is corrupted.",
                    corruptedHeader->_lsn ) ;

            /// only one corrupted log in this file.
            if ( 0 == offSet )
            {
               _logHeader._firstLSN.offset = DPS_INVALID_LSN_OFFSET ;
               _logHeader._firstLSN.version = DPS_INVALID_LSN_VERSION ;
            }
         }
         else if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "failed to load record log:%d", rc ) ;
            goto error ;
         }
      }

      _idleSize = _fileSize - offSet ;

   done:
      _inRestore = FALSE ;
      SAFE_OSS_FREE( lastRecord ) ;
      PD_TRACE_EXITRC ( SDB__DPSLOGFILE__RESTRORE, rc );
      return rc ;
   error:
      goto done ;
   }
示例#23
0
   INT32 _sptClassMetaInfo::_getFuncSynopsis( const CHAR *pFileBuff, 
                                              INT32 fileSize, 
                                              vector<string> &output )
   {
      INT32 rc = SDB_OK ;
      stringstream ss ;
      INT32 buffSize = 0 ;
      CHAR *pBuff = NULL ;
      vector<string> vec ;
      vector<string>::iterator it ;
      const CHAR *beg_mark = 
         SPT_LANG_EN == _lang ? SPT_TROFF_SYNOPSIS_EN : SPT_TROFF_SYNOPSIS_CN ;
      const CHAR *end_mark = 
         SPT_LANG_EN == _lang ? SPT_TROFF_CATEGORY_EN : SPT_TROFF_CATEGORY_CN ;

      rc = _getContents( pFileBuff, beg_mark, end_mark, 
                         &pBuff, &buffSize ) ;
      if ( SDB_OK != rc )
      {
         ss << "Failed to contents for extracting synopsis, rc = " 
            << rc << endl ;
         goto error ;
      }
      _filterMarks( pBuff, _uselessMarks, 
                    sizeof( _uselessMarks ) / sizeof( const CHAR * ) ) ;
      boost::split( vec, pBuff, boost::is_any_of("\n") ) ;
      for ( it = vec.begin(); it != vec.end(); it++ )
      {
         if ( !it->empty() )
         {
            std::size_t found = it->find( "(" ) ;
            if ( std::string::npos == found )
            {
               output.push_back( *it ) ;
            }
            else
            {
               string sub = it->substr( 0, found ) ;
               found = sub.find_last_of( "." ) ;
               if ( std::string::npos == found )
               {
                  output.push_back( *it ) ;
               }
               else
               {
                  output.push_back( it->substr( found + 1 ) ) ;
               }
            }
         }
      }
      
   done:
      if ( pBuff )
      {
         SAFE_OSS_FREE( pBuff ) ;
      }
      return rc ;
   error:
      PRINT_ERROR ;
      goto done ;
   }
示例#24
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_RTNLOCALLOBSTREAM__UPDATE, "_rtnLocalLobStream::_update" )
   INT32 _rtnLocalLobStream::_update( const _rtnLobTuple &tuple,
                                      _pmdEDUCB *cb )
   {
      INT32 rc = SDB_OK ;
      BOOLEAN accessInfoLocked = FALSE ;
      PD_TRACE_ENTRY( SDB_RTNLOCALLOBSTREAM__UPDATE ) ;

      dmsLobRecord record ;
      const MsgLobTuple &t = tuple.tuple ;
      CHAR* buf = NULL ;

      record.set( &getOID(), t.columns.sequence, t.columns.offset,
                  t.columns.len, ( const CHAR * )tuple.data ) ;

      if ( DMS_LOB_META_SEQUENCE == t.columns.sequence &&
           SDB_LOB_MODE_WRITE == _getMode() &&
           0 == t.columns.offset &&
           t.columns.len >= sizeof(_dmsLobMeta) )
      {
         _rtnLobMetaCache* metaCache = NULL ;
         const _dmsLobMeta* meta = (const _dmsLobMeta*)tuple.data ;
         if ( meta->hasPiecesInfo() && t.columns.len < DMS_LOB_META_LENGTH )
         {
            rc = SDB_SYS ;
            PD_LOG( PDERROR, "Invalid lob meta data length:%d, rc=%d",
                    t.columns.len, rc ) ;
            goto error ;
         }

         SDB_ASSERT( NULL != _accessInfo, "_accessInfo is null" ) ;

         _accessInfo->lock() ;
         accessInfoLocked = TRUE ;

         metaCache = _accessInfo->getMetaCache() ;
         SDB_ASSERT( NULL != metaCache, "metaCache is null" ) ;
         SDB_ASSERT( NULL != metaCache->lobMeta(), "lob meta cache is null" ) ;

         if ( metaCache->needMerge() )
         {
            _rtnLobMetaCache newCache ;
            rc = newCache.cache( *(metaCache->lobMeta()) ) ;
            if ( SDB_OK != rc )
            {
               PD_LOG( PDERROR, "Failed to cache lob meta, rc=%d", rc ) ;
               goto error ;
            }

            rc = newCache.merge( *meta, _su->getLobPageSize() ) ;
            if ( SDB_OK != rc )
            {
               PD_LOG( PDERROR, "Failed to merge lob meta data, rc=%d", rc ) ;
               goto error ;
            }

            SDB_ASSERT( NULL != newCache.lobMeta(), "new lob meta cache is null" ) ;

            rc = metaCache->cache( *( newCache.lobMeta() ) ) ;
            if ( SDB_OK != rc )
            {
               PD_LOG( PDERROR, "Failed to cache lob meta, rc=%d", rc ) ;
               goto error ;
            }

            buf = (CHAR*)SDB_OSS_MALLOC( record._dataLen > DMS_LOB_META_LENGTH ?
                                         record._dataLen : DMS_LOB_META_LENGTH ) ;
            if ( NULL == buf )
            {
               rc = SDB_OOM ;
               PD_LOG( PDERROR, "Failed to malloc buf, rc=%d", rc ) ;
               goto error ;
            }
            ossMemset( buf, 0, DMS_LOB_META_LENGTH ) ;

            ossMemcpy( buf, record._data, record._dataLen ) ;
            record._data = (const CHAR*)buf ;

            if ( newCache.lobMeta()->hasPiecesInfo() )
            {
               ossMemcpy( (void*)record._data, newCache.lobMeta(), DMS_LOB_META_LENGTH ) ;
               if ( record._dataLen < DMS_LOB_META_LENGTH )
               {
                  record._dataLen = DMS_LOB_META_LENGTH ;
               }
            }
            else
            {
               ossMemcpy( (void*)record._data, newCache.lobMeta(), sizeof( _dmsLobMeta ) ) ;
            }
         }
         else
         {
            rc = metaCache->cache( *meta ) ;
            if ( SDB_OK != rc )
            {
               PD_LOG( PDERROR, "Failed to cache lob meta, rc=%d", rc ) ;
               goto error ;
            }
         }

         rc = _su->lob()->update( record, _mbContext, cb, _getDPSCB() ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "failed to update to lob:%d", rc ) ;
            goto error ;
         }

         _accessInfo->unlock() ;
         accessInfoLocked = FALSE ;
      }
      else
      {
         rc = _su->lob()->update( record, _mbContext, cb, _getDPSCB() ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "failed to update to lob:%d", rc ) ;
            goto error ;
         }
      }

   done:
      if ( accessInfoLocked )
      {
         _accessInfo->unlock() ;
      }
      SAFE_OSS_FREE( buf ) ;
      PD_TRACE_EXITRC( SDB_RTNLOCALLOBSTREAM__UPDATE, rc ) ;
      return rc ;
   error:
      goto done ;
   }
示例#25
0
   INT32 _sptClassMetaInfo::_getFuncDesc( const CHAR *pFileBuff, 
                                          INT32 fileSize, 
                                          string &desc )
   {
      INT32 rc = SDB_OK ;
      stringstream ss ;
      INT32 buffSize = 0 ;
      CHAR *pBuff = NULL ;
      const CHAR *pos = NULL ;
      const CHAR *beg_mark = 
         SPT_LANG_EN == _lang ? SPT_TROFF_NAME_EN : SPT_TROFF_NAME_CN ;
      const CHAR *end_mark = 
         SPT_LANG_EN == _lang ? SPT_TROFF_SYNOPSIS_EN : SPT_TROFF_SYNOPSIS_CN ;

      rc = _getContents( pFileBuff, beg_mark, end_mark, 
                         &pBuff, &buffSize ) ;
      if ( SDB_OK != rc )
      {
         ss << "Failed to contents for extracting synopsis, rc = " 
            << rc << endl ;
         goto error ;
      }
      _replaceCharsWithSpace( pBuff, "\n" ) ;
      _filterMarks( pBuff, _uselessMarks2, 
                    sizeof( _uselessMarks2 ) / sizeof( const CHAR * ) ) ;
      pos = ossStrstr( pBuff, "-" ) ;
      if ( NULL == pos )
      {
         rc = SDB_INVALIDARG ;
         ss << "Failed to get the description of function, rc = " 
            << rc << ERROR_END ;
         goto error ;
      }
      pos++ ;
      while( '\r' != *pos && '\n' != *pos )
      {
         if ( ' ' == *pos )
         {
            pos++ ;
         }
         else
         {
            break ;
         }
      }
      if ( '\r' != *pos && '\n' != *pos )
      {
         desc += string( "- " ) + pos ;
         boost::trim( desc ) ;
      }

   done:
      if ( pBuff )
      {
         SAFE_OSS_FREE( pBuff ) ;
      }
      return rc ;
   error:
      PRINT_ERROR ;
      goto done ;
   }