Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per Dataset Caching #38

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1993067
Updated the way caching work so that caches can be set per dataset in…
flippmoke Jul 8, 2014
284f7d3
Added some code to ensure that the Raster Block Manager is cleaned up…
flippmoke Jul 8, 2014
43eba18
Fixed issues with RasterBlockManager not existing in some situations …
flippmoke Jul 8, 2014
2149f64
Merge remote-tracking branch 'osgeo/trunk' into trunk
flippmoke Jul 8, 2014
8e29bae
Fixed the various issues surrounding the use of the global GDALGetCac…
flippmoke Jul 9, 2014
c3c6e77
Fixed the various issues surrounding the use of the global GDALGetCac…
flippmoke Jul 9, 2014
b23c223
Attempting to break everything with some stupid git commits in a terr…
flippmoke Jul 9, 2014
24100c8
Updated postgisraster driver with proper accessor rather then accessi…
flippmoke Jul 9, 2014
e1ee0eb
Renamed the cache functions in the Raster Block Manager to be with ou…
flippmoke Jul 9, 2014
37fa066
Resolved issues with proper destruction of global raster block manage…
flippmoke Jul 9, 2014
62f0680
Fix to issue where different datasets might have different sized cach…
flippmoke Jul 9, 2014
514bcb1
Updated the way caching work so that caches can be set per dataset in…
flippmoke Jul 8, 2014
6865977
Added some code to ensure that the Raster Block Manager is cleaned up…
flippmoke Jul 8, 2014
e6a5605
Fixed issues with RasterBlockManager not existing in some situations …
flippmoke Jul 8, 2014
92a9756
Fixed the various issues surrounding the use of the global GDALGetCac…
flippmoke Jul 9, 2014
f5a2ff6
Fixed the various issues surrounding the use of the global GDALGetCac…
flippmoke Jul 9, 2014
76f3787
Updated postgisraster driver with proper accessor rather then accessi…
flippmoke Jul 9, 2014
288fe73
Renamed the cache functions in the Raster Block Manager to be with ou…
flippmoke Jul 9, 2014
bcb4b3d
Resolved issues with proper destruction of global raster block manage…
flippmoke Jul 9, 2014
2e4ad38
Fix to issue where different datasets might have different sized cach…
flippmoke Jul 9, 2014
07f11fd
Merge branch 'trunk' of github.com:flippmoke/gdal into trunk
flippmoke Jul 9, 2014
f249a5f
A few corrections, one that removed an un-needed object, the other pr…
flippmoke Jul 9, 2014
ee55148
A large set of modifications that will provide a way to use certain d…
flippmoke Jul 15, 2014
9de7c53
Some updates to the gitignore
flippmoke Jul 15, 2014
82b8794
Merge pull request #1 from flippmoke/mutex
flippmoke Jul 21, 2014
08dde2c
Updated the way caching work so that caches can be set per dataset in…
flippmoke Jul 8, 2014
ffd1a7a
Added some code to ensure that the Raster Block Manager is cleaned up…
flippmoke Jul 8, 2014
61c9c3e
Fixed issues with RasterBlockManager not existing in some situations …
flippmoke Jul 8, 2014
4bbafab
Fixed the various issues surrounding the use of the global GDALGetCac…
flippmoke Jul 9, 2014
c259b1e
Rebase fixes
flippmoke Jul 21, 2014
be647b1
Updated postgisraster driver with proper accessor rather then accessi…
flippmoke Jul 9, 2014
ea75671
Renamed the cache functions in the Raster Block Manager to be with ou…
flippmoke Jul 9, 2014
0eadef7
Resolved issues with proper destruction of global raster block manage…
flippmoke Jul 9, 2014
71a5f20
Fix to issue where different datasets might have different sized cach…
flippmoke Jul 9, 2014
7afa7c7
Updated the way caching work so that caches can be set per dataset in…
flippmoke Jul 8, 2014
42469ac
Fixed issues with RasterBlockManager not existing in some situations …
flippmoke Jul 8, 2014
63718c7
Fixed the various issues surrounding the use of the global GDALGetCac…
flippmoke Jul 9, 2014
4c10ad5
A few corrections, one that removed an un-needed object, the other pr…
flippmoke Jul 9, 2014
7ee4e40
A large set of modifications that will provide a way to use certain d…
flippmoke Jul 15, 2014
80bfad9
Some updates to the gitignore
flippmoke Jul 15, 2014
82eadeb
Merge branch 'trunk' of github.com:flippmoke/gdal into trunk
flippmoke Jul 21, 2014
b18b640
Merge remote-tracking branch 'osgeo/trunk' into trunk
flippmoke Jul 21, 2014
f5b4ec1
Some updates so that might prevent deadlock and spread out the mutexe…
flippmoke Jul 23, 2014
5dc7bf7
Some modifications adding the RW mutex.
flippmoke Jul 24, 2014
6609f56
Some fixes for the way GetRWMutex is called from the band and a fix t…
flippmoke Jul 29, 2014
d0d3cd5
Added needed include
flippmoke Jul 29, 2014
1fab48c
A few more instances of including multiproc for mutex support.
flippmoke Jul 29, 2014
a4502e5
Some changes so that some wms builds properly
flippmoke Jul 29, 2014
5b74f8a
Added some newlines to error points in multiproc
flippmoke Jul 30, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions autotest/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.pyc
*.o
ogr/tmp
ogr/data/delete_nas.gfs
ogr/data/replace_nas.gfs
Expand All @@ -15,3 +16,9 @@ gdrivers/data/byte.jp2.gz.properties
gdrivers/data/utm.json
gdrivers/tmp
osr/tmp
cpp/gdal_unit_test
cpp/test_virtualmem
cpp/testclosedondestroydm
cpp/testcopywords
cpp/testperfcopywords
cpp/testthreadcond
2 changes: 1 addition & 1 deletion gdal/alg/gdalrasterize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ CPLErr GDALRasterizeLayers( GDALDatasetH hDS,
;
else
{
GIntBig nYChunkSize64 = GDALGetCacheMax64() / nScanlineBytes;
GIntBig nYChunkSize64 = poDS->GetRasterBlockManager()->GetCacheMax() / nScanlineBytes;
if (nYChunkSize64 > INT_MAX)
nYChunkSize = INT_MAX;
else
Expand Down
12 changes: 7 additions & 5 deletions gdal/frmts/epsilon/epsilondataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "epsilon.h"
#include "gdal_pam.h"
#include "cpl_multiproc.h"

CPL_CVSID("$Id$");

Expand Down Expand Up @@ -337,11 +338,12 @@ CPLErr EpsilonRasterBand::IReadBlock( int nBlockXOff,
poBlock->DropLock();
break;
}

memcpy(pabySrcBlock,
poGDS->pabyRGBData + (iOtherBand - 1) * nBlockXSize * nBlockYSize,
nBlockXSize * nBlockYSize);

{
CPLMutexHolderD( poGDS->GetRasterBand(iOtherBand)->GetRWMutex() );
memcpy(pabySrcBlock,
poGDS->pabyRGBData + (iOtherBand - 1) * nBlockXSize * nBlockYSize,
nBlockXSize * nBlockYSize);
}
poBlock->DropLock();
}
}
Expand Down
4 changes: 2 additions & 2 deletions gdal/frmts/gtiff/geotiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ CPLErr GTiffRasterBand::IRasterIO( GDALRWFlag eRWFlag,
GIntBig nRequiredMem = (GIntBig)poGDS->nBands * nXBlocks * nYBlocks *
nBlockXSize * nBlockYSize *
(GDALGetDataTypeSize(eDataType) / 8);
if (nRequiredMem > GDALGetCacheMax64())
if (nRequiredMem > poDS->GetRasterBlockManager()->GetCacheMax())
{
if (!poGDS->bHasWarnedDisableAggressiveBandCaching)
{
Expand Down Expand Up @@ -1961,7 +1961,7 @@ CPLErr GTiffRasterBand::FillCacheForOtherBands( int nBlockXOff, int nBlockYOff )
/* enough to accomodate the size of all the blocks, don't enter */
/* -------------------------------------------------------------------- */
if( poGDS->nBands != 1 && !poGDS->bLoadingOtherBands &&
nBlockXSize * nBlockYSize * (GDALGetDataTypeSize(eDataType) / 8) < GDALGetCacheMax64() / poGDS->nBands)
nBlockXSize * nBlockYSize * (GDALGetDataTypeSize(eDataType) / 8) < poDS->GetRasterBlockManager()->GetCacheMax() / poGDS->nBands)
{
int iOtherBand;

Expand Down
7 changes: 5 additions & 2 deletions gdal/frmts/jp2kak/jp2kakdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,11 @@ CPLErr JP2KAKRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,

if( poBlock )
{
memcpy( poBlock->GetDataRef(), pabyWrkBuffer + nBandStart,
nWordSize * nBlockXSize * nBlockYSize );
{
CPLMutexHolderD( poBand->GetRWMutex() );
memcpy( poBlock->GetDataRef(), pabyWrkBuffer + nBandStart,
nWordSize * nBlockXSize * nBlockYSize );
}
poBlock->DropLock();
}
}
Expand Down
15 changes: 10 additions & 5 deletions gdal/frmts/mbtiles/mbtilesdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "gdal_pam.h"
#include "ogr_api.h"
#include "cpl_vsil_curl_priv.h"
#include "cpl_multiproc.h"

#include "zlib.h"
#include "json.h"
Expand Down Expand Up @@ -293,11 +294,14 @@ CPLErr MBTilesBand::IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage)
poBlock->DropLock();
break;
}

if (nTileBands == 3 && poGDS->nBands == 4 && iOtherBand == 4)
{
CPLMutexHolderD( poGDS->GetRasterBand(iOtherBand)->GetRWMutex() );
memset(pabySrcBlock, 255, nBlockXSize * nBlockYSize);
}
else if (nTileBands == 1 && (poGDS->nBands == 3 || poGDS->nBands == 4))
{
CPLMutexHolderD( poGDS->GetRasterBand(iOtherBand)->GetRWMutex() );
int i;
if (pSrcImage)
{
Expand Down Expand Up @@ -381,10 +385,11 @@ CPLErr MBTilesBand::IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage)
poBlock->DropLock();
break;
}

memset(pabySrcBlock, (iOtherBand == 4) ? 0 : 255,
nBlockXSize * nBlockYSize);

{
CPLMutexHolderD( poGDS->GetRasterBand(iOtherBand)->GetRWMutex() );
memset(pabySrcBlock, (iOtherBand == 4) ? 0 : 255,
nBlockXSize * nBlockYSize);
}
poBlock->DropLock();
}
}
Expand Down
10 changes: 5 additions & 5 deletions gdal/frmts/openjpeg/openjpegdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,9 @@ static void JP2OpenJPEGReadBlockInThread(void* userdata)
poBlock->DropLock();
break;
}

poGDS->ReadBlock(nBand, fp, nBlockXOff, nBlockYOff, pDstBuffer,
nBandCount, panBandMap);

poBlock->DropLock();
}

Expand All @@ -468,7 +467,7 @@ int JP2OpenJPEGDataset::PreloadBlocks(JP2OpenJPEGRasterBand* poBand,
int nMaxThreads = GetNumThreads();
if( !bUseSetDecodeArea && nMaxThreads > 1 )
{
if( nReqMem > GDALGetCacheMax64() / (nBandCount == 0 ? 1 : nBandCount) )
if( nReqMem > poRasterBlockManager->GetCacheMax() / (nBandCount == 0 ? 1 : nBandCount) )
return FALSE;

int nBlocksToLoad = 0;
Expand Down Expand Up @@ -508,7 +507,7 @@ int JP2OpenJPEGDataset::PreloadBlocks(JP2OpenJPEGRasterBand* poBand,
}
else
{
if( nReqMem <= GDALGetCacheMax64() / nBands )
if( nReqMem <= poRasterBlockManager->GetCacheMax() / nBands )
{
oJob.nBandCount = nBands;
oJob.panBandMap = NULL;
Expand Down Expand Up @@ -716,7 +715,6 @@ CPLErr JP2OpenJPEGDataset::ReadBlock( int nBand, VSILFILE* fp,
continue;
}
}

if (bIs420)
{
CPLAssert((int)psImage->comps[0].w >= nWidthToRead);
Expand All @@ -729,6 +727,7 @@ CPLErr JP2OpenJPEGDataset::ReadBlock( int nBand, VSILFILE* fp,
OPJ_INT32* pSrcY = psImage->comps[0].data;
OPJ_INT32* pSrcCb = psImage->comps[1].data;
OPJ_INT32* pSrcCr = psImage->comps[2].data;
CPLMutexHolderD( &hRWMutex );
GByte* pDst = (GByte*)pDstBuffer;
for(int j=0;j<nHeightToRead;j++)
{
Expand Down Expand Up @@ -761,6 +760,7 @@ CPLErr JP2OpenJPEGDataset::ReadBlock( int nBand, VSILFILE* fp,
}
}
}
CPLMutexHolderD( &hRWMutex );

if ((int)psImage->comps[iBand-1].w == nBlockXSize &&
(int)psImage->comps[iBand-1].h == nBlockYSize)
Expand Down
15 changes: 9 additions & 6 deletions gdal/frmts/postgisraster/postgisrasterdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* SOFTWARE.
**********************************************************************/
#include "postgisraster.h"
#include "cpl_multiproc.h"
#include <math.h>

#ifdef _WIN32
Expand Down Expand Up @@ -973,11 +974,13 @@ void PostGISRasterDataset::CacheTile(const char* pszMetadata,
{
GDALRasterBlock* poBlock = poRTB->GetLockedBlockRef(0, 0, TRUE);
if( poBlock != NULL )
{
// Point block data ref to fetched data
memcpy(poBlock->GetDataRef(), (void *)pbyDataToRead,
nExpectedBandDataSize);

{
{
CPLMutexHolderD( poRTB->GetRWMutex() );
// Point block data ref to fetched data
memcpy(poBlock->GetDataRef(), (void *)pbyDataToRead,
nExpectedBandDataSize);
}
poBlock->DropLock();
}
}
Expand Down Expand Up @@ -1065,7 +1068,7 @@ GBool PostGISRasterDataset::LoadSources(int nXOff, int nYOff, int nXSize, int nY
{
GIntBig nMemoryRequiredForTiles = PQntuples(poResult) * nTileWidth * nTileHeight *
GDALGetDataTypeSize(GetRasterBand(nBand)->GetRasterDataType()) / 8;
GIntBig nCacheMax = (GIntBig) GDALGetCacheMax64();
GIntBig nCacheMax = (GIntBig) poRasterBlockManager->GetCacheMax();
if( nBands * nMemoryRequiredForTiles <= nCacheMax )
{
bLoadRasters = TRUE;
Expand Down
2 changes: 1 addition & 1 deletion gdal/frmts/postgisraster/postgisrasterrasterband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ CPLErr PostGISRasterRasterBand::IRasterIO(GDALRWFlag eRWFlag, int nXOff,
int bAllBandCaching = FALSE;
if (nTilesToFetch > 0)
{
GIntBig nCacheMax = (GIntBig) GDALGetCacheMax64();
GIntBig nCacheMax = (GIntBig) GetRasterBlockManager()->GetCacheMax();
if( nMemoryRequiredForTiles > nCacheMax )
{
CPLDebug("PostGIS_Raster",
Expand Down
3 changes: 3 additions & 0 deletions gdal/frmts/vrt/vrtwarped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "vrtdataset.h"
#include "cpl_minixml.h"
#include "cpl_string.h"
#include "cpl_multiproc.h"
#include "gdalwarper.h"
#include "gdal_alg_priv.h"
#include <cassert>
Expand Down Expand Up @@ -1200,6 +1201,7 @@ CPLErr VRTWarpedDataset::ProcessBlock( int iBlockX, int iBlockY )
{
if ( poBlock->GetDataRef() != NULL )
{
CPLMutexHolderD( poBand->GetRWMutex() );
GDALCopyWords( pabyDstBuffer + iBand*nBlockXSize*nBlockYSize*nWordSize,
psWO->eWorkingDataType, nWordSize,
poBlock->GetDataRef(),
Expand Down Expand Up @@ -1292,6 +1294,7 @@ CPLErr VRTWarpedRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
int nDataBytes;
nDataBytes = (GDALGetDataTypeSize(poBlock->GetDataType()) / 8)
* poBlock->GetXSize() * poBlock->GetYSize();
CPLMutexHolderD( GetRWMutex() );
memcpy( pImage, poBlock->GetDataRef(), nDataBytes );
}

Expand Down
10 changes: 10 additions & 0 deletions gdal/frmts/wms/gdalwmsrasterband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
****************************************************************************/

#include "wmsdriver.h"
#include "cpl_multiproc.h"

GDALWMSRasterBand::GDALWMSRasterBand(GDALWMSDataset *parent_dataset, int band, double scale) {
// printf("[%p] GDALWMSRasterBand::GDALWMSRasterBand(%p, %d, %f)\n", this, parent_dataset, band, scale);
Expand Down Expand Up @@ -623,11 +624,14 @@ CPLErr GDALWMSRasterBand::ReadBlockFromFile(int x, int y, const char *file_name,
for (int ib = 1; ib <= m_parent_dataset->nBands; ++ib) {
if (ret == CE_None) {
void *p = NULL;
void ** hThisMutex = NULL;
GDALRasterBlock *b = NULL;
if ((buffer != NULL) && (ib == to_buffer_band)) {
p = buffer;
hThisMutex = NULL;
} else {
GDALWMSRasterBand *band = static_cast<GDALWMSRasterBand *>(m_parent_dataset->GetRasterBand(ib));
hThisMutex = band->GetRWMutex();
if (m_overview >= 0) band = static_cast<GDALWMSRasterBand *>(band->GetOverview(m_overview));
if (!band->IsBlockInCache(x, y)) {
b = band->GetLockedBlockRef(x, y, true);
Expand Down Expand Up @@ -664,6 +668,7 @@ CPLErr GDALWMSRasterBand::ReadBlockFromFile(int x, int y, const char *file_name,
if (accepted_as_no_alpha)
{
// the file had 3 bands and we are reading band 4 (Alpha) so fill with 255 (no alpha)
CPLMutexHolderD( hThisMutex );
GByte *byte_buffer = reinterpret_cast<GByte *>(p);
for (int y = 0; y < sy; ++y) {
for (int x = 0; x < sx; ++x) {
Expand All @@ -686,6 +691,7 @@ CPLErr GDALWMSRasterBand::ReadBlockFromFile(int x, int y, const char *file_name,
}
if (ret == CE_None) {
GByte *band_color_table = color_table + 256 * (ib - 1);
CPLMutexHolderD( hThisMutex );
GByte *byte_buffer = reinterpret_cast<GByte *>(p);
for (int y = 0; y < sy; ++y) {
for (int x = 0; x < sx; ++x) {
Expand Down Expand Up @@ -724,11 +730,14 @@ CPLErr GDALWMSRasterBand::ZeroBlock(int x, int y, int to_buffer_band, void *buff
for (int ib = 1; ib <= m_parent_dataset->nBands; ++ib) {
if (ret == CE_None) {
void *p = NULL;
void **hThisMutex = NULL;
GDALRasterBlock *b = NULL;
if ((buffer != NULL) && (ib == to_buffer_band)) {
p = buffer;
hThisMutex = NULL;
} else {
GDALWMSRasterBand *band = static_cast<GDALWMSRasterBand *>(m_parent_dataset->GetRasterBand(ib));
hThisMutex = band->GetRWMutex();
if (m_overview >= 0) band = static_cast<GDALWMSRasterBand *>(band->GetOverview(m_overview));
if (!band->IsBlockInCache(x, y)) {
b = band->GetLockedBlockRef(x, y, true);
Expand All @@ -742,6 +751,7 @@ CPLErr GDALWMSRasterBand::ZeroBlock(int x, int y, int to_buffer_band, void *buff
}
}
if (p != NULL) {
CPLMutexHolderD( hThisMutex );
unsigned char *b = reinterpret_cast<unsigned char *>(p);
int block_size = nBlockXSize * nBlockYSize * (GDALGetDataTypeSize(eDataType) / 8);
for (int i = 0; i < block_size; ++i) b[i] = 0;
Expand Down
3 changes: 2 additions & 1 deletion gdal/gcore/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ OBJ = gdalopeninfo.o gdaldrivermanager.o gdaldriver.o gdaldataset.o \
gdalallvalidmaskband.o gdalnodatamaskband.o gdal_rpcimdio.o \
gdalproxydataset.o gdalproxypool.o gdaldefaultasync.o \
gdalnodatavaluesmaskband.o gdaldllmain.o gdalexif.o gdalclientserver.o \
gdalgeorefpamdataset.o gdaljp2abstractdataset.o gdalvirtualmem.o
gdalgeorefpamdataset.o gdaljp2abstractdataset.o gdalvirtualmem.o \
gdalrasterblockmanager.o

# Enable the following if you want to use MITAB's code to convert
# .tab coordinate systems into well known text. But beware that linking
Expand Down
Loading