Fix directIO reader hang when pread returns short reads#4841
Open
void-ptr974 wants to merge 2 commits into
Open
Fix directIO reader hang when pread returns short reads#4841void-ptr974 wants to merge 2 commits into
void-ptr974 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a potential hang in DirectReader when using O_DIRECT reads and pread returns a short read: the reader now advances by the aligned portion actually read (and fails fast if no aligned progress is possible), preventing repeated reads at the same offset. It also tightens buffer-copying to only return bytes that are actually available within the currently loaded block, and adds a regression test for aligned short-read progress.
Changes:
- Fix aligned progress calculation in
DirectReader.readBlock()for shortpreadresults and fail fast on zero aligned progress. - Ensure
readBytesIntoBuf()copies only the bytes available in the current cached block. - Add a unit test that simulates aligned short reads and verifies the reader advances to the next aligned offset.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/DirectReader.java | Fixes short-read alignment progress and restricts copying to bytes available in the current block. |
| bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/directentrylogger/TestDirectReader.java | Adds a regression test to ensure aligned short reads advance the read offset and complete. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+233
to
+235
| .kv("requestedBytes", blockSize) | ||
| .kv("offset", blockStart) | ||
| .kv("expectedBytes", Math.min(blockSize, bytesAvailable)) |
| .kv("size", size).toString()); | ||
| } | ||
| return nativeBuffer.readByteBuf(buf, offsetInBuffer, size); | ||
| return nativeBuffer.readByteBuf(buf, offsetInBuffer, sizeInBuffer); |
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.
DirectReader performs aligned O_DIRECT reads into a reusable native buffer. Short reads must preserve alignment, and failed partial reads must not leave modified buffer contents associated with stale cache metadata.
This change:
Tests:
mvn -pl bookkeeper-server -DskipTests=false -Dtest=TestDirectReader testmvn -pl bookkeeper-server -DskipTests checkstyle:checkgit diff --check