amaliujia commented on a change in pull request #213:
URL: https://github.com/apache/incubator-ratis/pull/213#discussion_r499123983



##########
File path: 
ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyServerStreamRpc.java
##########
@@ -51,27 +57,52 @@
   private RandomAccessFile stream;
   private FileChannel fileChannel;
   private File file = new File("client-data-stream");
+  private List<DataStreamClientImpl> clients = new ArrayList<>();
+  private List<DataStreamOutput> streams = new ArrayList<>();
 
 
   public NettyServerStreamRpc(RaftPeer server){
     this.raftServer = server;
     setupServer();
   }
 
+  public NettyServerStreamRpc(
+      RaftPeer server, List<RaftPeer> otherPeers, RaftProperties properties){
+    this.raftServer = server;
+    setupServer();
+    setupClient(otherPeers, properties);
+  }
+
   private ChannelInboundHandler getServerHandler(){
     return new ChannelInboundHandlerAdapter(){
       @Override
       public void channelRead(ChannelHandlerContext ctx, Object msg) throws 
Exception {
         final DataStreamRequestByteBuf req = (DataStreamRequestByteBuf)msg;
+
+        List<CompletableFuture<DataStreamReply>> futures = new ArrayList<>();
+        // forward requests to other stream servers.
+        for (DataStreamOutput streamOutput : streams) {
+          CompletableFuture<DataStreamReply> future =
+              streamOutput.streamAsync(req.getBuf().nioBuffer());
+          futures.add(future);
+        }
+
         ByteBuffer[] bfs = req.getBuf().nioBuffers();
         for(int i = 0; i < bfs.length; i++){
           fileChannel.write(bfs[i]);
         }
-        req.getBuf().release();
-        final DataStreamReply reply = new 
DataStreamReplyByteBuffer(req.getStreamId(),
-                                                        req.getDataOffset(),
-                                                        
ByteBuffer.wrap("OK".getBytes()));
-        ctx.writeAndFlush(reply);
+
+        try {
+          for (CompletableFuture<DataStreamReply> future : futures) {
+              future.join();

Review comment:
       At this moment, I am not sure how this server should handle exceptions 
when forwarding message to peers:
   1. Will there any exception be thrown? I have this question because existing 
request handling code seems does not throw any exception already.
   2. If this server fails to forward a message to a peer, what is the proper 
way to respond to client? Note that the client is sending a stream of message. 
So is failures happen in the middle means the client should retry from the 
failure point?




----------------------------------------------------------------
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:
[email protected]


Reply via email to