HADOOP-8711. IPC Server supports adding exceptions for which the message is printed and the stack trace is not printed to avoid chatter. Contributed by Brandon Li.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1375790 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ca2dc3e785
commit
e8477759ac
@ -91,6 +91,10 @@ Trunk (unreleased changes)
|
|||||||
HADOOP-8624. ProtobufRpcEngine should log all RPCs if TRACE logging is
|
HADOOP-8624. ProtobufRpcEngine should log all RPCs if TRACE logging is
|
||||||
enabled (todd)
|
enabled (todd)
|
||||||
|
|
||||||
|
HADOOP-8711. IPC Server supports adding exceptions for which
|
||||||
|
the message is printed and the stack trace is not printed to avoid chatter.
|
||||||
|
(Brandon Li via Suresh)
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
||||||
HADOOP-8177. MBeans shouldn't try to register when it fails to create MBeanName.
|
HADOOP-8177. MBeans shouldn't try to register when it fails to create MBeanName.
|
||||||
|
@ -46,11 +46,13 @@
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
@ -108,6 +110,42 @@
|
|||||||
public abstract class Server {
|
public abstract class Server {
|
||||||
private final boolean authorize;
|
private final boolean authorize;
|
||||||
private boolean isSecurityEnabled;
|
private boolean isSecurityEnabled;
|
||||||
|
private ExceptionsHandler exceptionsHandler = new ExceptionsHandler();
|
||||||
|
|
||||||
|
public void addTerseExceptions(Class<?>... exceptionClass) {
|
||||||
|
exceptionsHandler.addTerseExceptions(exceptionClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ExceptionsHandler manages Exception groups for special handling
|
||||||
|
* e.g., terse exception group for concise logging messages
|
||||||
|
*/
|
||||||
|
static class ExceptionsHandler {
|
||||||
|
private volatile Set<String> terseExceptions = new HashSet<String>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add exception class so server won't log its stack trace.
|
||||||
|
* Modifying the terseException through this method is thread safe.
|
||||||
|
*
|
||||||
|
* @param exceptionClass exception classes
|
||||||
|
*/
|
||||||
|
void addTerseExceptions(Class<?>... exceptionClass) {
|
||||||
|
|
||||||
|
// Make a copy of terseException for performing modification
|
||||||
|
final HashSet<String> newSet = new HashSet<String>(terseExceptions);
|
||||||
|
|
||||||
|
// Add all class names into the HashSet
|
||||||
|
for (Class<?> name : exceptionClass) {
|
||||||
|
newSet.add(name.toString());
|
||||||
|
}
|
||||||
|
// Replace terseException set
|
||||||
|
terseExceptions = Collections.unmodifiableSet(newSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isTerse(Class<?> t) {
|
||||||
|
return terseExceptions.contains(t.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The first four bytes of Hadoop RPC connections
|
* The first four bytes of Hadoop RPC connections
|
||||||
@ -1704,7 +1742,7 @@ public Writable run() throws Exception {
|
|||||||
// on the server side, as opposed to just a normal exceptional
|
// on the server side, as opposed to just a normal exceptional
|
||||||
// result.
|
// result.
|
||||||
LOG.warn(logMsg, e);
|
LOG.warn(logMsg, e);
|
||||||
} else if (e instanceof StandbyException) {
|
} else if (exceptionsHandler.isTerse(e.getClass())) {
|
||||||
// Don't log the whole stack trace of these exceptions.
|
// Don't log the whole stack trace of these exceptions.
|
||||||
// Way too noisy!
|
// Way too noisy!
|
||||||
LOG.info(logMsg);
|
LOG.info(logMsg);
|
||||||
@ -1844,6 +1882,8 @@ protected Server(String bindAddress, int port,
|
|||||||
if (isSecurityEnabled) {
|
if (isSecurityEnabled) {
|
||||||
SaslRpcServer.init(conf);
|
SaslRpcServer.init(conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.exceptionsHandler.addTerseExceptions(StandbyException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void closeConnection(Connection connection) {
|
private void closeConnection(Connection connection) {
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.BindException;
|
import java.net.BindException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
@ -115,4 +116,16 @@ public void testBindError() throws Exception {
|
|||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExceptionsHandler() throws IOException {
|
||||||
|
Server.ExceptionsHandler handler = new Server.ExceptionsHandler();
|
||||||
|
handler.addTerseExceptions(IOException.class);
|
||||||
|
handler.addTerseExceptions(RpcServerException.class, IpcException.class);
|
||||||
|
|
||||||
|
assertTrue(handler.isTerse(IOException.class));
|
||||||
|
assertTrue(handler.isTerse(RpcServerException.class));
|
||||||
|
assertTrue(handler.isTerse(IpcException.class));
|
||||||
|
assertFalse(handler.isTerse(RpcClientException.class));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user