[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:
@ -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) {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user