sijie closed pull request #1776: Reduce stack traces in logs for common cases URL: https://github.com/apache/bookkeeper/pull/1776
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/bookie/Journal.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java index 0db23c6345..25680925f9 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Journal.java @@ -513,7 +513,7 @@ public void run() { running = false; } catch (InterruptedException e) { Thread.currentThread().interrupt(); - LOG.error("ForceWrite thread interrupted", e); + LOG.info("ForceWrite thread interrupted"); // close is idempotent if (null != req) { req.shouldClose = true; @@ -1142,7 +1142,7 @@ public void run() { LOG.error("I/O exception in Journal thread!", ioe); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); - LOG.warn("Journal exits when shutting down", ie); + LOG.info("Journal exits when shutting down"); } finally { // There could be packets queued for forceWrite on this logFile // That is fine as this exception is going to anyway take down the 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 79e4de912b..071b8395bf 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 @@ -49,6 +49,7 @@ import io.netty.channel.epoll.EpollSocketChannel; import io.netty.channel.local.LocalChannel; import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.channel.unix.Errors.NativeIoException; import io.netty.handler.codec.CorruptedFrameException; import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.LengthFieldBasedFrameDecoder; @@ -62,6 +63,7 @@ import java.io.IOException; import java.net.SocketAddress; +import java.net.UnknownHostException; import java.security.cert.Certificate; import java.util.ArrayDeque; import java.util.ArrayList; @@ -1137,7 +1139,13 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E } if (cause instanceof IOException) { - LOG.warn("Exception caught on:{} cause:", ctx.channel(), cause); + if (cause instanceof NativeIoException) { + // Stack trace is not very interesting for native IO exceptio, the important part is in + // the exception message + LOG.warn("Exception caught on:{} cause: {}", ctx.channel(), cause.getMessage()); + } else { + LOG.warn("Exception caught on:{} cause:", ctx.channel(), cause); + } ctx.close(); return; } @@ -2254,8 +2262,17 @@ public void operationComplete(ChannelFuture future) throws Exception { closeChannel(future.channel()); return; // pendingOps should have been completed when other channel connected } else { - LOG.error("Could not connect to bookie: {}/{}, current state {} : ", - future.channel(), addr, state, future.cause()); + Throwable cause = future.cause(); + if (cause instanceof UnknownHostException || cause instanceof NativeIoException) { + // Don't log stack trace for common errors + LOG.warn("Could not connect to bookie: {}/{}, current state {} : {}", + future.channel(), addr, state, future.cause().getMessage()); + } else { + // Regular exceptions, include stack trace + LOG.error("Could not connect to bookie: {}/{}, current state {} : ", + future.channel(), addr, state, future.cause()); + } + rc = BKException.Code.BookieHandleNotAvailableException; closeChannel(future.channel()); channel = null; ---------------------------------------------------------------- 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