You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by eo...@apache.org on 2021/04/01 12:46:49 UTC
[pulsar] branch master updated: Avoid spammy logs in case of BK
problems (#10088)
This is an automated email from the ASF dual-hosted git repository.
eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new cdba1c0 Avoid spammy logs in case of BK problems (#10088)
cdba1c0 is described below
commit cdba1c03efff2b908850b54456a1843649fb98fb
Author: Enrico Olivelli <eo...@gmail.com>
AuthorDate: Thu Apr 1 14:46:19 2021 +0200
Avoid spammy logs in case of BK problems (#10088)
---
.../apache/pulsar/broker/service/ServerCnx.java | 4 +++-
.../apache/pulsar/functions/utils/Exceptions.java | 12 ++++++++++
.../pulsar/functions/utils/ExceptionsTest.java | 27 ++++++++++++++++++++++
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
index a2fe4a0..cd896bd 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
@@ -132,6 +132,7 @@ import org.apache.pulsar.common.protocol.schema.SchemaVersion;
import org.apache.pulsar.common.schema.SchemaType;
import org.apache.pulsar.common.util.FutureUtil;
import org.apache.pulsar.common.util.collections.ConcurrentLongHashMap;
+import org.apache.pulsar.functions.utils.Exceptions;
import org.apache.pulsar.transaction.coordinator.TransactionCoordinatorID;
import org.apache.pulsar.transaction.coordinator.impl.MLTransactionMetadataStore;
import org.slf4j.Logger;
@@ -1245,7 +1246,8 @@ public class ServerCnx extends PulsarHandler implements TransportCnx {
cause = new TopicNotFoundException("Topic Not Found.");
}
- if (!(cause instanceof ServiceUnitNotReadyException)) {
+ if (!Exceptions.areExceptionsPresentInChain(cause,
+ ServiceUnitNotReadyException.class, ManagedLedgerException.class)) {
// Do not print stack traces for expected exceptions
log.error("[{}] Failed to create topic {}, producerId={}",
remoteAddress, topicName, producerId, exception);
diff --git a/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/Exceptions.java b/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/Exceptions.java
index 19b31c6..c1e804c 100644
--- a/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/Exceptions.java
+++ b/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/Exceptions.java
@@ -48,4 +48,16 @@ public class Exceptions {
return sw.toString();
}
+ public static boolean areExceptionsPresentInChain(Throwable error, Class ... types) {
+ while (error != null) {
+ for (Class type : types) {
+ if (type.isInstance(error)) {
+ return true;
+ }
+ }
+ error = error.getCause();
+ }
+ return false;
+ }
+
}
diff --git a/pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/ExceptionsTest.java b/pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/ExceptionsTest.java
index 67e1406..f08c143 100644
--- a/pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/ExceptionsTest.java
+++ b/pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/ExceptionsTest.java
@@ -21,7 +21,9 @@ package org.apache.pulsar.functions.utils;
import static org.apache.pulsar.functions.utils.Exceptions.rethrowIOException;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.io.IOException;
@@ -77,4 +79,29 @@ public class ExceptionsTest {
}
}
+ @Test
+ public void testAreExceptionsPresentInChain() {
+ assertFalse(Exceptions.areExceptionsPresentInChain(null, IllegalStateException.class));
+ }
+
+ @Test
+ public void testAreExceptionsPresentInChain2() {
+ assertTrue(Exceptions.areExceptionsPresentInChain(new IllegalStateException(), IllegalStateException.class));
+ }
+
+ @Test
+ public void testAreExceptionsPresentInChain3() {
+ assertTrue(Exceptions.areExceptionsPresentInChain(new IllegalArgumentException(new IllegalStateException()), IllegalStateException.class));
+ }
+
+ @Test
+ public void testAreExceptionsPresentInChain4() {
+ assertTrue(Exceptions.areExceptionsPresentInChain(new IllegalArgumentException(new IllegalStateException()), UnsupportedOperationException.class, IllegalStateException.class));
+ }
+
+ @Test
+ public void testAreExceptionsPresentInChain5() {
+ assertFalse(Exceptions.areExceptionsPresentInChain(new IllegalArgumentException(new IllegalArgumentException()), IllegalStateException.class));
+ }
+
}