Repository navigation
HDDS-16258. Refactor streaming block reads and fix checksum verification for variable-sized chunks #11302
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
Merged
+663
−345
Merged
HDDS-16258. Refactor streaming block reads and fix checksum verification for variable-sized chunks #11302
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8bff57b
HDDS-16258. Verify streaming block reads using chunk boundaries
peterxcli cfd49a2
HDDS-16258. Keep existing streaming response test builders separate
peterxcli c5f8eb6
HDDS-16258. Simplify streaming response schema and range validation
peterxcli 31d0ffb
HDDS-16258. Preserve the release protobuf compatibility baseline
peterxcli cdae9ed
HDDS-16258. Bound streaming response buffers using the existing read …
peterxcli da3fb37
HDDS-16258. Use chunk offsets for cursor boundary lookup
peterxcli f0dfd43
HDDS-16258. Clarify cursor boundary search
peterxcli 4dc5af7
HDDS-16258. Retain the streaming alignment constant
peterxcli ece80ba
HDDS-16258. Keep validation focused on streaming checksums
peterxcli 6505008
HDDS-16258. Omit streaming response checksums when not requested
peterxcli ca5728f
HDDS-16258. Remove redundant includeChecksums comment
peterxcli cc04676
Merge branch 'master' into HDDS-16258
peterxcli d3769cd
HDDS-16258. Merge master and preserve streaming checksum verification
peterxcli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,6 @@ | |
|
|
||
| package org.apache.hadoop.ozone.common; | ||
|
|
||
| import static org.apache.ratis.util.Preconditions.assertSame; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import java.nio.ByteBuffer; | ||
| import java.security.MessageDigest; | ||
|
|
@@ -441,37 +439,37 @@ public static void verifyChecksum(List<ByteBuffer> bufferList, int startIndex, C | |
| public static void validateChecksums(ByteBuffer data, long blockOffset, int startIndex, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding those check is nice, but could you clarify the motivation behind refactoring this method? From my perspective, this change seems unnecessary. Please leave this part as it is. |
||
| final List<ChunkInfo> chunks) throws OzoneChecksumException { | ||
|
|
||
| long firstChunkOffset = blockOffset - chunks.get(startIndex).getOffset(); | ||
| int bytesPerChecksum = chunks.get(startIndex).getChecksumData().getBytesPerChecksum(); | ||
| long readLength = data.remaining(); | ||
| int dataOffset = data.position(); | ||
|
|
||
| if (readLength <= 0) { | ||
| if (!data.hasRemaining()) { | ||
| return; | ||
| } | ||
|
|
||
| assertSame(0, firstChunkOffset % bytesPerChecksum, "blockOffset % bytesPerChecksum"); | ||
| ContainerProtos.ChunkInfo firstChunk = chunks.get(startIndex); | ||
|
|
||
| // verify first chunk, only the first chunk is not start at zero. | ||
| int firstChunkIndex = (int) (firstChunkOffset / bytesPerChecksum); | ||
| int dataLimit = (int) Math.min(firstChunk.getLen() - firstChunkOffset, readLength); | ||
| Checksum.verifySingleChunk(data, dataOffset, dataLimit, firstChunk, firstChunkIndex); | ||
| dataOffset += dataLimit; | ||
| readLength -= dataLimit; | ||
| startIndex++; | ||
|
|
||
| while (readLength > 0) { | ||
| ContainerProtos.ChunkInfo chunkInfo = chunks.get(startIndex); | ||
| dataLimit = (int) Math.min(chunkInfo.getLen(), readLength); | ||
|
|
||
| Checksum.verifySingleChunk(data, dataOffset, dataLimit, chunkInfo, 0); | ||
|
|
||
| dataOffset += dataLimit; | ||
| readLength -= dataLimit; | ||
| startIndex++; | ||
| int dataOffset = data.position(); | ||
| int remaining = data.remaining(); | ||
| long offset = blockOffset; | ||
| while (remaining > 0) { | ||
| if (startIndex >= chunks.size()) { | ||
| throw new OzoneChecksumException("Missing chunk metadata at offset " + offset); | ||
| } | ||
| ChunkInfo chunk = chunks.get(startIndex++); | ||
| long chunkOffset = chunk.getOffset(); | ||
| long length = chunk.getLen(); | ||
| if (offset < chunkOffset || offset - chunkOffset >= length | ||
| || (offset != blockOffset && offset != chunkOffset)) { | ||
| throw new OzoneChecksumException("Invalid chunk coverage at offset " + offset); | ||
| } | ||
| long relativeOffset = offset - chunkOffset; | ||
| int size = (int) Math.min(remaining, length - relativeOffset); | ||
| if (chunk.getChecksumData().getType() != ChecksumType.NONE) { | ||
| int bytesPerChecksum = chunk.getChecksumData().getBytesPerChecksum(); | ||
| if (bytesPerChecksum <= 0 || relativeOffset % bytesPerChecksum != 0 | ||
| || (relativeOffset + size != length && (relativeOffset + size) % bytesPerChecksum != 0)) { | ||
| throw new OzoneChecksumException("Invalid checksum boundary at offset " + offset); | ||
| } | ||
| verifySingleChunk(data, dataOffset, size, chunk, (int) (relativeOffset / bytesPerChecksum)); | ||
| } | ||
| dataOffset += size; | ||
| offset += size; | ||
| remaining -= size; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| private static void verifySingleChunk(ByteBuffer data, int dataOffset, int dataLimit, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.