Пример #1
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__NETEVNHND__ALLOBUF, "_netEventHandler::_allocateBuf" )
   INT32 _netEventHandler::_allocateBuf( UINT32 len )
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY ( SDB__NETEVNHND__ALLOBUF );
      if ( _bufLen < len )
      {
         if ( NULL != _buf )
         {
            SDB_OSS_FREE( _buf ) ;
            _bufLen = 0 ;
         }
         _buf = (CHAR *)SDB_OSS_MALLOC( len ) ;
         if ( NULL == _buf )
         {
            PD_LOG( PDERROR, "mem allocate failed, len: %u", len ) ;
            rc = SDB_OOM ;
            goto error ;
         }
         _bufLen = len ;
      }

   done:
      PD_TRACE_EXITRC ( SDB__NETEVNHND__ALLOBUF, rc );
      return rc ;
   error:
      goto done ;
   }
Пример #2
0
 // PD_TRACE_DECLARE_FUNCTION ( SDB__DMSROUNIT__ALCEXT, "_dmsReorgUnit::_allocateExtent" )
 INT32 _dmsReorgUnit::_allocateExtent ( INT32 requestSize )
 {
    INT32 rc = SDB_OK ;
    PD_TRACE_ENTRY ( SDB__DMSROUNIT__ALCEXT );
    SDB_ASSERT ( !_pCurrentExtent, "current extent must be NULL" ) ;
    if ( requestSize < DMS_MIN_EXTENT_SZ(_pageSize) )
       requestSize = DMS_MIN_EXTENT_SZ(_pageSize) ;
    else if ( requestSize > DMS_MAX_EXTENT_SZ )
       requestSize = DMS_MAX_EXTENT_SZ ;
    else
       requestSize = ossRoundUpToMultipleX ( requestSize, _pageSize ) ;
    _pCurrentExtent = (CHAR*)SDB_OSS_MALLOC ( requestSize ) ;
    if ( !_pCurrentExtent )
    {
       PD_LOG ( PDERROR, "Unable to allocate %d bytes memory", requestSize ) ;
       rc = SDB_OOM ;
       goto error ;
    }
    _currentExtentSize = requestSize ;
    _initExtentHeader ( (dmsExtent*)_pCurrentExtent,
                        _currentExtentSize/_pageSize ) ;
 done :
    PD_TRACE_EXITRC ( SDB__DMSROUNIT__ALCEXT, rc );
    return rc ;
 error :
    goto done ;
 }
Пример #3
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSU_DUMPINFO, "_dmsStorageUnit::dumpInfo" )
   void _dmsStorageUnit::dumpInfo ( vector<CHAR*> &collectionList,
                                    BOOLEAN sys )
   {
      PD_TRACE_ENTRY( SDB__DMSSU_DUMPINFO ) ;
      _pDataSu->_metadataLatch.get_shared() ;

      dmsStorageData::COLNAME_MAP_IT it = _pDataSu->_collectionNameMap.begin() ;
      while ( it != _pDataSu->_collectionNameMap.end() )
      {
         if ( !sys && dmsIsSysCLName( it->first ) )
         {
            ++it ;
            continue ;
         }

         CHAR *pBuffer = (CHAR*)SDB_OSS_MALLOC ( DMS_COLLECTION_NAME_SZ + 1 ) ;
         if ( !pBuffer )
         {
            PD_LOG( PDERROR, "Allocate memory failed" ) ;
            goto error ;
         }
         ossStrncpy ( pBuffer, it->first, DMS_COLLECTION_NAME_SZ ) ;
         pBuffer[ DMS_COLLECTION_NAME_SZ ] = 0 ;
         collectionList.push_back ( pBuffer ) ;

         ++it ;
      }

   done :
      _pDataSu->_metadataLatch.release_shared() ;
      PD_TRACE_EXIT ( SDB__DMSSU_DUMPINFO ) ;
      return ;
   error :
      goto done ;
   }
Пример #4
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_RTNLOBDATAPOOL_ALLOCATE, "_rtnLobDataPool::allocate" )
   INT32 _rtnLobDataPool::allocate( UINT32 len, CHAR **buf )
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY( SDB_RTNLOBDATAPOOL_ALLOCATE ) ;
      SDB_ASSERT( NULL != buf, "can not be null" ) ;
      
      if ( len <= _bufSz )
      {
         *buf = _buf ;
         goto done ;
      }
      else if ( NULL != _buf )
      {
         SDB_OSS_FREE( _buf ) ;
         _bufSz = 0 ;
      }

      _buf = ( CHAR * )SDB_OSS_MALLOC( len ) ;
      if ( NULL == _buf )
      {
         PD_LOG( PDERROR, "failed to allocate mem." ) ; 
         rc = SDB_OOM ;
         goto error ;
      }
      _bufSz = len ;
      *buf = _buf ;
   done:
      PD_TRACE_EXITRC( SDB_RTNLOBDATAPOOL_ALLOCATE, rc ) ;
      return rc ;
   error:
      goto done ;
   }
Пример #5
0
INT32 ossWC2ANSI ( LPCWSTR lpcszWCString,
                   LPSTR   *plppszString,
                   DWORD   *plpdwString )
{
   INT32 rc           = SDB_OK ;
   INT32 strSize      = 0 ;
   INT32 requiredSize = 0 ;
   requiredSize       = WideCharToMultiByte ( CP_ACP, 0, lpcszWCString,
                                              -1, NULL, 0, NULL, NULL ) ;
   *plppszString = (LPSTR)SDB_OSS_MALLOC ( requiredSize ) ;
   if ( !plppszString )
   {
      rc = SDB_OOM ;
      goto error ;
   }
   strSize = WideCharToMultiByte ( CP_ACP, 0, lpcszWCString, -1,
                                   *plppszString, requiredSize,
                                   NULL, NULL ) ;
   if ( 0 == strSize )
   {
      SDB_OSS_FREE ( *plppszString ) ;
      rc = SDB_SYS ;
      *plppszString = NULL ;
      goto error ;
   }
   if ( plpdwString )
   {
      *plpdwString = (DWORD)strSize ;
   }
done :
   return rc ;
error :
   goto done ;
}
Пример #6
0
   INT32 _rtnLobWindow::init( INT32 pageSize )
   {
      INT32 rc = SDB_OK ;
      SDB_ASSERT( DMS_DO_NOT_CREATE_LOB < pageSize,
                  "invalid arguments" ) ;

      SDB_ASSERT( _writeData.empty(), "impossible" ) ;

      if ( !ossIsPowerOf2( pageSize, &_logarithmic ) )
      {
         PD_LOG( PDERROR, "invalid page size:%d, it should be a power of 2",
                 pageSize ) ;
         rc = SDB_INVALIDARG ;
         goto error ;
      }

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

      _pageSize = pageSize ;
   done:
      return rc ;
   error:
      goto done ;
   }
Пример #7
0
   INT32 _pmdEDUCB::allocBuff( INT32 len, CHAR **ppBuff, INT32 &buffLen )
   {
      INT32 rc = SDB_OK ;

      if ( _totalCatchSize >= len && _allocFromCatch( len, ppBuff, buffLen ) )
      {
         goto done ;
      }

      len = ossRoundUpToMultipleX( len, EDU_MEM_ALIGMENT_SIZE ) ;
      *ppBuff = ( CHAR* )SDB_OSS_MALLOC( len ) ;
      if( !*ppBuff )
      {
         rc = SDB_OOM ;
         PD_LOG( PDERROR, "Edu[%s] malloc memory[size: %d] failed",
                 toString().c_str(), len ) ;
         goto error ;
      }
      buffLen = len ;

      _totalMemSize += buffLen ;
      _allocMap[ *ppBuff ] = buffLen ;

   done:
      return rc ;
   error:
      goto done ;
   }
Пример #8
0
   CHAR* _pmdController::allocFixBuf()
   {
      CHAR *pBuff = NULL ;

      _ctrlLatch.get() ;
      if ( _vecFixBuf.size() > 0 )
      {
         pBuff = _vecFixBuf.back() ;
         _vecFixBuf.pop_back() ;
      }
      _ctrlLatch.release() ;

      if ( pBuff )
      {
         goto done ;
      }

      pBuff = ( CHAR* )SDB_OSS_MALLOC( PMD_FIX_PTR_SIZE( _fixBufSize ) ) ;
      if ( !pBuff )
      {
         PD_LOG( PDERROR, "Alloc fix buff failed, size: %d",
                 PMD_FIX_PTR_SIZE( _fixBufSize ) ) ;
         goto error ;
      }
      PMD_FIX_PTR_HEADER( pBuff ) = _fixBufSize ;
      pBuff = PMD_FIX_PTR_TO_BUFF( pBuff ) ;

   done:
      return pBuff ;
   error:
      goto done ;
   }
Пример #9
0
   CHAR* _pmdController::allocFixBuf()
   {
      CHAR *pBuff = NULL ;

      // if fix buff catch is not empty, get from catch
      _ctrlLatch.get() ;
      if ( _vecFixBuf.size() > 0 )
      {
         pBuff = _vecFixBuf.back() ;
         _vecFixBuf.pop_back() ;
      }
      _ctrlLatch.release() ;

      // if we still have free memory, let's just return the pointer
      if ( pBuff )
      {
         goto done ;
      }

      // memory will be freed in releaseFixBuf and fini
      pBuff = ( CHAR* )SDB_OSS_MALLOC( PMD_FIX_PTR_SIZE( _fixBufSize ) ) ;
      if ( !pBuff )
      {
         PD_LOG( PDERROR, "Alloc fix buff failed, size: %d",
                 PMD_FIX_PTR_SIZE( _fixBufSize ) ) ;
         goto error ;
      }
      PMD_FIX_PTR_HEADER( pBuff ) = _fixBufSize ;
      pBuff = PMD_FIX_PTR_TO_BUFF( pBuff ) ;

   done:
      return pBuff ;
   error:
      goto done ;
   }
Пример #10
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__CLSCATCLR_CALL, "_clsCatalogCaller::call" )
   INT32 _clsCatalogCaller::call( MsgHeader *header )
   {
      SDB_ASSERT( NULL != header, "header should not be NULL" ) ;
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY ( SDB__CLSCATCLR_CALL );
      _clsCataCallerMeta &meta = _meta[MAKE_REPLY_TYPE(header->opCode)] ;
      if ( (SINT32)meta.bufLen < header->messageLength )
      {
         if ( NULL != meta.header )
         {
            SDB_OSS_FREE( meta.header ) ;
            meta.bufLen = 0 ;
         }
         meta.header = ( MsgHeader *)SDB_OSS_MALLOC( header->messageLength ) ;
         if ( NULL == meta.header )
         {
            PD_LOG ( PDERROR, "Failed to allocate memory for header" ) ;
            rc = SDB_OOM ;
            goto error ;
         }
         meta.bufLen = header->messageLength ;
      }

      ossMemcpy( meta.header, header, header->messageLength ) ;
      PD_LOG( PDEVENT, "send msg[%d] to catalog node.",
              meta.header->opCode ) ;
      pmdGetKRCB()->getClsCB()->sendToCatlog( meta.header ) ;
      meta.timeout = 0 ;

   done:
      PD_TRACE_EXITRC ( SDB__CLSCATCLR_CALL, rc );
      return rc ;
   error:
      goto done ;
   }
Пример #11
0
INT32 ossANSI2WC ( LPCSTR lpcszString,
                   LPWSTR *plppszWCString,
                   DWORD  *plpdwWCString )
{
   INT32 rc           = SDB_OK ;
   INT32 strSize      = 0 ;
   INT32 requiredSize = 0 ;
   requiredSize       = MultiByteToWideChar ( CP_ACP,
                                              0, lpcszString, -1, NULL, 0 ) ;
   *plppszWCString = (LPWSTR)SDB_OSS_MALLOC ( requiredSize * sizeof(WCHAR) ) ;
   if ( !plppszWCString )
   {
      rc = SDB_OOM ;
      goto error ;
   }
   strSize = MultiByteToWideChar ( CP_ACP, 0, lpcszString, -1,
                                   *plppszWCString, requiredSize ) ;
   if ( 0 == strSize )
   {
      SDB_OSS_FREE ( *plppszWCString ) ;
      rc = SDB_SYS ;
      *plppszWCString = NULL ;
      goto error ;
   }

   if ( plpdwWCString )
      *plpdwWCString = strSize ;
done :
   return rc ;
error :
   goto done ;
}
Пример #12
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 ;
   }
Пример #13
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSTORAGELOADEXT__ALLOCEXTENT, "dmsStorageLoadOp::_allocateExtent" )
   INT32 dmsStorageLoadOp::_allocateExtent ( INT32 requestSize )
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY ( SDB__DMSSTORAGELOADEXT__ALLOCEXTENT );
      if ( requestSize < DMS_MIN_EXTENT_SZ(_pageSize) )
      {
         requestSize = DMS_MIN_EXTENT_SZ(_pageSize) ;
      }
      else if ( requestSize > DMS_MAX_EXTENT_SZ )
      {
         requestSize = DMS_MAX_EXTENT_SZ ;
      }
      else
      {
         requestSize = ossRoundUpToMultipleX ( requestSize, _pageSize ) ;
      }

      if ( !_pCurrentExtent )
      {
         _pCurrentExtent = (CHAR*)SDB_OSS_MALLOC ( requestSize ) ;
         if ( !_pCurrentExtent )
         {
            PD_LOG ( PDERROR, "Unable to allocate %d bytes memory",
                     requestSize ) ;
            rc = SDB_OOM ;
            goto error ;
         }
         _currentExtentSize = requestSize ;
         _initExtentHeader ( (dmsExtent*)_pCurrentExtent,
                             _currentExtentSize/_pageSize ) ;
      }
      else
      {
         if ( requestSize > _currentExtentSize )
         {
            CHAR *pOldPtr = _pCurrentExtent ;
            _pCurrentExtent = (CHAR*)SDB_OSS_REALLOC ( _pCurrentExtent,
                                                       requestSize ) ;
            if ( !_pCurrentExtent )
            {
               PD_LOG ( PDERROR, "Unable to realloc %d bytes memory",
                        requestSize ) ;
               _pCurrentExtent = pOldPtr ;
               rc = SDB_OOM ;
               goto error ;
            }
            _currentExtentSize = requestSize ;
         }
         _initExtentHeader ( (dmsExtent*)_pCurrentExtent,
                             _currentExtentSize/_pageSize ) ;
      }

   done :
      PD_TRACE_EXITRC ( SDB__DMSSTORAGELOADEXT__ALLOCEXTENT, rc );
      return rc ;
   error :
      goto done ;
   }
Пример #14
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 ;
   }
Пример #15
0
CHAR *ossStrdup ( const CHAR * str )
{
   size_t siz ;
   CHAR *copy ;
   siz = ossStrlen ( str ) + 1 ;
   if ( ( copy = (CHAR*)SDB_OSS_MALLOC ( siz ) ) == NULL )
      return NULL ;
   ossMemcpy ( copy, str, siz ) ;
   return copy ;
}
Пример #16
0
   INT32 _rtnDataSet::initByReply( MsgOpReply *pReply,
                                   _pmdEDUCB *cb,
                                   BOOLEAN ownned )
   {
      INT32 rc = SDB_OK ;

      /// context id must be invalid
      SDB_ASSERT( -1 == pReply->contextID, "Context id must be -1" ) ;

      /// first clear
      clear() ;

      _lastErr = pReply->flags ;
      _cb = cb ;

      rc = pReply->flags ;

      /// has data
      if ( SDB_OK == rc &&
           pReply->header.messageLength > (INT32)sizeof( MsgOpReply ) )
      {
         if ( !ownned )
         {
            _pBuff = ( CHAR* )pReply ;
         }
         else
         {
            _pBuff = ( CHAR* )SDB_OSS_MALLOC( pReply->header.messageLength ) ;
            if ( !_pBuff )
            {
               PD_LOG( PDERROR, "Alloc memory[%d] failed",
                       pReply->header.messageLength ) ;
               rc = SDB_OOM ;
               _lastErr = rc ;
               goto error ;
            }
            _ownned = TRUE ;
            ossMemcpy( _pBuff, pReply, pReply->header.messageLength ) ;
         }

         _contextBuf = rtnContextBuf( _pBuff + sizeof( MsgOpReply ),
                                      pReply->header.messageLength -
                                      sizeof( MsgOpReply ),
                                      pReply->numReturned ) ;
      }

   done:
      return rc ;
   error:
      goto done ;
   }
Пример #17
0
   /*
      _pmdEDUCB implement
   */
   _pmdEDUCB::_pmdEDUCB( _pmdEDUMgr *mgr, EDU_TYPES type )
   : _tid( 0 ),
   _processEventCount( 0 ),
   _eduMgr( mgr ),
   _eduType( type ),
   _ctrlFlag( 0 ),
   _writingDB( FALSE ),
   _writingTime( 0 ),
   _threadHdl( 0 ),
#if defined (_LINUX)
   _threadID( 0 ),
#endif
   _pClientSock( NULL )
   {
      _Name[0]          = 0 ;
      _pSession         = NULL ;
      _pCompressBuff    = NULL ;
      _compressBuffLen  = 0 ;
      _pUncompressBuff  = NULL ;
      _uncompressBuffLen= 0 ;
      _totalCatchSize   = 0 ;
      _totalMemSize     = 0 ;
      _isDoRollback     = FALSE ;

#if defined ( SDB_ENGINE )
      _pCoordSession    = NULL ;
      _beginLsn         = 0 ;
      _endLsn           = 0 ;
      _lsnNumber        = 0 ;
      _relatedTransLSN  = DPS_INVALID_LSN_OFFSET ;
      _curTransLSN      = DPS_INVALID_LSN_OFFSET ;
      _curTransID       = DPS_INVALID_TRANS_ID ;
      _pTransNodeMap    = NULL ;
      _transRC          = SDB_OK ;

      _alignedMem       = NULL ;
      _alignedMemSize   = 0 ;

      _curRequestID     = 1 ;
      _dmsLockLevel     = 0 ;

      _monCfgCB = *( (monConfigCB*)(pmdGetKRCB()->getMonCB()) ) ;
#endif // SDB_ENGINE

      _pErrorBuff = (CHAR *)SDB_OSS_MALLOC( EDU_ERROR_BUFF_SIZE + 1 ) ;
      if ( _pErrorBuff )
      {
         ossMemset( _pErrorBuff, 0, EDU_ERROR_BUFF_SIZE + 1 ) ;
      }
   }
Пример #18
0
      INT32 init(INT32 capacity)
      {
         SDB_ASSERT(NULL == _array, "already inited");
         SDB_ASSERT(capacity > 0, "capacity must be greater than 0");

         _array = (bson**)SDB_OSS_MALLOC(sizeof(bson*) * capacity);
         if (NULL == _array)
         {
            return SDB_OOM;
         }
         ossMemset(_array, 0, sizeof(bson*) * capacity);
         _capacity = capacity;

         return SDB_OK;
      }
Пример #19
0
 _utilArray( UINT32 size = 0 )
 :_dynamicBuf( NULL ),
  _eles( _staticBuf ),
  _bufSize( UTIL_ARRAY_DEFAULT_SIZE ),
  _eleSize( 0 )
 {
    if ( UTIL_ARRAY_DEFAULT_SIZE < size )
    {
       _dynamicBuf = ( T * )SDB_OSS_MALLOC( sizeof( T ) * size ) ;
       if ( NULL != _dynamicBuf )
       {
          _eles = _dynamicBuf ;
          _bufSize = size ;
       }
    }
 }
Пример #20
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 ;
}
Пример #21
0
   INT32 _utilESBulkActionBase::setSourceData( const CHAR *sourceData,
                                               INT32 length, BOOLEAN copy )
   {
      INT32 rc = SDB_OK ;

      if ( !sourceData || length <=0 )
      {
         rc = SDB_INVALIDARG ;
         PD_LOG( PDERROR, "Invalid source data or length" ) ;
         goto error ;
      }

      if ( _sourceData )
      {
         if ( _ownData )
         {
            SDB_OSS_FREE( _sourceData ) ;
            _ownData = FALSE ;
         }
         _sourceData = NULL ;
      }

      if ( copy )
      {
         _sourceData = (CHAR *)SDB_OSS_MALLOC( length ) ;
         if ( !_sourceData )
         {
            rc = SDB_OOM ;
            PD_LOG( PDERROR, "Allocate memory for source data failed, requested"
                    " size[ %d ]", length ) ;
            goto error ;
         }
         ossStrncpy( _sourceData, sourceData, length ) ;
         _ownData = TRUE ;
      }
      else
      {
         _sourceData = (CHAR *)sourceData ;
      }

      _srcDataLen = length ;

   done:
      return rc ;
   error:
      goto done ;
   }
Пример #22
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSTORAGELOADEXT__ALLOCEXTENT, "dmsStorageLoadOp::_allocateExtent" )
   INT32 dmsStorageLoadOp::_allocateExtent ( INT32 requestSize )
   {
      INT32 rc = SDB_OK ;
      PD_TRACE_ENTRY ( SDB__DMSSTORAGELOADEXT__ALLOCEXTENT );
      if ( requestSize < DMS_MIN_EXTENT_SZ(_pageSize) )
      {
         requestSize = DMS_MIN_EXTENT_SZ(_pageSize) ;
      }
      else if ( requestSize > DMS_MAX_EXTENT_SZ )
      {
         requestSize = DMS_MAX_EXTENT_SZ ;
      }
      else
      {
         requestSize = ossRoundUpToMultipleX ( requestSize, _pageSize ) ;
      }

      if ( (UINT32)requestSize > _buffSize && _pCurrentExtent )
      {
         SDB_OSS_FREE( _pCurrentExtent ) ;
         _pCurrentExtent = NULL ;
         _buffSize = 0 ;
      }

      if ( (UINT32)requestSize > _buffSize )
      {
         _pCurrentExtent = ( CHAR* )SDB_OSS_MALLOC( requestSize << 1 ) ;
         if ( !_pCurrentExtent )
         {
            PD_LOG( PDERROR, "Alloc memroy[%d] failed",
                    requestSize << 1 ) ;
            rc = SDB_OOM ;
            goto error ;
         }
         _buffSize = ( requestSize << 1 ) ;
      }

      _currentExtentSize = requestSize ;
      _initExtentHeader ( (dmsExtent*)_pCurrentExtent,
                          _currentExtentSize/_pageSize ) ;

   done :
      PD_TRACE_EXITRC ( SDB__DMSSTORAGELOADEXT__ALLOCEXTENT, rc );
      return rc ;
   error :
      goto done ;
   }
Пример #23
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_NETMLTRTAGT_HNDMSG, "netMultiRouteAgent::handleMsg" )
   INT32 netMultiRouteAgent::handleMsg( const NET_HANDLE &handle,
                                        const _MsgHeader *header,
                                        const CHAR *msg )
   {
      INT32 rc = SDB_OK;
      PD_TRACE_ENTRY ( SDB_NETMLTRTAGT_HNDMSG );

      CHAR *pMsgRsp = (CHAR *)SDB_OSS_MALLOC( header->messageLength );
      PD_CHECK( pMsgRsp, SDB_OOM, error, PDERROR,
                "Memory malloc failed(size = %d)", header->messageLength ) ;

      ossMemcpy( pMsgRsp, msg, header->messageLength );

      {
         ossScopedLock _lock( &_mutex, SHARED ) ;
         COORD_SESSION_MAP::iterator it = _sessionMap.find( header->TID );
         if ( _sessionMap.end() != it )
         {
            it->second->postEvent( pmdEDUEvent( PMD_EDU_EVENT_MSG,
                                                PMD_EDU_MEM_ALLOC,
                                                pMsgRsp ) ) ;
         }
         else
         {
            PD_LOG( PDWARNING, "Recieve expired msg[opCode:[%d]%d, TID:%d,"
                    "ReqID:%lld] from node[%d:%d:%d]",
                    IS_REPLY_TYPE( header->opCode ),
                    GET_REQUEST_TYPE( header->opCode ), header->TID,
                    header->requestID, header->routeID.columns.groupID,
                    header->routeID.columns.nodeID,
                    header->routeID.columns.serviceID ) ;
            rc = SDB_SYS ;
            goto error ;
         }
      }

   done:
      PD_TRACE_EXITRC ( SDB_NETMLTRTAGT_HNDMSG, rc );
      return rc ;
   error:
      if ( pMsgRsp )
      {
         SDB_OSS_FREE( pMsgRsp ) ;
      }
      goto done ;
   }
Пример #24
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_COORDSN_DISCONN, "CoordSession::disConnect" )
   INT32 CoordSession::disConnect( const MsgRouteID &routeID )
   {
      INT32 rc = SDB_OK;
      PD_TRACE_ENTRY ( SDB_COORDSN_DISCONN );
      BOOLEAN hasSession = FALSE;
      {
         ossScopedLock _lock( &_mutex ) ;
         COORD_SUBSESSION_MAP::iterator it;
         it = _subSessionMap.find( routeID.value );
         if ( it != _subSessionMap.end() )
         {
            hasSession = TRUE;
            it->second.isConnected = FALSE;
         }
      }

      if ( hasSession )
      {
         MsgOpReply *pMsg = (MsgOpReply *)SDB_OSS_MALLOC( sizeof(MsgOpReply) );
         if ( NULL != pMsg )
         {
            pMsg->header.messageLength = sizeof(MsgOpReply);
            pMsg->header.opCode = MSG_COOR_REMOTE_DISC;
            pMsg->header.routeID = routeID;
            pMsg->header.requestID = pmdGetKRCB()->getCoordCB(
               )->getRouteAgent()->reqIDNew();
            pMsg->flags = SDB_COORD_REMOTE_DISC;
            pMsg->numReturned = 0;
            pMsg->contextID = -1 ;
            pMsg->startFrom = 0 ;
            _pEduCB->postEvent ( pmdEDUEvent( PMD_EDU_EVENT_MSG,
                                              PMD_EDU_MEM_ALLOC,
                                              pMsg ) ) ;
         }
         else
         {
            rc = SDB_OOM;
            PD_LOG( PDERROR, "malloc failed(size=%d)", sizeof(MsgHeader) );
         }
      }

      PD_TRACE_EXITRC ( SDB_COORDSN_DISCONN, rc );
      return rc;
   }
Пример #25
0
   INT32 _rtnObjBuff::getOwned()
   {
      INT32 rc = SDB_OK ;

      if ( !_owned && _pBuff )
      {
         CHAR *pBuff = ( CHAR* )SDB_OSS_MALLOC( _buffSize ) ;
         if ( pBuff )
         {
            _pBuff = pBuff ;
            _owned = TRUE ;
         }
         else
         {
            rc = SDB_OOM ;
         }
      }
      return rc ;
   }
Пример #26
0
   INT32 _sptClassMetaInfo::_getContents( const CHAR *pFileBuff,
                                          const CHAR *pMark1,
                                          const CHAR*pMark2,
                                          CHAR **ppBuff,
                                          INT32 *pBuffSize )
   {
      INT32 rc = SDB_OK ;
      stringstream ss ;
      INT32 buffSize = 0 ;
      CHAR *pBuff = NULL ;
      CHAR *begin = NULL ;
      CHAR *end = NULL ;

      begin = ossStrstr( (CHAR *)pFileBuff, (CHAR *)pMark1 ) ;
      end = ossStrstr( (CHAR *)pFileBuff, (CHAR *)pMark2 ) ;
      if ( NULL == begin || NULL == end )
      {
         rc = SDB_INVALIDARG ;
         ss << "Failed to get [" << pMark1 << "], or [" 
            << pMark2 << "], rc = " << rc << ERROR_END ;
         goto error ;
      }
      buffSize = end - begin ;
      pBuff = (CHAR *)SDB_OSS_MALLOC( buffSize + 1 ) ;
      if ( NULL == pBuff )
      {
         rc = SDB_OOM ;
         ss << "Failed to alloc [" << buffSize << "] bytes, rc = " 
            << rc << ERROR_END ;
         goto error ;
      }
      ossMemset( pBuff, 0, buffSize ) ;
      ossMemcpy( pBuff, begin, buffSize ) ;
      pBuff[buffSize] = '\0' ;
      *ppBuff = pBuff ;
      *pBuffSize = buffSize + 1 ;
      
   done:
      return rc ;
   error:
      PRINT_ERROR ;
      goto done ;
   }
Пример #27
0
 _monCollectionSpace &operator= (const _monCollectionSpace &right)
 {
    vector<CHAR *>::const_iterator it ;
    ossMemcpy ( _name, right._name, sizeof(_name) ) ;
    _pageSize = right._pageSize ;
    _clNum    = right._clNum ;
    _totalRecordNum = right._totalRecordNum ;
    _totalSize      = right._totalSize ;
    _freeSize       = right._freeSize ;
    _lobPageSize    = right._lobPageSize ;
    _totalDataSize = right._totalDataSize ;
    _totalIndexSize = right._totalIndexSize ;
    _totalLobSize = right._totalLobSize ;
    _freeDataSize = right._freeDataSize ;
    _freeIndexSize = right._freeIndexSize ;
    _freeLobSize = right._freeLobSize ;
    try
    {
       for ( it = right._collections.begin();
             it != right._collections.end(); ++it )
       {
          CHAR *p = (CHAR*)SDB_OSS_MALLOC ( DMS_COLLECTION_NAME_SZ + 1 ) ;
          if ( p )
          {
             ossMemcpy ( p, *it, DMS_COLLECTION_NAME_SZ + 1 ) ;
             _collections.push_back ( p ) ;
          }
          else
          {
             PD_LOG ( PDERROR, "Failed to allocate memory" ) ;
          }
       }
    }
    catch ( std::exception &e )
    {
       PD_LOG ( PDERROR,
                "Exception happened during monCollectionSpace =: %s",
                e.what() ) ;
    }
    return *this ;
 }
Пример #28
0
 OSS_INLINE INT32 append( const T &t )
 {
    INT32 rc = SDB_OK ;
    if ( _eleSize < _bufSize )
    {
       _eles[_eleSize++] = t ;
    }
    else if ( UTIL_ARRAY_DEFAULT_SIZE == _bufSize )
    {
       _dynamicBuf = ( T * )SDB_OSS_MALLOC( sizeof( T ) * ( _bufSize * 2 ) ) ;
       if ( NULL == _dynamicBuf )
       {
          rc = SDB_OOM ;
          goto error ;
       }
       _bufSize *= 2 ;
       ossMemcpy( _dynamicBuf, _staticBuf, sizeof( T ) * UTIL_ARRAY_DEFAULT_SIZE ) ;
       _eles = _dynamicBuf ;
       _eles[_eleSize++] = t ;
    }
    else
    {
       T *tmp = _dynamicBuf ;
       _dynamicBuf = ( T * )SDB_OSS_REALLOC( _dynamicBuf,
                                             sizeof( T ) * _bufSize * 2 ) ;
       if ( NULL == _dynamicBuf )
       {
          _dynamicBuf = tmp ;
          rc = SDB_OOM ;
          goto error ;
       }
       _bufSize *= 2 ;
       _eles = _dynamicBuf ;
       _eles[_eleSize++] = t ;
    }
 done:
    return rc ;
 error:
    goto done ;
 }
Пример #29
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 ;
   }
Пример #30
0
      INT32 resize( UINT32 size )
      {
         INT32 rc = SDB_OK ;
         if ( size <= _bufSize ||
              size <= _eleSize )
         {
            goto done ;
         }

         else if ( UTIL_ARRAY_DEFAULT_SIZE == _bufSize )
         {
            _dynamicBuf = ( T * )SDB_OSS_MALLOC( sizeof( T ) * size ) ;
            if ( NULL == _dynamicBuf )
            {
               rc = SDB_OOM ;
               goto error ;
            }
            _bufSize = size ;
            ossMemcpy( _dynamicBuf, _staticBuf, sizeof( T ) * UTIL_ARRAY_DEFAULT_SIZE ) ;
            _eles = _dynamicBuf ;
         }
         else
         {
            T *tmp = _dynamicBuf ;
            _dynamicBuf = ( T * )SDB_OSS_REALLOC( _dynamicBuf,
                                                  sizeof( T ) * size ) ;
            if ( NULL == _dynamicBuf )
            {
               _dynamicBuf = tmp ;
               rc = SDB_OOM ;
               goto error ;
            }
            _bufSize = size ;
            _eles = _dynamicBuf ;
         } 
      done:
         return rc ;
      error:
         goto done ;
      }