szetszwo commented on code in PR #10764:
URL: https://github.com/apache/ozone/pull/10764#discussion_r3942301564
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java:
##########
@@ -2445,6 +2462,64 @@ static List<ByteString> getChecksums(long blockOffset,
int readLength, int bytes
return checksums;
}
+ /**
+ * We have to align the read to checksum boundaries, so whatever offset is
requested, we have to move back to the
+ * previous checksum boundary.
+ * eg if bytesPerChecksum is 512, and the requested offset is 600, we have
to move back to 512.
+ * Returns the checksum boundaries of {@code ChecksumBoundaries} relative to
blockOffset and blockLength.
+ */
+ private static ChecksumBoundaries getChecksumBoundaries(long blockOffset,
long blockLength,
+ List<ContainerProtos.ChunkInfo> chunkInfos, long bytesPerChecksum) {
+ final int offsetChunkIndex = searchChunkByOffset(blockOffset, chunkInfos);
+ final long offsetAlignment = (blockOffset -
chunkInfos.get(offsetChunkIndex).getOffset()) % bytesPerChecksum;
+ final long adjustedOffset = blockOffset - offsetAlignment;
+ final long blockEnd = blockOffset + blockLength - 1;
+ final ContainerProtos.ChunkInfo lastChunk =
chunkInfos.get(searchChunkByOffset(blockEnd, chunkInfos));
+
+ final long chunkOffset = lastChunk.getOffset();
+ final long chunkLength = Math.min(
+ (getEndChecksumIndex(blockEnd, chunkOffset, bytesPerChecksum) + 1) *
bytesPerChecksum, lastChunk.getLen());
+ return new ChecksumBoundaries(offsetChunkIndex, adjustedOffset,
+ chunkOffset + chunkLength - adjustedOffset);
+ }
+
+ private static int getEndChecksumIndex(long blockEnd, long chunkOffset, long
bytesPerChecksum) {
+ return (int) ((blockEnd - chunkOffset) / bytesPerChecksum);
+ }
+
+ private static final class ChecksumBoundaries {
Review Comment:
> Why use inclusive for blockEnd?
Let's keep it inclusive.
> Why Math.min instead of plain adjustEnd?
That's good point. Then, requiredLength is not needed anymore. We should
change it to an assertion.
> The bitwise operation (bufferLimit ... & -bytesPerChecksum):
This is clever! Let's add some comments explaining it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]