Skip to content

Commit 99dc74b

Browse files
authored
[improve][broker] Do not print error logs for NotFound or Conflict errors when using the Admin API (apache#23928)
### Motivation Currently, when there is a 404 or 409 error in the Admin API call, the broker prints the error logs. ``` ERROR org.apache.pulsar.broker.admin.v2.PersistentTopics - [xxx] Failed to get partitioned metadata topic persistent://xxx: Namespace not found ``` ``` ERROR org.apache.pulsar.broker.admin.v2.Namespaces - Failed to get policies for namespace xxx: Namespace does not exist ``` ``` ERROR org.apache.pulsar.broker.admin.v2.PersistentTopics - [xxx] Failed to create non-partitioned topic persistent:/xxx: This topic already exists ``` ``` [pulsar-web-44-1] ERROR org.apache.pulsar.broker.admin.AdminResource - [admin] Failed to create partitioned topic persistent://xxx java.util.concurrent.CompletionException: org.apache.pulsar.broker.web.RestException: This topic already exists ``` These errors are related to the client side. The client can handle the error, so we don't need to print it in the broker log. ### Modifications - Print a warning log for NotFound or Conflict errors in the Admin API.
1 parent 8a40b30 commit 99dc74b

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,12 @@ && pulsar().getConfig().isCreateTopicToRemoteClusterForReplication()) {
624624
asyncResponse.resume(Response.noContent().build());
625625
})
626626
.exceptionally(ex -> {
627-
log.error("[{}] Failed to create partitioned topic {}", clientAppId(), topicName, ex);
627+
if (AdminResource.isConflictException(ex)) {
628+
log.info("[{}] Failed to create partitioned topic {}: {}", clientAppId(), topicName,
629+
ex.getMessage());
630+
} else {
631+
log.error("[{}] Failed to create partitioned topic {}", clientAppId(), topicName, ex);
632+
}
628633
resumeAsyncResponseExceptionally(asyncResponse, ex);
629634
return null;
630635
});
@@ -885,13 +890,24 @@ protected static boolean isRedirectException(Throwable ex) {
885890
== Status.TEMPORARY_REDIRECT.getStatusCode();
886891
}
887892

893+
protected static boolean isNotFoundOrConflictException(Throwable ex) {
894+
return isNotFoundException(ex) || isConflictException(ex);
895+
}
896+
888897
protected static boolean isNotFoundException(Throwable ex) {
889898
Throwable realCause = FutureUtil.unwrapCompletionException(ex);
890899
return realCause instanceof WebApplicationException
891900
&& ((WebApplicationException) realCause).getResponse().getStatus()
892901
== Status.NOT_FOUND.getStatusCode();
893902
}
894903

904+
protected static boolean isConflictException(Throwable ex) {
905+
Throwable realCause = FutureUtil.unwrapCompletionException(ex);
906+
return realCause instanceof WebApplicationException
907+
&& ((WebApplicationException) realCause).getResponse().getStatus()
908+
== Status.CONFLICT.getStatusCode();
909+
}
910+
895911
protected static boolean isNot307And404Exception(Throwable ex) {
896912
return !isRedirectException(ex) && !isNotFoundException(ex);
897913
}

pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Namespaces.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import javax.ws.rs.core.MediaType;
4848
import javax.ws.rs.core.Response;
4949
import javax.ws.rs.core.StreamingOutput;
50+
import org.apache.pulsar.broker.admin.AdminResource;
5051
import org.apache.pulsar.broker.admin.impl.NamespacesBase;
5152
import org.apache.pulsar.broker.admin.impl.OffloaderObjectsScannerUtils;
5253
import org.apache.pulsar.broker.web.RestException;
@@ -154,7 +155,11 @@ public void getPolicies(@Suspended AsyncResponse response,
154155
.thenCompose(__ -> getNamespacePoliciesAsync(namespaceName))
155156
.thenAccept(response::resume)
156157
.exceptionally(ex -> {
157-
log.error("Failed to get policies for namespace {}", namespaceName, ex);
158+
if (AdminResource.isNotFoundOrConflictException(ex)) {
159+
log.info("Failed to get policies for namespace {}: {}", namespaceName, ex.getMessage());
160+
} else {
161+
log.error("Failed to get policies for namespace {}", namespaceName, ex);
162+
}
158163
resumeAsyncResponseExceptionally(response, ex);
159164
return null;
160165
});

pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public void createNonPartitionedTopic(
346346
internalCreateNonPartitionedTopicAsync(authoritative, properties)
347347
.thenAccept(__ -> asyncResponse.resume(Response.noContent().build()))
348348
.exceptionally(ex -> {
349-
if (isNot307And404Exception(ex)) {
349+
if (isNot307And404Exception(ex) && !isConflictException(ex)) {
350350
log.error("[{}] Failed to create non-partitioned topic {}", clientAppId(), topicName, ex);
351351
}
352352
resumeAsyncResponseExceptionally(asyncResponse, ex);
@@ -946,7 +946,7 @@ public void getPartitionedMetadata(
946946
Throwable t = FutureUtil.unwrapCompletionException(ex);
947947
if (!isRedirectException(t)) {
948948
if (AdminResource.isNotFoundException(t)) {
949-
log.error("[{}] Failed to get partitioned metadata topic {}: {}",
949+
log.info("[{}] Failed to get partitioned metadata topic {}: {}",
950950
clientAppId(), topicName, ex.getMessage());
951951
} else {
952952
log.error("[{}] Failed to get partitioned metadata topic {}",

0 commit comments

Comments
 (0)