-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
added DropCache to GDALDataset #8940
Changes from 2 commits
27c6a37
c761f4c
35c52f2
96d53a2
1427e75
02039ab
9a0b161
a311185
86f1fbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -537,6 +537,7 @@ class CPL_DLL GDALDataset : public GDALMajorObject | |
Bands GetBands(); | ||
|
||
virtual CPLErr FlushCache(bool bAtClosing = false); | ||
virtual CPLErr DropCache(); | ||
|
||
virtual GIntBig GetEstimatedRAMUsage(); | ||
|
||
|
@@ -1188,7 +1189,7 @@ class GDALAbstractBandBlockCache | |
|
||
int m_nInitialDirtyBlocksInFlushCache = 0; | ||
int m_nLastTick = -1; | ||
bool m_bWriteDirtyBlocks = true; | ||
size_t m_bWriteDirtyBlocksDisabled = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'b' is for boolean. So this should be "m_nWriteDirtyBlocksDisabled" |
||
|
||
void FreeDanglingBlocks(); | ||
void UnreferenceBlockBase(); | ||
|
@@ -1205,9 +1206,13 @@ class GDALAbstractBandBlockCache | |
void AddBlockToFreeList(GDALRasterBlock *); | ||
void IncDirtyBlocks(int nInc); | ||
void WaitCompletionPendingTasks(); | ||
void EnableDirtyBlockWriting() | ||
{ | ||
--m_bWriteDirtyBlocksDisabled; | ||
} | ||
void DisableDirtyBlockWriting() | ||
{ | ||
m_bWriteDirtyBlocks = false; | ||
++m_bWriteDirtyBlocksDisabled; | ||
} | ||
bool HasDirtyBlocks() const | ||
{ | ||
|
@@ -1412,6 +1417,7 @@ class CPL_DLL GDALRasterBand : public GDALMajorObject | |
// New OpengIS CV_SampleDimension stuff. | ||
|
||
virtual CPLErr FlushCache(bool bAtClosing = false); | ||
virtual CPLErr DropCache(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. virtual needed ? |
||
virtual char **GetCategoryNames(); | ||
virtual double GetNoDataValue(int *pbSuccess = nullptr); | ||
virtual int64_t GetNoDataValueAsInt64(int *pbSuccess = nullptr); | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -613,6 +613,59 @@ CPLErr CPL_STDCALL GDALFlushCache(GDALDatasetH hDS) | |||||||||||
return GDALDataset::FromHandle(hDS)->FlushCache(false); | ||||||||||||
} | ||||||||||||
|
||||||||||||
/************************************************************************/ | ||||||||||||
/* DropCache() */ | ||||||||||||
/************************************************************************/ | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* \brief Drop all write cached data | ||||||||||||
* | ||||||||||||
* This method is the same as the C function GDALDropCache(). | ||||||||||||
* | ||||||||||||
* @return CE_None in case of success | ||||||||||||
*/ | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
CPLErr GDALDataset::DropCache() | ||||||||||||
|
||||||||||||
{ | ||||||||||||
CPLErr eErr = CE_None; | ||||||||||||
// This sometimes happens if a dataset is destroyed before completely | ||||||||||||
// built. | ||||||||||||
|
||||||||||||
if (papoBands) | ||||||||||||
{ | ||||||||||||
for (int i = 0; i < nBands; ++i) | ||||||||||||
{ | ||||||||||||
if (papoBands[i]) | ||||||||||||
{ | ||||||||||||
if (papoBands[i]->DropCache() != CE_None) | ||||||||||||
eErr = CE_Failure; | ||||||||||||
} | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
return eErr; | ||||||||||||
} | ||||||||||||
|
||||||||||||
/************************************************************************/ | ||||||||||||
/* GDALDropCache() */ | ||||||||||||
/************************************************************************/ | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* \brief Drop all write cached data | ||||||||||||
* | ||||||||||||
* @see GDALDataset::DropCache(). | ||||||||||||
* @return CE_None in case of success | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
*/ | ||||||||||||
|
||||||||||||
CPLErr CPL_STDCALL GDALDropCache(GDALDatasetH hDS) | ||||||||||||
|
||||||||||||
{ | ||||||||||||
VALIDATE_POINTER1(hDS, "GDALDropCache", CE_Failure); | ||||||||||||
|
||||||||||||
return GDALDataset::FromHandle(hDS)->DropCache(); | ||||||||||||
} | ||||||||||||
|
||||||||||||
/************************************************************************/ | ||||||||||||
/* GetEstimatedRAMUsage() */ | ||||||||||||
/************************************************************************/ | ||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -1140,6 +1140,68 @@ CPLErr CPL_STDCALL GDALFlushRasterCache(GDALRasterBandH hBand) | |||||||
return GDALRasterBand::FromHandle(hBand)->FlushCache(false); | ||||||||
} | ||||||||
|
||||||||
/************************************************************************/ | ||||||||
/* DropCache() */ | ||||||||
/************************************************************************/ | ||||||||
|
||||||||
/** | ||||||||
* \brief Drop raster data cache : data in cache will be lost. | ||||||||
* | ||||||||
* This call will recover memory used to cache data blocks for this raster | ||||||||
* band, and ensure that new requests are referred to the underlying driver. | ||||||||
* | ||||||||
* This method is the same as the C function GDALDropRasterCache(). | ||||||||
* | ||||||||
* @return CE_None on success. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
*/ | ||||||||
|
||||||||
CPLErr GDALRasterBand::DropCache() | ||||||||
|
||||||||
{ | ||||||||
CPLErr result = CE_None; | ||||||||
|
||||||||
if (poBandBlockCache) | ||||||||
poBandBlockCache->DisableDirtyBlockWriting(); | ||||||||
|
||||||||
CPLErr eGlobalErr = eFlushBlockErr; | ||||||||
|
||||||||
if (eFlushBlockErr != CE_None) | ||||||||
{ | ||||||||
ReportError( | ||||||||
eFlushBlockErr, CPLE_AppDefined, | ||||||||
"An error occurred while writing a dirty block from DropCache"); | ||||||||
eFlushBlockErr = CE_None; | ||||||||
} | ||||||||
|
||||||||
if (poBandBlockCache == nullptr || !poBandBlockCache->IsInitOK()) | ||||||||
result = eGlobalErr; | ||||||||
else | ||||||||
result = poBandBlockCache->FlushCache(); | ||||||||
|
||||||||
if (poBandBlockCache) | ||||||||
poBandBlockCache->EnableDirtyBlockWriting(); | ||||||||
|
||||||||
return result; | ||||||||
} | ||||||||
|
||||||||
/************************************************************************/ | ||||||||
/* GDALDropRasterCache() */ | ||||||||
/************************************************************************/ | ||||||||
|
||||||||
/** | ||||||||
* \brief Drop raster data cache. | ||||||||
* | ||||||||
* @see GDALRasterBand::DropCache() | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
*/ | ||||||||
|
||||||||
CPLErr CPL_STDCALL GDALDropRasterCache(GDALRasterBandH hBand) | ||||||||
|
||||||||
{ | ||||||||
VALIDATE_POINTER1(hBand, "GDALDropRasterCache", CE_Failure); | ||||||||
|
||||||||
return GDALRasterBand::FromHandle(hBand)->DropCache(); | ||||||||
} | ||||||||
|
||||||||
/************************************************************************/ | ||||||||
/* UnreferenceBlock() */ | ||||||||
/* */ | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does that need to be virtual ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly it is just copy/paste from FlushCache().
I think
virtual
is harmless and make it ready for future specific implementations (if any)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok