[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.
This commit is contained in:
Yingchun Lai
2021-02-06 23:14:26 +08:00
committed by GitHub
parent a6e2c3e3f1
commit 4ce6f49c0f
3 changed files with 20 additions and 12 deletions

View File

@ -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) {

View File

@ -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;
}

View File

@ -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