jiazhai commented on a change in pull request #4963: Add more config for 
auto-topic-creation
URL: https://github.com/apache/pulsar/pull/4963#discussion_r321597326
 
 

 ##########
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
 ##########
 @@ -566,6 +574,78 @@ public PartitionedTopicMetadata deserialize(String key, 
byte[] content) throws E
         return metadataFuture;
     }
 
+    protected static PartitionedTopicMetadata 
fetchPartitionedTopicMetadataCheckAllowAutoCreation(
+            PulsarService pulsar, String path, TopicName topicName) {
+        try {
+            return 
fetchPartitionedTopicMetadataCheckAllowAutoCreationAsync(pulsar, path, 
topicName)
+                    .get();
+        } catch (Exception e) {
+            if (e.getCause() instanceof RestException) {
+                throw (RestException) e;
+            }
+            throw new RestException(e);
+        }
+    }
+
+    protected static CompletableFuture<PartitionedTopicMetadata> 
fetchPartitionedTopicMetadataCheckAllowAutoCreationAsync(
+            PulsarService pulsar, String path, TopicName topicName) {
+        CompletableFuture<PartitionedTopicMetadata> metadataFuture = new 
CompletableFuture<>();
+        try {
+            boolean allowAutoTopicCreation = 
pulsar.getConfiguration().isAllowAutoTopicCreation();
+            String topicType = 
pulsar.getConfiguration().getAllowAutoTopicCreationType();
+            boolean topicExist;
+            try {
+                topicExist = pulsar.getNamespaceService()
+                        .getListOfTopics(topicName.getNamespaceObject(), 
PulsarApi.CommandGetTopicsOfNamespace.Mode.ALL)
+                        .contains(topicName.toString());
+            } catch (Exception e) {
+                log.warn("Unexpected error while getting list of topics. 
topic={}. Error: {}",
+                        topicName, e.getMessage(), e);
+                throw new RestException(e);
+            }
+            fetchPartitionedTopicMetadataAsync(pulsar, 
path).whenComplete((metadata, ex) -> {
 
 Review comment:
   Discussed with Penghui through slack channel. Penghui's concern is here: the 
returned future of `fetchPartitionedTopicMetadataAsync` is completed in 
`pulsar.getGlobalZkCache().getDataAsync` callback, so this `whenComplete` 
method will be executed in zkcache callback. This has potential to block 
zkcache thread.  
   we should use `whenCompleteAsync` here, then the following method will 
execute in a new thread, and could avoid blocking zkcache thread.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to