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 2022/09/13 06:29:31 UTC
[pulsar] branch branch-2.10 updated: Issue 17588: Allow deletion of a namespace that was left in deleted status
This is an automated email from the ASF dual-hosted git repository.
eolivelli pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.10 by this push:
new 62c8b60a61d Issue 17588: Allow deletion of a namespace that was left in deleted status
62c8b60a61d is described below
commit 62c8b60a61d6b072d90197703d1f24d7375d19ba
Author: Enrico Olivelli <eo...@apache.org>
AuthorDate: Mon Sep 12 15:20:29 2022 +0200
Issue 17588: Allow deletion of a namespace that was left in deleted status
---
.../org/apache/pulsar/broker/namespace/NamespaceService.java | 2 +-
.../java/org/apache/pulsar/broker/web/PulsarWebResource.java | 7 ++++++-
.../java/org/apache/pulsar/broker/admin/NamespacesTest.java | 12 ++++++++++++
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java
index cf7ac381d43..dbe41b42c8a 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java
@@ -1219,7 +1219,7 @@ public class NamespaceService implements AutoCloseable {
public CompletableFuture<List<String>> getListOfNonPersistentTopics(NamespaceName namespaceName) {
- return PulsarWebResource.checkLocalOrGetPeerReplicationCluster(pulsar, namespaceName)
+ return PulsarWebResource.checkLocalOrGetPeerReplicationCluster(pulsar, namespaceName, true)
.thenCompose(peerClusterData -> {
// if peer-cluster-data is present it means namespace is owned by that peer-cluster and request
// should be redirect to the peer-cluster
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
index fca5b47703e..7cc019f2e25 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
@@ -803,6 +803,11 @@ public abstract class PulsarWebResource {
public static CompletableFuture<ClusterDataImpl> checkLocalOrGetPeerReplicationCluster(PulsarService pulsarService,
NamespaceName namespace) {
+ return checkLocalOrGetPeerReplicationCluster(pulsarService, namespace, false);
+ }
+ public static CompletableFuture<ClusterDataImpl> checkLocalOrGetPeerReplicationCluster(PulsarService pulsarService,
+ NamespaceName namespace,
+ boolean allowDeletedNamespace) {
if (!namespace.isGlobal()) {
return CompletableFuture.completedFuture(null);
}
@@ -818,7 +823,7 @@ public abstract class PulsarWebResource {
.getPoliciesAsync(namespace).thenAccept(policiesResult -> {
if (policiesResult.isPresent()) {
Policies policies = policiesResult.get();
- if (policies.deleted) {
+ if (!allowDeletedNamespace && policies.deleted) {
String msg = String.format("Namespace %s is deleted", namespace.toString());
log.warn(msg);
validationFuture.completeExceptionally(new RestException(Status.PRECONDITION_FAILED,
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java
index b754a592ba0..50a9a1d554d 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java
@@ -1172,6 +1172,18 @@ public class NamespacesTest extends MockedPulsarServiceBaseTest {
topicList = admin.topics().getList(namespace);
assertTrue(topicList.isEmpty());
+ // simulate a partially deleted namespace, we should be able to recover
+ pulsar.getPulsarResources().getNamespaceResources()
+ .setPolicies(NamespaceName.get(namespace), old -> {
+ old.deleted = true;
+ return old;
+ });
+ admin.namespaces().deleteNamespace(namespace, true);
+
+ admin.namespaces().createNamespace(namespace, 100);
+ topicList = admin.topics().getList(namespace);
+ assertTrue(topicList.isEmpty());
+
// reset back to false
pulsar.getConfiguration().setForceDeleteNamespaceAllowed(false);
}