315157973 commented on a change in pull request #11148:
URL: https://github.com/apache/pulsar/pull/11148#discussion_r672227978



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
##########
@@ -742,19 +742,28 @@ protected void 
internalCreatePartitionedTopic(AsyncResponse asyncResponse, int n
      * @param topicName given topic name
      */
     protected CompletableFuture<Boolean> checkTopicExistsAsync(TopicName 
topicName) {
-        return 
pulsar().getNamespaceService().getListOfTopics(topicName.getNamespaceObject(),
-                CommandGetTopicsOfNamespace.Mode.ALL)
-                .thenCompose(topics -> {
-                    boolean exists = false;
-                    for (String topic : topics) {
-                        if (topicName.getPartitionedTopicName().equals(
-                                
TopicName.get(topic).getPartitionedTopicName())) {
-                            exists = true;
-                            break;
+        if (topicName.isPersistent()) {
+            String path = ZkAdminPaths.partitionedTopicPath(topicName);
+            return 
pulsar().getPulsarResources().getNamespaceResources().getPartitionedTopicResources().
+                    
existsAsync(path).thenCombine(pulsar().getLocalZkCacheService().
+                            
managedLedgerExists(topicName.getPersistenceNamingEncoding()),
+                    (isPartitionedExists, isNonPartitionedExists) -> 
isPartitionedExists || isNonPartitionedExists);
+
+        } else {
+            return 
pulsar().getNamespaceService().getListOfTopics(topicName.getNamespaceObject(),
+                    CommandGetTopicsOfNamespace.Mode.NON_PERSISTENT)

Review comment:
       We have multiLayerTopicsMap in BrokerService, we don't need to traverse 
all NON_PERSISTENT, and then traverse again to determine whether it exists.
   We only need to traverse the bundles, and then directly map.contains can do 
it, usually the number of bundles is not too much




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