Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][broker] Improve naming for delete topic error #16965

Merged
merged 3 commits into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public void deleteTopic(
Throwable t = FutureUtil.unwrapCompletionException(ex);
if (!force && (t instanceof BrokerServiceException.TopicBusyException)) {
ex = new RestException(Response.Status.PRECONDITION_FAILED,
"Topic has active producers/subscriptions");
t.getMessage());
}
if (isManagedLedgerNotFoundException(t)) {
ex = new RestException(Response.Status.NOT_FOUND,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ public void deleteTopic(
Throwable t = FutureUtil.unwrapCompletionException(ex);
if (!force && (t instanceof BrokerServiceException.TopicBusyException)) {
ex = new RestException(Response.Status.PRECONDITION_FAILED,
"Topic has active producers/subscriptions");
t.getMessage());
}
if (isManagedLedgerNotFoundException(t)) {
ex = new RestException(Response.Status.NOT_FOUND,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,8 @@ private CompletableFuture<Void> delete(boolean failIfHasSubscriptions, boolean c
if (failIfHasSubscriptions) {
if (!subscriptions.isEmpty()) {
isFenced = false;
deleteFuture.completeExceptionally(new TopicBusyException("Topic has subscriptions"));
deleteFuture.completeExceptionally(
new TopicBusyException("Topic has subscriptions:" + subscriptions.keys()));
return;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1130,9 +1130,15 @@ private CompletableFuture<Void> delete(boolean failIfHasSubscriptions,
log.warn("[{}] Topic is already being closed or deleted", topic);
return FutureUtil.failedFuture(new TopicFencedException("Topic is already fenced"));
} else if (failIfHasSubscriptions && !subscriptions.isEmpty()) {
return FutureUtil.failedFuture(new TopicBusyException("Topic has subscriptions"));
return FutureUtil.failedFuture(
new TopicBusyException("Topic has subscriptions: " + subscriptions.keys()));
} else if (failIfHasBacklogs && hasBacklogs()) {
return FutureUtil.failedFuture(new TopicBusyException("Topic has subscriptions did not catch up"));
List<String> backlogSubs =
subscriptions.values().stream()
.filter(sub -> sub.getNumberOfEntriesInBacklog(false) > 0)
.map(PersistentSubscription::getName).toList();
return FutureUtil.failedFuture(
new TopicBusyException("Topic has subscriptions did not catch up: " + backlogSubs));
}

fenceTopicToCloseOrDelete(); // Avoid clients reconnections while deleting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ public void testDeleteTopicAndSchemaForV1() throws Exception {
} catch (Exception e) {
assertThat(e.getMessage())
.isNotNull()
.startsWith("Topic has active producers/subscriptions");
.startsWith("Topic has 2 connected producers/consumers");
}
assertEquals(this.getPulsar().getSchemaRegistryService()
.trimDeletedSchemaAndGetList(TopicName.get(topic1).getSchemaName()).get().size(), 2);
Expand Down Expand Up @@ -936,7 +936,7 @@ public void testDeleteTopicAndSchemaForV2() throws Exception {
admin.topics().delete(topicOne, false);
fail();
} catch (Exception e) {
assertTrue(e.getMessage().startsWith("Topic has active producers/subscriptions"));
assertTrue(e.getMessage().startsWith("Topic has 2 connected producers/consumers"));
}
assertEquals(this.getPulsar().getSchemaRegistryService()
.trimDeletedSchemaAndGetList(TopicName.get(topicOne).getSchemaName()).get().size(), 2);
Expand Down