Repository navigation
Avoid flushing a zero-sized mmapped file - #5842
Merged
Merged
Conversation
coszio
commented
Jan 21, 2025
| #[case(1111, 1110)] | ||
| #[case(1111, 0)] | ||
| #[case(10, 2)] | ||
| #[case(0, 0)] |
Contributor
Author
There was a problem hiding this comment.
If we had included this case, we would've discovered this much earlier 📝
ffuugoo
approved these changes
Jan 21, 2025
timvisee
approved these changes
Jan 21, 2025
Comment on lines
165
to
174
| Box::new({ | ||
| let mmap = self.mmap.clone(); | ||
| move || { | ||
| mmap.flush()?; | ||
| // flushing a zero-sized mmap can cause panicking on some systems | ||
| if mmap.len() > 0 { | ||
| mmap.flush()?; | ||
| } | ||
| Ok(()) | ||
| } | ||
| }) |
Member
There was a problem hiding this comment.
Can we move the length check outside of the box, and return an empty closure if it's empty?
That may be a bit nicer so we don't clone the mmap structure (even though it's empty).
Contributor
Author
There was a problem hiding this comment.
Is it ensured that a mmap won't grow its size? just thinking that this returns a closure which will be run at a later time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Discovered when running crasher 🔥
The problem arose when trying to convert an empty
ImmutableInvertedIndexinto aMmapInvertedIndex, which would create zero-sized files.There seems to be no problem mmapping them, but, when we try to
msyncduring flushing, it panics with anEINVALerror.I have done a simple fix where we just don't flush when the file length is zero.