Repository navigation
Conversation
…uffered bytes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Generated-by: Claude Code (Opus 5.5)
What changes were proposed in this pull request?
ChunkInputStream.read(byte[], int, int)andread(ByteBuffer)can first copy bytes still buffered from the previous ReadChunk and then issue another ReadChunk for the rest. If that ReadChunk fails, the copied byte count is lost with the exception but the chunk position stays advanced.BlockInputStream.readWithStrategythen refreshes the pipeline and token and retries from the advanced position:byte[]: theByteArrayReaderoffset never advanced, so the retry writes the following bytes over the start of the caller's buffer and reports success. The read silently returns wrong data and the stream ends up that many bytes ahead.ByteBuffer: the data lands in the right place but the count is short, so the read fails with "Inconsistent read" although the retry itself succeeded.Triggers include a block token expiring on a long open stream (
BLOCK_TOKEN_VERIFICATION_FAILED, which the client is designed to refresh and retry) or a transient datanode or network failure, combined with a sequential read that starts inside a buffered checksum range (any read size or seek offset not aligned to bytes per checksum).Fix: when
prepareReadthrows after the call has already copied bytes, seek the chunk stream back by that many bytes (and reset theByteBufferposition) before rethrowing, so a failed call has no effect and the retry resumes from where the call started. Successful reads and reads that fail before copying anything are unchanged. When retries are exhausted, the stream is now left at the start of the failed call instead of past the copied bytes.Positioned reads and the streaming read path are not affected.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-17000
How was this patch tested?
Added
retriedReadReturnsContiguousDataandfailedReadLeavesPositionUnchangedtoTestBlockInputStream, using a realChunkInputStreamwith ReadChunk stubbed to fail withBLOCK_TOKEN_VERIFICATION_FAILED, for bothbyte[]andByteBuffer, after an unaligned and an aligned first read. Without the fix, the four unaligned/exhausted cases fail (wrong bytes, "Inconsistent read", wrong position); with the fix all pass.Also verified locally: the reproduction attached to the JIRA shows the defect on master and no longer does with the fix;
hdds-clientandozone-clientunit tests,TestChunkInputStreamandTestKeyInputStreampass; checkstyle is clean.🤖 Generated with Claude Code