This is an automated email from the ASF dual-hosted git repository.

lhotari pushed a commit to branch branch-3.2
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit 5d4746578695f828e0901cb14fd1e83837fe4b1a
Author: 道君 <dao...@apache.org>
AuthorDate: Wed Apr 17 03:12:34 2024 +0800

    [improve][broker] Add topic name to emitted error messages. (#22506)
    
    (cherry picked from commit d5b36da9a2e0d4f17bea8e033180e494e93dc442)
---
 .../org/apache/pulsar/broker/service/AbstractTopic.java | 17 +++++++++--------
 .../org/apache/pulsar/broker/admin/AdminApi2Test.java   |  6 ++++--
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java
 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java
index 837f073b00d..39c3cbf13b2 100644
--- 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java
+++ 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java
@@ -855,7 +855,7 @@ public abstract class AbstractTopic implements Topic, 
TopicPolicyListener<TopicP
             }
 
         } catch (Exception e) {
-            log.error("Encountered unexpected error during exclusive producer 
creation", e);
+            log.error("[{}] Encountered unexpected error during exclusive 
producer creation", topic, e);
             return FutureUtil.failedFuture(new BrokerServiceException(e));
         } finally {
             lock.writeLock().unlock();
@@ -929,14 +929,14 @@ public abstract class AbstractTopic implements Topic, 
TopicPolicyListener<TopicP
     protected CompletableFuture<Void> internalAddProducer(Producer producer) {
         if (isProducersExceeded(producer)) {
             log.warn("[{}] Attempting to add producer to topic which reached 
max producers limit", topic);
-            return CompletableFuture.failedFuture(
-                    new BrokerServiceException.ProducerBusyException("Topic 
reached max producers limit"));
+            return CompletableFuture.failedFuture(new 
BrokerServiceException.ProducerBusyException(
+                    "Topic '" + topic + "' reached max producers limit"));
         }
 
         if (isSameAddressProducersExceeded(producer)) {
             log.warn("[{}] Attempting to add producer to topic which reached 
max same address producers limit", topic);
-            return CompletableFuture.failedFuture(
-                    new BrokerServiceException.ProducerBusyException("Topic 
reached max same address producers limit"));
+            return CompletableFuture.failedFuture(new 
BrokerServiceException.ProducerBusyException(
+                    "Topic '" + topic + "' reached max same address producers 
limit"));
         }
 
         if (log.isDebugEnabled()) {
@@ -971,7 +971,7 @@ public abstract class AbstractTopic implements Topic, 
TopicPolicyListener<TopicP
                     if (previousIsActive) {
                         return CompletableFuture.failedFuture(new 
BrokerServiceException.NamingException(
                                 "Producer with name '" + 
newProducer.getProducerName()
-                                        + "' is already connected to topic"));
+                                        + "' is already connected to topic '" 
+ topic + "'"));
                     } else {
                         // If the connection of the previous producer is not 
active, the method
                         // "cnx().checkConnectionLiveness()" will trigger the 
close for it and kick off the previous
@@ -984,7 +984,8 @@ public abstract class AbstractTopic implements Topic, 
TopicPolicyListener<TopicP
                 });
             }
             return CompletableFuture.failedFuture(new 
BrokerServiceException.NamingException(
-                    "Producer with name '" + newProducer.getProducerName() + 
"' is already connected to topic"));
+                    "Producer with name '" + newProducer.getProducerName() + 
"' is already connected to topic '"
+                            + topic + "'"));
         }
     }
 
@@ -1329,7 +1330,7 @@ public abstract class AbstractTopic implements Topic, 
TopicPolicyListener<TopicP
             return getMigratedClusterUrlAsync(pulsar, topic)
                     
.get(pulsar.getPulsarResources().getClusterResources().getOperationTimeoutSec(),
 TimeUnit.SECONDS);
         } catch (Exception e) {
-            log.warn("Failed to get migration cluster URL", e);
+            log.warn("[{}] Failed to get migration cluster URL", topic, e);
         }
         return Optional.empty();
     }
diff --git 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java
index 38993388704..a6849793137 100644
--- 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java
+++ 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApi2Test.java
@@ -2887,7 +2887,8 @@ public class AdminApi2Test extends 
MockedPulsarServiceBaseTest {
             Producer<byte[]> producer = 
pulsarClient.newProducer().topic(topic).create();
             fail("should fail");
         } catch (PulsarClientException e) {
-            assertTrue(e.getMessage().contains("Topic reached max producers 
limit"));
+            String expectMsg = "Topic '" + topic + "' reached max producers 
limit";
+            assertTrue(e.getMessage().contains(expectMsg));
         }
         //set the limit to 3
         admin.namespaces().setMaxProducersPerTopic(myNamespace, 3);
@@ -2901,7 +2902,8 @@ public class AdminApi2Test extends 
MockedPulsarServiceBaseTest {
             Producer<byte[]> producer1 = 
pulsarClient.newProducer().topic(topic).create();
             fail("should fail");
         } catch (PulsarClientException e) {
-            assertTrue(e.getMessage().contains("Topic reached max producers 
limit"));
+            String expectMsg = "Topic '" + topic + "' reached max producers 
limit";
+            assertTrue(e.getMessage().contains(expectMsg));
         }
 
         //clean up

Reply via email to