szetszwo commented on code in PR #977:
URL: https://github.com/apache/ratis/pull/977#discussion_r1413184180
##########
ratis-netty/src/main/java/org/apache/ratis/netty/client/NettyClientStreamRpc.java:
##########
@@ -242,29 +249,44 @@ public String toString() {
}
}
- class OutstandingRequests {
+ static class OutstandingRequests {
private int count;
private long bytes;
- synchronized boolean write(DataStreamRequest request) {
- count++;
- bytes += request.getDataLength();
- final List<WriteOption> options = request.getWriteOptionList();
- final boolean isClose = options.contains(StandardWriteOption.CLOSE);
- final boolean isFlush = options.contains(StandardWriteOption.FLUSH);
- final boolean flush = shouldFlush(isClose || isFlush,
flushRequestCountMin, flushRequestBytesMin);
- LOG.debug("Stream{} outstanding: count={}, bytes={}, options={}, flush?
{}",
- request.getStreamId(), count, bytes, options, flush);
- return flush;
+ private boolean shouldFlush(List<WriteOption> options, int countMin,
SizeInBytes bytesMin) {
+ if (options.contains(StandardWriteOption.CLOSE)) {
+ // flush in order to send the CLOSE option.
+ return true;
+ } else if (bytes == 0 && count == 0) {
+ // nothing to flush (when bytes == 0 && count > 0, client may have
written empty packets for including options)
+ return false;
+ } else {
+ return count >= countMin
+ || bytes >= bytesMin.getSize()
+ || options.contains(StandardWriteOption.FLUSH);
Review Comment:
Another case needs `FLUSH` is the remote streams -- they should auto-flush
all the requests in order to propagate them to the next nodes.
--
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]