You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by aa...@apache.org on 2021/09/03 02:06:40 UTC
[hadoop] branch branch-3.2 updated: HADOOP-17874. ExceptionsHandler
to add terse/suppressed Exceptions in thread-safe manner (#3343)
This is an automated email from the ASF dual-hosted git repository.
aajisaka pushed a commit to branch branch-3.2
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/branch-3.2 by this push:
new 25fe54b HADOOP-17874. ExceptionsHandler to add terse/suppressed Exceptions in thread-safe manner (#3343)
25fe54b is described below
commit 25fe54b8902c360a4cd8e77b97b17fe7d3a4446e
Author: Viraj Jasani <vj...@apache.org>
AuthorDate: Fri Sep 3 06:55:33 2021 +0530
HADOOP-17874. ExceptionsHandler to add terse/suppressed Exceptions in thread-safe manner (#3343)
Signed-off-by: Akira Ajisaka <aa...@apache.org>
(cherry picked from commit 99a157fa4ad174c4ff979414af2edb67a98eb9fe)
---
.../main/java/org/apache/hadoop/ipc/Server.java | 38 ++++++++--------------
1 file changed, 14 insertions(+), 24 deletions(-)
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 5f4b957..9f9a485 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
@@ -67,6 +67,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.stream.Collectors;
import javax.security.sasl.Sasl;
import javax.security.sasl.SaslException;
@@ -180,8 +181,11 @@ public abstract class Server {
* e.g., terse exception group for concise logging messages
*/
static class ExceptionsHandler {
- private volatile Set<String> terseExceptions = new HashSet<>();
- private volatile Set<String> suppressedExceptions = new HashSet<>();
+
+ private final Set<String> terseExceptions =
+ ConcurrentHashMap.newKeySet();
+ private final Set<String> suppressedExceptions =
+ ConcurrentHashMap.newKeySet();
/**
* Add exception classes for which server won't log stack traces.
@@ -189,8 +193,10 @@ public abstract class Server {
* @param exceptionClass exception classes
*/
void addTerseLoggingExceptions(Class<?>... exceptionClass) {
- // Thread-safe replacement of terseExceptions.
- terseExceptions = addExceptions(terseExceptions, exceptionClass);
+ terseExceptions.addAll(Arrays
+ .stream(exceptionClass)
+ .map(Class::toString)
+ .collect(Collectors.toSet()));
}
/**
@@ -199,9 +205,10 @@ public abstract class Server {
* @param exceptionClass exception classes
*/
void addSuppressedLoggingExceptions(Class<?>... exceptionClass) {
- // Thread-safe replacement of suppressedExceptions.
- suppressedExceptions = addExceptions(
- suppressedExceptions, exceptionClass);
+ suppressedExceptions.addAll(Arrays
+ .stream(exceptionClass)
+ .map(Class::toString)
+ .collect(Collectors.toSet()));
}
boolean isTerseLog(Class<?> t) {
@@ -212,23 +219,6 @@ public abstract class Server {
return suppressedExceptions.contains(t.toString());
}
- /**
- * Return a new set containing all the exceptions in exceptionsSet
- * and exceptionClass.
- * @return
- */
- private static Set<String> addExceptions(
- final Set<String> exceptionsSet, Class<?>[] exceptionClass) {
- // Make a copy of the exceptionSet for performing modification
- final HashSet<String> newSet = new HashSet<>(exceptionsSet);
-
- // Add all class names into the HashSet
- for (Class<?> name : exceptionClass) {
- newSet.add(name.toString());
- }
-
- return Collections.unmodifiableSet(newSet);
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org