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

added DropCache to GDALDataset #8940

Merged
merged 9 commits into from
Dec 11, 2023
Merged

added DropCache to GDALDataset #8940

merged 9 commits into from
Dec 11, 2023

Conversation

chacha21
Copy link
Contributor

@chacha21 chacha21 commented Dec 8, 2023

DropCache() release cache blocks but does not write cache to disk. It is similar to FlushCache(true) but does not assume that the dataset will be closed.

proposal for #8938

DropCache() release cache blocks but does not write cache to disk.
It is similar tp FlushCache(true) but does not assume that the dataset will be closed.
Copy link
Member

@rouault rouault left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides my comments, looks good to me.
We'd need a test for that. Presumably in autotest/cpp/test_gdal.cpp (run by autotest/cpp/gdal_unit_test)

@@ -537,6 +537,7 @@ class CPL_DLL GDALDataset : public GDALMajorObject
Bands GetBands();

virtual CPLErr FlushCache(bool bAtClosing = false);
virtual CPLErr DropCache();
Copy link
Member

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 ?

Copy link
Contributor Author

@chacha21 chacha21 Dec 8, 2023

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -1188,7 +1189,7 @@ class GDALAbstractBandBlockCache

int m_nInitialDirtyBlocksInFlushCache = 0;
int m_nLastTick = -1;
bool m_bWriteDirtyBlocks = true;
size_t m_bWriteDirtyBlocksDisabled = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'b' is for boolean. So this should be "m_nWriteDirtyBlocksDisabled"

@@ -1412,6 +1417,7 @@ class CPL_DLL GDALRasterBand : public GDALMajorObject
// New OpengIS CV_SampleDimension stuff.

virtual CPLErr FlushCache(bool bAtClosing = false);
virtual CPLErr DropCache();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

virtual needed ?

Comment on lines 625 to 626
* @return CE_None in case of success
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return CE_None in case of success
*/
* @return CE_None in case of success
* @since 3.9
*/

* \brief Drop all write cached data
*
* @see GDALDataset::DropCache().
* @return CE_None in case of success
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return CE_None in case of success
* @return CE_None in case of success
* @since 3.9

*
* This method is the same as the C function GDALDropRasterCache().
*
* @return CE_None on success.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return CE_None on success.
* @return CE_None on success.
* @since 3.9

/**
* \brief Drop raster data cache.
*
* @see GDALRasterBand::DropCache()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @see GDALRasterBand::DropCache()
* @see GDALRasterBand::DropCache()
* @since 3.9

also removed a useless comment inherited from copy/paste
@chacha21
Copy link
Contributor Author

chacha21 commented Dec 8, 2023

We'd need a test for that. Presumably in autotest/cpp/test_gdal.cpp (run by autotest/cpp/gdal_unit_test)

What kind of test should be written ?

@rouault
Copy link
Member

rouault commented Dec 8, 2023

What kind of test should be written ?

something along:

  • create a new dataset (1x1 should be fine)
  • call GDALFillRaster(band, 1)
  • call GDALDropCache(...)
  • GDALClose(...)
  • GDALOpen(...)
  • check that GDALChecksumImage(GDALGetRasterBand(hDS, 1), 0, 0, 1, 1) == 0

m_bWriteDirtyBlocks -> m_nWriteDirtyBlocksDisabled
@chacha21
Copy link
Contributor Author

chacha21 commented Dec 8, 2023

I was not able to run the test, there's something broken with my gtests

@rouault
Copy link
Member

rouault commented Dec 8, 2023

for correct code formatting, you need to install pre-commit. Cf https://gdal.org/development/dev_practices.html#commit-hooks for instructions

@chacha21
Copy link
Contributor Author

chacha21 commented Dec 9, 2023

Does DropCache() make FlushCache(true) obsolete ?
I mean , instead of having the bClosing parameter, one could instead use DropCache() at the beginning of a dataset destructor in the case of MarkSuppressOnClose(), so that every subsequent FlushCache() would do nothing.

@rouault
Copy link
Member

rouault commented Dec 9, 2023

Does DropCache() make FlushCache(true) obsolete ? I mean , instead of having the bClosing parameter, one could instead use DropCache() at the beginning of a dataset destructor in the case of MarkSuppressOnClose(), so that every subsequent FlushCache() would do nothing.

yes, that mostly obsoletes it. That said there are a few drivers that use now the bAtClosing flag to save some work (cf frmts/rmf/rmfdataset.cpp)

@@ -3491,4 +3491,48 @@ TEST_F(test_gdal, open_shared_open_options)
}
}

// Test GDAL_OF_SHARED flag and open options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment should be updated or removed

@rouault
Copy link
Member

rouault commented Dec 11, 2023

@chacha21 are you done with this PR?

@chacha21
Copy link
Contributor Author

@chacha21 are you done with this PR?

As long as you have no more comments, I have nothing remaining to be committed.
I just could not run the test myself (can't explain why, gtest is crashing on my machine), so I just have to trust the buildbot.

I ran the test code manually and it behaved as expected, though. (GDALChecksumImage returns 0)

@rouault rouault merged commit 5489059 into OSGeo:master Dec 11, 2023
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants