Skip to content

Commit

Permalink
[improve][admin] Unset namespace policy to improve deleting namespace. (
Browse files Browse the repository at this point in the history
  • Loading branch information
Technoboy- authored Aug 14, 2022
1 parent d3dd143 commit 70020f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,12 @@ protected void internalDeleteNamespaceForcefully(AsyncResponse asyncResponse, bo
if (topicName.isPartitioned()) {
String partitionedTopic = topicName.getPartitionedTopicName();
if (!partitionedTopics.contains(partitionedTopic)) {
// Distinguish partitioned topic to avoid duplicate deletion of the same schema
topicFutures.add(pulsar().getAdminClient().topics().deletePartitionedTopicAsync(
partitionedTopic, true, true));
partitionedTopics.add(partitionedTopic);
}
} else {
topicFutures.add(pulsar().getAdminClient().topics().deleteAsync(
topic, true, true));
nonPartitionedTopics.add(topic);
}
topicFutures.add(pulsar().getAdminClient().topics().deleteAsync(topic, true));
} catch (Exception e) {
String errorMessage = String.format("Failed to force delete topic %s, "
+ "but the previous deletion command of partitioned-topics:%s "
Expand All @@ -500,6 +496,11 @@ protected void internalDeleteNamespaceForcefully(AsyncResponse asyncResponse, bo
}
}

for (String partitionedTopic : partitionedTopics) {
topicFutures.add(namespaceResources().getPartitionedTopicResources()
.deletePartitionedTopicAsync(TopicName.get(partitionedTopic)));
}

if (log.isDebugEnabled()) {
log.debug("Successfully send deletion command of partitioned-topics:{} "
+ "and non-partitioned-topics:{} in namespace:{}.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public class AdminApi2Test extends MockedPulsarServiceBaseTest {
@BeforeMethod
@Override
public void setup() throws Exception {
conf.setForceDeleteNamespaceAllowed(true);
conf.setLoadBalancerEnabled(true);
conf.setEnableNamespaceIsolationUpdateOnTime(true);
super.internalSetup();
Expand Down Expand Up @@ -2561,4 +2562,15 @@ private void testTerminateSystemTopic() throws Exception {
() -> admin.topics().terminateTopic(eventTopic));
assertTrue(ex instanceof PulsarAdminException.NotAllowedException);
}

@Test
private void testDeleteNamespaceForciblyWithManyTopics() throws Exception {
final String ns = "prop-xyz/ns-testDeleteNamespaceForciblyWithManyTopics";
admin.namespaces().createNamespace(ns, 2);
for (int i = 0; i < 100; i++) {
admin.topics().createPartitionedTopic(String.format("persistent://%s", ns + "/topic" + i), 3);
}
admin.namespaces().deleteNamespace(ns, true);
Assert.assertFalse(admin.namespaces().getNamespaces("prop-xyz").contains(ns));
}
}

0 comments on commit 70020f1

Please sign in to comment.