aymkhalil commented on code in PR #19097:
URL: https://github.com/apache/pulsar/pull/19097#discussion_r1059203687


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java:
##########
@@ -3157,42 +3157,38 @@ public CompletableFuture<Boolean> 
isAllowAutoTopicCreationAsync(final String top
         TopicName topicName = TopicName.get(topic);
         return isAllowAutoTopicCreationAsync(topicName);
     }
-
     public CompletableFuture<Boolean> isAllowAutoTopicCreationAsync(final 
TopicName topicName) {
-        Optional<Policies> policies =
-                pulsar.getPulsarResources().getNamespaceResources()
-                        .getPoliciesIfCached(topicName.getNamespaceObject());
-        return isAllowAutoTopicCreationAsync(topicName, policies);
-    }
-
-    private CompletableFuture<Boolean> isAllowAutoTopicCreationAsync(final 
TopicName topicName,
-                                                                     final 
Optional<Policies> policies) {
-        if (policies.isPresent() && policies.get().deleted) {
-            log.info("Preventing AutoTopicCreation on a namespace that is 
being deleted {}",
-                    topicName.getNamespaceObject());
-            return CompletableFuture.completedFuture(false);
-        }
-        //System topic can always be created automatically
-        if (pulsar.getConfiguration().isSystemTopicEnabled() && 
isSystemTopic(topicName)) {
-            return CompletableFuture.completedFuture(true);
-        }
-        final boolean allowed;
-        AutoTopicCreationOverride autoTopicCreationOverride = 
getAutoTopicCreationOverride(topicName, policies);
-        if (autoTopicCreationOverride != null) {
-            allowed = autoTopicCreationOverride.isAllowAutoTopicCreation();
-        } else {
-            allowed = pulsar.getConfiguration().isAllowAutoTopicCreation();
-        }
-
-        if (allowed && topicName.isPartitioned()) {
-            // cannot re-create topic while it is being deleted
-            return 
pulsar.getPulsarResources().getNamespaceResources().getPartitionedTopicResources()
-                    .isPartitionedTopicBeingDeletedAsync(topicName)
-                    .thenApply(beingDeleted -> !beingDeleted);
-        } else {
-            return CompletableFuture.completedFuture(allowed);
-        }
-
+        return pulsar.getPulsarResources().getNamespaceResources()
+                .getPoliciesAsync(topicName.getNamespaceObject(), true)

Review Comment:
   I traced http vs binary protocol calls that invoke this code:
   http calls:
   -  resetCursorOnPosition
   -  lookupTopic
   -  createSubscription
   -  grantPermissionsOnTopic
   -  getPartitionedMetadata
   -  Basically any method calling the 
[AdminResource#getPartitionedTopicMetadataAsync](https://github.com/apache/pulsar/blob/416c5b40ac1c44bbe281dba35ea6682dae7697da/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java#L482)
 with `checkAllowAutoCreation` true
   
   binary protocol calls:
   - handlePartitionMetadataRequest
   - handleSubscribe
   - handleProducer 
   
   I isolated the calls with as minimum code changes as possible. Please 
evaluate the value of the change vs the introduced code branches. 
   
   PTAL.
   



-- 
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]

Reply via email to