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

Prefetch buffer may not contain all of requested data if EOF is hit #13376

Closed
wants to merge 2 commits into from

Conversation

archang19
Copy link
Contributor

@archang19 archang19 commented Feb 6, 2025

Summary

There was a stress test that failed at the assertion check for IsDataBlockInBuffer.

IsDataBlockInBuffer is too strict of a condition if we are trying to read past the end of the file.

This seems to be a bug from the original 2019 commit siying@3737d06: https://github.com/siying/rocksdb/blob/4eb51130917c260f5637731cd77baaa45dfdc5ec/file/file_prefetch_buffer.cc#L130

If the caller tries requesting more bytes than are available, then we still return n bytes, even if the buffer really only contains m < n bytes.

Test Plan

I added a unit test which caused the original IsDataBlockInBuffer assertion to fail. I also updated the unit test to check for the result size, which triggered the bug (without this fix) where we return a size of n even if less than n bytes exist.

@@ -865,8 +865,7 @@ bool FilePrefetchBuffer::TryReadFromCacheUntracked(
if (copy_to_overlap_buffer) {
buf = overlap_buf_;
}
assert(buf->offset_ <= offset);
assert(buf->IsDataBlockInBuffer(offset, n));
assert(buf->IsOffsetInBuffer(offset));
uint64_t offset_in_buffer = offset - buf->offset_;
*result = Slice(buf->buffer_.BufferStart() + offset_in_buffer, n);
Copy link
Contributor Author

@archang19 archang19 Feb 6, 2025

Choose a reason for hiding this comment

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

I think this is a bug from this 2019 commit siying@3737d06: https://github.com/siying/rocksdb/blob/4eb51130917c260f5637731cd77baaa45dfdc5ec/file/file_prefetch_buffer.cc#L130

What happens if we try to read more bytes than there exists in the file? I don't think we always want to return n bytes.

@archang19 archang19 force-pushed the prefetch-update-assertion branch 2 times, most recently from 5507d62 to 0e22c2e Compare February 6, 2025 19:35
@archang19 archang19 force-pushed the prefetch-update-assertion branch from 0e22c2e to 159dd79 Compare February 6, 2025 22:17
@facebook-github-bot
Copy link
Contributor

@archang19 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@archang19 archang19 marked this pull request as ready for review February 6, 2025 22:18
@archang19 archang19 requested a review from anand1976 February 6, 2025 22:41
@archang19
Copy link
Contributor Author

fyi @jowlyzhang this error affected the warm storage crash tests

@facebook-github-bot
Copy link
Contributor

@archang19 merged this pull request in c1fb33e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants