szetszwo commented on code in PR #5621:
URL: https://github.com/apache/ozone/pull/5621#discussion_r1404656414


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/GrpcXceiverService.java:
##########
@@ -39,9 +45,58 @@ public class GrpcXceiverService extends
       LOG = LoggerFactory.getLogger(GrpcXceiverService.class);
 
   private final ContainerDispatcher dispatcher;
+  private final boolean zeroCopyEnabled;
+  private final ZeroCopyMessageMarshaller<ContainerCommandRequestProto>
+      zeroCopyMessageMarshaller = new ZeroCopyMessageMarshaller<>(
+          ContainerCommandRequestProto.getDefaultInstance());
 
-  public GrpcXceiverService(ContainerDispatcher dispatcher) {
+  public GrpcXceiverService(ContainerDispatcher dispatcher,
+      boolean zeroCopyEnabled) {
     this.dispatcher = dispatcher;
+    this.zeroCopyEnabled = zeroCopyEnabled;
+  }
+
+  /**
+   * Bind service with zerocopy marshaller equiped for the `send` API if
+   * zerocopy is enabled.
+   * @return  service definition.
+   */
+  public ServerServiceDefinition bindServiceWithZerocopy() {
+    ServerServiceDefinition orig = super.bindService();
+    if (!zeroCopyEnabled) {
+      LOG.info("Zerocopy is not enabled.");
+      return orig;
+    }
+
+    ServerServiceDefinition.Builder builder =
+        ServerServiceDefinition.builder(orig.getServiceDescriptor().getName());
+    // Add `send` method with zerocopy marshaller.
+    addZeroCopyMethod(orig, builder, getSendMethod(),
+        zeroCopyMessageMarshaller);
+    // Add other methods as is.
+    orig.getMethods().stream().filter(
+        x -> !x.getMethodDescriptor().getFullMethodName().equals(
+            getSendMethod().getFullMethodName())
+    ).forEach(
+        builder::addMethod
+    );
+
+    return builder.build();
+  }
+
+  @SuppressWarnings("unchecked")

Review Comment:
   Move the tag to right above `ServerCallHandler<Req, Resp> 
serverCallHandler`, i.e.
   ```java
       @SuppressWarnings("unchecked")
       ServerCallHandler<Req, Resp> serverCallHandler =
           (ServerCallHandler<Req, Resp>) orig.getMethod(
               newMethod.getFullMethodName()).getServerCallHandler();
   ```



##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/GrpcXceiverService.java:
##########
@@ -52,6 +107,7 @@ public StreamObserver<ContainerCommandRequestProto> send(
 
       @Override
       public void onNext(ContainerCommandRequestProto request) {
+        InputStream popStream = zeroCopyMessageMarshaller.popStream(request);

Review Comment:
   Move `popStream` inside finally.  BTW, the `popStream(..)` method is going 
to be replaced by a new `release(..)` method; see 
https://github.com/apache/ratis/pull/971/files



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