merlimat closed pull request #1321: Avoid contention on netty channel promise URL: https://github.com/apache/bookkeeper/pull/1321
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java index 20fcdda09..b125d9721 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java @@ -42,6 +42,7 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; +import io.netty.channel.ChannelPromise; import io.netty.channel.DefaultEventLoopGroup; import io.netty.channel.EventLoopGroup; import io.netty.channel.WriteBufferWaterMark; @@ -877,21 +878,20 @@ private void writeAndFlush(final Channel channel, try { final long startTime = MathUtils.nowInNano(); - ChannelFuture future = channel.writeAndFlush(request); - future.addListener(future1 -> { - if (future1.isSuccess()) { - nettyOpLogger.registerSuccessfulEvent(MathUtils.elapsedNanos(startTime), - TimeUnit.NANOSECONDS); + + ChannelPromise promise = channel.newPromise().addListener(future -> { + if (future.isSuccess()) { + nettyOpLogger.registerSuccessfulEvent(MathUtils.elapsedNanos(startTime), TimeUnit.NANOSECONDS); CompletionValue completion = completionObjects.get(key); if (completion != null) { completion.setOutstanding(); } - } else { - nettyOpLogger.registerFailedEvent(MathUtils.elapsedNanos(startTime), - TimeUnit.NANOSECONDS); + nettyOpLogger.registerFailedEvent(MathUtils.elapsedNanos(startTime), TimeUnit.NANOSECONDS); } }); + + channel.writeAndFlush(request, promise); } catch (Throwable e) { LOG.warn("Operation {} failed", requestToString(request), e); errorOut(key); ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services