This is an automated email from the ASF dual-hosted git repository.

technoboy pushed a commit to branch branch-2.11
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-2.11 by this push:
     new f8e1089872c [fix] [broker] delete topic failed if disabled system 
topic (#19735)
f8e1089872c is described below

commit f8e1089872cd34ea1c3e589eab02a3a8ef7229ae
Author: fengyubiao <[email protected]>
AuthorDate: Thu Mar 9 15:13:50 2023 +0800

    [fix] [broker] delete topic failed if disabled system topic (#19735)
    
    Motivation: After PR #18823, The cmd delete topic will fail if disabled the 
feature system topic.
    Modifications: do not delete the system policy if disabled the feature 
system topic
---
 .../broker/service/persistent/PersistentTopic.java | 14 ++---
 .../client/impl/DisabledSystemTopicTest.java       | 61 ++++++++++++++++++++++
 2 files changed, 68 insertions(+), 7 deletions(-)

diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
index 6213db88f80..8e95f2c4313 100644
--- 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
+++ 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
@@ -1184,13 +1184,13 @@ public class PersistentTopic extends AbstractTopic 
implements Topic, AddEntryCal
                     CompletableFuture<Void> deleteTopicAuthenticationFuture = 
new CompletableFuture<>();
                     brokerService.deleteTopicAuthenticationWithRetry(topic, 
deleteTopicAuthenticationFuture, 5);
                     deleteTopicAuthenticationFuture.thenCompose(ignore -> 
deleteSchema())
-                            .thenCompose(ignore -> {
-                                if 
(!this.getBrokerService().getPulsar().getBrokerService()
-                                        .isSystemTopic(TopicName.get(topic))) {
-                                    return deleteTopicPolicies();
-                                } else {
-                                    return 
CompletableFuture.completedFuture(null);
-                                }
+                                .thenCompose(ignore -> {
+                                    if 
(!SystemTopicNames.isTopicPoliciesSystemTopic(topic)
+                                            && 
brokerService.getPulsar().getConfiguration().isSystemTopicEnabled()) {
+                                        return deleteTopicPolicies();
+                                    } else {
+                                        return 
CompletableFuture.completedFuture(null);
+                                    }
                                 })
                             .thenCompose(ignore -> 
transactionBufferCleanupAndClose())
                             .whenComplete((v, ex) -> {
diff --git 
a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/DisabledSystemTopicTest.java
 
b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/DisabledSystemTopicTest.java
new file mode 100644
index 00000000000..7747d3a576c
--- /dev/null
+++ 
b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/DisabledSystemTopicTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.impl;
+
+import java.util.UUID;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.client.api.ProducerConsumerBase;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+@Slf4j
+@Test(groups = "broker")
+public class DisabledSystemTopicTest extends ProducerConsumerBase {
+
+    @Override
+    @BeforeMethod
+    public void setup() throws Exception {
+        super.internalSetup();
+        super.producerBaseSetup();
+    }
+
+    @Override
+    @AfterMethod(alwaysRun = true)
+    public void cleanup() throws Exception {
+        super.internalCleanup();
+    }
+
+    protected void doInitConf() throws Exception {
+        super.doInitConf();
+        conf.setTransactionCoordinatorEnabled(false);
+        conf.setSystemTopicEnabled(false);
+    }
+
+    @Test
+    public void testDeleteTopic() throws Exception {
+        String topicName = "persistent://my-property/my-ns/tp_" + 
UUID.randomUUID().toString();
+
+        admin.topics().createNonPartitionedTopic(topicName);
+        admin.topics().delete(topicName, false);
+
+        admin.topics().createPartitionedTopic(topicName, 3);
+        admin.topics().deletePartitionedTopic(topicName);
+    }
+}

Reply via email to