Improve Gridstore wipe/clear functionality #6614
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Gridstore has a
wipe
function which drops storage, it did take a&mut self
reference. It was problematic.It is fine to use to clear, close and remove storage. But, it's not fine to clear storage and reuse storage afterwards. It leaves the storage in an inconsistent state. I therefore consider this to be a nasty footgun, and I'd argue it must take ownership to disallow reuse.
I've added a test to show the problematic behavior. It calls wipe the same way as we do on other storages, producing this panic:
To fix the problem I've done two things:
wipe(mut self)
take ownership to disallow reuseclear(&mut self)
to clear and get into the initial state (one empty page), allowing reuseThe clear function is naively implemented removing the directory and recreating storage, but I don't see this as a huge problem.
I actually discovered this problem while implementing #6609. It puzzled me for more than an hour, which is why I'm fixing it now.
All Submissions:
dev
branch. Did you create your branch fromdev
?New Feature Submissions:
cargo +nightly fmt --all
command prior to submission?cargo clippy --all --all-features
command?