From 4ce6f49c0f6df9326d207e4a80da6680fcdaae29 Mon Sep 17 00:00:00 2001 From: Yingchun Lai <405403881@qq.com> Date: Sat, 6 Feb 2021 23:14:26 +0800 Subject: [PATCH] [LOG] Reduce verbose exception log by catch exceptions (#5229) In our product environment, we use LVS to dispatch requests to FEs, however, LVS will send probes to check whether FE is alive, and will close the connection immediately. It will cause much verbose log, this patch aim to reduce these log by catch related exceptions. --- .../org/apache/doris/mysql/MysqlProto.java | 8 ++++++-- .../apache/doris/mysql/nio/NMysqlChannel.java | 20 +++++++++++-------- .../apache/doris/mysql/MysqlProtoTest.java | 4 ++-- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlProto.java b/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlProto.java index 18401cc2e8..7c6c1a4269 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlProto.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlProto.java @@ -138,8 +138,12 @@ public class MysqlProto { serializer.reset(); MysqlHandshakePacket handshakePacket = new MysqlHandshakePacket(context.getConnectionId()); handshakePacket.writeTo(serializer); - channel.sendAndFlush(serializer.toByteBuffer()); - + try { + channel.sendAndFlush(serializer.toByteBuffer()); + } catch (IOException e) { + LOG.warn("Send and flush channel exception, ignore. Exception: " + e.toString()); + return false; + } // Server receive authenticate packet from client. ByteBuffer handshakeResponse = channel.fetchOnePacket(); if (handshakeResponse == null) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/mysql/nio/NMysqlChannel.java b/fe/fe-core/src/main/java/org/apache/doris/mysql/nio/NMysqlChannel.java index 04af03dd89..799a00529a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mysql/nio/NMysqlChannel.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mysql/nio/NMysqlChannel.java @@ -54,18 +54,22 @@ public class NMysqlChannel extends MysqlChannel { * * @param dstBuf * @return - * @throws IOException */ @Override - protected int readAll(ByteBuffer dstBuf) throws IOException { + protected int readAll(ByteBuffer dstBuf) { int readLen = 0; - while (dstBuf.remaining() != 0) { - int ret = Channels.readBlocking(conn.getSourceChannel(), dstBuf); - // return -1 when remote peer close the channel - if (ret == -1) { - return readLen; + try { + while (dstBuf.remaining() != 0) { + int ret = Channels.readBlocking(conn.getSourceChannel(), dstBuf); + // return -1 when remote peer close the channel + if (ret == -1) { + return readLen; + } + readLen += ret; } - readLen += ret; + } catch (IOException e) { + LOG.warn("Read channel exception, ignore. Exception: " + e.toString()); + return 0; } return readLen; } diff --git a/fe/fe-core/src/test/java/org/apache/doris/mysql/MysqlProtoTest.java b/fe/fe-core/src/test/java/org/apache/doris/mysql/MysqlProtoTest.java index 4343dbbbf9..ebd1f966a9 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/mysql/MysqlProtoTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/mysql/MysqlProtoTest.java @@ -183,14 +183,14 @@ public class MysqlProtoTest { Assert.assertTrue(MysqlProto.negotiate(context)); } - @Test(expected = IOException.class) + @Test public void testNegotiateSendFail() throws Exception { mockChannel("user", false); mockPassword(true); mockAccess(); ConnectContext context = new ConnectContext(null); MysqlProto.negotiate(context); - Assert.fail("No Exception throws."); + Assert.assertFalse(MysqlProto.negotiate(context)); } @Test