// 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 ;
   }
Exemple #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 ;
 }
   // 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 ;
   }