amaliujia commented on code in PR #12035:
URL: https://github.com/apache/ozone/pull/12035#discussion_r4560201100


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/ContainerStateMachine.java:
##########
@@ -732,11 +734,30 @@ private StateMachine.DataChannel getStreamDataChannel(
     }
     dispatchCommand(requestProto, context);  // stream init
     final CheckedConsumer<ContainerCommandRequestProto, IOException> putBlock
-        = requestProto.getCmdType() == Type.StreamInitWithPutBlock ? 
this::streamPutBlock : null;
+        = requestProto.getCmdType() == Type.StreamInitWithPutBlock ? r -> 
streamPutBlock(requestProto, r) : null;
     return dispatcher.getStreamDataChannel(requestProto, putBlock);
   }
 
-  void streamPutBlock(ContainerCommandRequestProto request) throws IOException 
{
+  /** A PutBlock sent on a data stream must be a PutBlock for the block the 
stream was opened for. */
+  private static void checkStreamPutBlock(ContainerCommandRequestProto 
streamInit,
+      ContainerCommandRequestProto request) throws StorageContainerException {
+    if (request.getCmdType() != Type.PutBlock) {
+      throw new StorageContainerException("Unexpected stream PutBlock request 
type " + request.getCmdType()
+          + ", expected " + Type.PutBlock, 
ContainerProtos.Result.MALFORMED_REQUEST);
+    }
+    final ContainerBlockID streamBlock = 
BlockID.getFromProtobuf(streamInit.getWriteChunk().getBlockID())
+        .getContainerBlockID();
+    final ContainerBlockID block = 
BlockID.getFromProtobuf(request.getPutBlock().getBlockData().getBlockID())
+        .getContainerBlockID();

Review Comment:
   Good idea!



-- 
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]

Reply via email to