You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/12/30 00:54:45 UTC

[GitHub] [pulsar] aymkhalil commented on a diff in pull request #19097: [improve] Refresh ns policy when deciding auto topic creation eligibility

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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org