chungen0126 commented on code in PR #6613:
URL: https://github.com/apache/ozone/pull/6613#discussion_r1867497656
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java:
##########
@@ -1345,6 +1349,114 @@ public void deleteUnreferenced(Container container,
long localID)
}
}
+ @Override
+ public ContainerCommandResponseProto streamDataReadOnly(
+ ContainerCommandRequestProto request, KeyValueContainer kvContainer,
+ DispatcherContext dispatcherContext,
+ StreamObserver<ContainerCommandResponseProto> streamObserver) {
+ ContainerCommandResponseProto responseProto = null;
+ try {
+ if (!request.hasReadBlock()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Malformed Read Block request. trace ID: {}",
+ request.getTraceID());
+ }
+ return malformedRequest(request);
+ }
+ ReadBlockRequestProto readBlock = request.getReadBlock();
+
+ BlockID blockID = BlockID.getFromProtobuf(
+ readBlock.getBlockID());
+ // This is a new api the block should always be checked.
+ BlockUtils.verifyReplicaIdx(kvContainer, blockID);
+ BlockUtils.verifyBCSId(kvContainer, blockID);
+
+ BlockData blockData = getBlockManager().getBlock(kvContainer, blockID);
+ List<ContainerProtos.ChunkInfo> chunkInfos = blockData.getChunks();
+ long blockOffset = 0;
+ int chunkIndex = -1;
+ long chunkOffset = 0;
+ long offset = readBlock.getOffset();
+ for (int i = 0; i < chunkInfos.size(); i++) {
+ final long chunkLen = chunkInfos.get(i).getLen();
+ blockOffset += chunkLen;
+ if (blockOffset > offset) {
+ chunkIndex = i;
+ chunkOffset = offset - blockOffset + chunkLen;
+ break;
+ }
+ }
+ Preconditions.checkState(chunkIndex >= 0);
+
+ if (dispatcherContext == null) {
+ dispatcherContext = DispatcherContext.getHandleReadBlock();
+ }
+
+ ChunkBuffer data;
+
+ long len = readBlock.getLen();
+ long adjustedChunkOffset, adjustedChunkLen;
+ do {
+ ContainerProtos.ChunkInfo chunk = chunkInfos.get(chunkIndex);
+ if (readBlock.getVerifyChecksum()) {
Review Comment:
> Why not do this check and adjust on client side?
If we want to adjust the offset and length on client side, we need to get
block info before reading block. In the original implementation, we get block
info first and then read chunks, but now we're going to read block data
directly.
--
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]