Technoboy- commented on a change in pull request #14215:
URL: https://github.com/apache/pulsar/pull/14215#discussion_r804306626
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
##########
@@ -263,52 +263,51 @@ protected void internalDeleteNamespace(AsyncResponse
asyncResponse, boolean auth
// remove from owned namespace map and ephemeral node from ZK
final List<CompletableFuture<Void>> futures = Lists.newArrayList();
- try {
- // remove system topics first.
- if (!topics.isEmpty()) {
- for (String topic : topics) {
-
pulsar().getBrokerService().getTopicIfExists(topic).whenComplete((topicOptional,
ex) -> {
- topicOptional.ifPresent(systemTopic ->
futures.add(systemTopic.deleteForcefully()));
- });
- }
- }
- NamespaceBundles bundles =
pulsar().getNamespaceService().getNamespaceBundleFactory()
- .getBundles(namespaceName);
- for (NamespaceBundle bundle : bundles.getBundles()) {
- // check if the bundle is owned by any broker, if not then we
do not need to delete the bundle
- if
(pulsar().getNamespaceService().getOwner(bundle).isPresent()) {
- futures.add(pulsar().getAdminClient().namespaces()
-
.deleteNamespaceBundleAsync(namespaceName.toString(), bundle.getBundleRange()));
+ // remove system topics first.
+ if (!topics.isEmpty()) {
+ for (String topic : topics) {
+ try {
+
futures.add(pulsar().getAdminClient().topics().deleteAsync(topic, true, true));
+ } catch (Exception ex) {
+ log.error("[{}] Failed to delete system topic {}",
clientAppId(), topic, ex);
+ asyncResponse.resume(new
RestException(Status.INTERNAL_SERVER_ERROR, ex));
+ return;
}
}
- } catch (Exception e) {
- log.error("[{}] Failed to remove owned namespace {}",
clientAppId(), namespaceName, e);
- asyncResponse.resume(new RestException(e));
- return;
}
-
- FutureUtil.waitForAll(futures).handle((result, exception) -> {
- if (exception != null) {
- if (exception.getCause() instanceof PulsarAdminException) {
- asyncResponse.resume(new
RestException((PulsarAdminException) exception.getCause()));
- return null;
- } else {
- log.error("[{}] Failed to remove owned namespace {}",
clientAppId(), namespaceName, exception);
- asyncResponse.resume(new
RestException(exception.getCause()));
- return null;
+ FutureUtil.waitForAll(futures).thenApply(__ -> {
+ futures.clear();
+ try {
+ NamespaceBundles bundles =
pulsar().getNamespaceService().getNamespaceBundleFactory()
+ .getBundles(namespaceName);
+ for (NamespaceBundle bundle : bundles.getBundles()) {
+ // check if the bundle is owned by any broker, if not then
we do not need to delete the bundle
+ if
(pulsar().getNamespaceService().getOwner(bundle).isPresent()) {
+ futures.add(pulsar().getAdminClient().namespaces()
+
.deleteNamespaceBundleAsync(namespaceName.toString(), bundle.getBundleRange()));
+ }
}
+ return futures;
+ } catch (Exception e) {
+ throw new RestException(e);
}
-
- internalClearZkSources(asyncResponse);
-
+ })
+ .thenCompose(__ -> internalClearZkSources())
+ .thenAccept(__ -> {
+ log.info("[{}] Remove namespace successfully {}", clientAppId(),
namespaceName);
+ asyncResponse.resume(Response.noContent().build());
+ })
+ .exceptionally(ex -> {
+ log.error("[{}] Failed to remove namespace {}", clientAppId(),
namespaceName, ex.getCause());
Review comment:
Yes, this is ok here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]