You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/06/23 09:09:35 UTC

[GitHub] [ozone] szetszwo commented on a change in pull request #2358: HDDS-5366. [Ozone-Streaming] Implement stream method to ContainerStateMachine.

szetszwo commented on a change in pull request #2358:
URL: https://github.com/apache/ozone/pull/2358#discussion_r656905202



##########
File path: hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/ContainerStateMachine.java
##########
@@ -501,6 +503,30 @@ private ExecutorService getCommandExecutor(
     return raftFuture;
   }
 
+  @Override
+  public CompletableFuture<DataStream> stream(RaftClientRequest request) {
+    try {
+      ContainerCommandRequestProto requestProto =
+          getContainerCommandRequestProto(gid,
+              request.getMessage().getContent());
+      DispatcherContext context =
+          new DispatcherContext.Builder()
+              .setStage(DispatcherContext.WriteChunkStage.WRITE_DATA)
+              .setContainer2BCSIDMap(container2BCSIDMap)
+              .build();
+
+      ContainerCommandResponseProto response = runCommand(
+          requestProto, context);
+      String path = response.getMessage();
+      CompletableFuture<DataStream> dataStream = new CompletableFuture<>();
+      dataStream.complete(new LocalStream(new StreamDataChannel(
+          Paths.get(path))));
+      return dataStream;
+    } catch (IOException e) {
+      throw new CompletionException("Failed to create data stream", e);
+    }

Review comment:
       We should make it async like below:
   ```
     public CompletableFuture<DataStream> stream(RaftClientRequest request) {
       return CompletableFuture.supplyAsync(() -> {
         try {
           ContainerCommandRequestProto requestProto =
               getContainerCommandRequestProto(gid,
                   request.getMessage().getContent());
           DispatcherContext context =
               new DispatcherContext.Builder()
                   .setStage(DispatcherContext.WriteChunkStage.WRITE_DATA)
                   .setContainer2BCSIDMap(container2BCSIDMap)
                   .build();
   
           ContainerCommandResponseProto response = runCommand(
               requestProto, context);
           String path = response.getMessage();
           return new LocalStream(new StreamDataChannel(Paths.get(path))));
         } catch (IOException e) {
           throw new CompletionException("Failed to create data stream", e);
         }
       }, executor);
     }
   ```




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org