amaliujia commented on a change in pull request #213:
URL: https://github.com/apache/incubator-ratis/pull/213#discussion_r501249518
##########
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:
I am little confused here: this is an implementation that forwards
messages to peers from a server, and then wait the `writes` on peers to finish,
then replies to complete the current write (also a future for client, thus
reply will complete that client's future).
How is it related to read?
----------------------------------------------------------------
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]