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

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

commit a749d564ff361a4cb7cf7d49fb014e5bfcca4dd0
Author: Christophe Bornet <[email protected]>
AuthorDate: Thu Dec 9 18:47:50 2021 +0100

    Fix namespace policy override ignored when creating subscription (#12699)
    
    PR #6471 introduced the possibility to set auto topic creation settings at 
the namespace level
    PR #6685 is a fix to take into account the auto topic creation setting when 
creating a subscription
    but it uses the broker configuration and doesn't see the namespace level 
setting that was introduced in #6471
    
    This fix uses the   method that fetches config overrides in ZK instead of 
the one from the broker configuration.
    This way the  method of the pulsar-admin uses the value set for the 
namespace for auto-topic-creation
    
    (cherry picked from commit 965a80f1337697c8714e6b41bf562c196a126eae)
---
 .../pulsar/broker/admin/impl/PersistentTopicsBase.java    |  4 ++--
 .../service/BrokerServiceAutoTopicCreationTest.java       | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
index f223869..d97042f 100644
--- 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
+++ 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
@@ -2024,7 +2024,7 @@ public class PersistentTopicsBase extends AdminResource {
             internalCreateSubscriptionForNonPartitionedTopic(asyncResponse,
                     subscriptionName, targetMessageId, authoritative, 
replicated);
         } else {
-            boolean allowAutoTopicCreation = 
pulsar().getConfiguration().isAllowAutoTopicCreation();
+            boolean allowAutoTopicCreation = 
pulsar().getBrokerService().isAllowAutoTopicCreation(topicName);
             getPartitionedTopicMetadataAsync(topicName,
                     authoritative, 
allowAutoTopicCreation).thenAccept(partitionMetadata -> {
                 final int numPartitions = partitionMetadata.partitions;
@@ -2109,7 +2109,7 @@ public class PersistentTopicsBase extends AdminResource {
             AsyncResponse asyncResponse, String subscriptionName,
             MessageIdImpl targetMessageId, boolean authoritative, boolean 
replicated) {
 
-        boolean isAllowAutoTopicCreation = 
pulsar().getConfiguration().isAllowAutoTopicCreation();
+        boolean isAllowAutoTopicCreation = 
pulsar().getBrokerService().isAllowAutoTopicCreation(topicName);
 
         validateTopicOwnershipAsync(topicName, authoritative)
                 .thenCompose(__ -> {
diff --git 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceAutoTopicCreationTest.java
 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceAutoTopicCreationTest.java
index 7b74933..33ed356 100644
--- 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceAutoTopicCreationTest.java
+++ 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceAutoTopicCreationTest.java
@@ -351,6 +351,21 @@ public class BrokerServiceAutoTopicCreationTest extends 
BrokerTestBase{
     }
 
     @Test
+    public void testAutoCreationNamespaceOverridesSubscriptionTopicCreation() 
throws Exception {
+        pulsar.getConfiguration().setAllowAutoTopicCreation(false);
+        String topicString = "persistent://prop/ns-abc/non-partitioned-topic" 
+ System.currentTimeMillis();
+        String subscriptionName = "non-partitioned-topic-sub";
+        final TopicName topicName = TopicName.get(topicString);
+        
pulsar.getAdminClient().namespaces().setAutoTopicCreation(topicName.getNamespace(),
+                AutoTopicCreationOverride.builder()
+                        .allowAutoTopicCreation(true)
+                        .topicType(TopicType.NON_PARTITIONED.toString())
+                        .build());
+
+        admin.topics().createSubscription(topicString, subscriptionName, 
MessageId.earliest);
+    }
+
+    @Test
     public void testMaxNumPartitionsPerPartitionedTopicTopicCreation() {
         pulsar.getConfiguration().setAllowAutoTopicCreation(true);
         pulsar.getConfiguration().setAllowAutoTopicCreationType("partitioned");

Reply via email to