Skip to content

Avoid flushing a zero-sized mmapped file - #5842

Merged
coszio merged 1 commit into
devfrom
skip-flushing-zero-sized-files
Jan 21, 2025
Merged

coszio merged 1 commit into
devfrom
skip-flushing-zero-sized-files

Conversation

@coszio

@coszio coszio commented Jan 21, 2025

Copy link
Copy Markdown
Contributor

Discovered when running crasher 🔥

The problem arose when trying to convert an empty ImmutableInvertedIndex into a MmapInvertedIndex, which would create zero-sized files.

There seems to be no problem mmapping them, but, when we try to msync during flushing, it panics with an EINVAL error.

I have done a simple fix where we just don't flush when the file length is zero.

@coszio
coszio requested review from generall and timvisee January 21, 2025 15:48
#[case(1111, 1110)]
#[case(1111, 0)]
#[case(10, 2)]
#[case(0, 0)]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we had included this case, we would've discovered this much earlier 📝

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(())
}
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

@coszio
coszio merged commit d9f2baa into dev Jan 21, 2025
@coszio
coszio deleted the skip-flushing-zero-sized-files branch January 21, 2025 19:11
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.

3 participants