From 3ef924019d7f6b4750771eb40b1048fbdc8f59fa Mon Sep 17 00:00:00 2001 From: Kihwal Lee Date: Thu, 18 Apr 2013 20:54:07 +0000 Subject: [PATCH] svn merge -c 1375790 Merging from trunk to branch-2 to fix HADOOP-8711. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1469565 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 5 +++ .../java/org/apache/hadoop/ipc/Server.java | 44 ++++++++++++++++++- .../org/apache/hadoop/ipc/TestServer.java | 13 ++++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index c8a3b3087ff..d2364b99c3b 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -1180,6 +1180,11 @@ Release 0.23.7 - UNRELEASED HADOOP-9374. Add tokens from -tokenCacheFile into UGI (daryn) + 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) + + OPTIMIZATIONS HADOOP-8462. Native-code implementation of bzip2 codec. (Govind Kamat via diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java index ddaad723a8b..90476187353 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java @@ -48,11 +48,13 @@ import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.Set; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.LinkedBlockingQueue; @@ -113,6 +115,42 @@ public abstract class Server { private final boolean authorize; private EnumSet enabledAuthMethods; + 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 terseExceptions = new HashSet(); + + /** + * 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 newSet = new HashSet(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 @@ -1756,8 +1794,8 @@ public Writable run() throws Exception { // on the server side, as opposed to just a normal exceptional // result. LOG.warn(logMsg, e); - } else if (e instanceof StandbyException) { - // Don't log the whole stack trace of these exceptions. + } else if (exceptionsHandler.isTerse(e.getClass())) { + // Don't log the whole stack trace of these exceptions. // Way too noisy! LOG.info(logMsg); } else { @@ -1898,6 +1936,8 @@ protected Server(String bindAddress, int port, if (secretManager != null) { SaslRpcServer.init(conf); } + + this.exceptionsHandler.addTerseExceptions(StandbyException.class); } // get the security type from the conf. implicitly include token support diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestServer.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestServer.java index db0d2ccc15a..57785c10502 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestServer.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestServer.java @@ -20,6 +20,7 @@ import static org.junit.Assert.*; +import java.io.IOException; import java.net.BindException; import java.net.InetSocketAddress; import java.net.ServerSocket; @@ -115,4 +116,16 @@ public void testBindError() throws Exception { 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)); + } }