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/03/29 05:54:48 UTC

[GitHub] [pulsar] mattisonchao commented on a change in pull request #14920: [fix][broker] Reject auto create partitioned topic when topic name contains ``-partition-``

mattisonchao commented on a change in pull request #14920:
URL: https://github.com/apache/pulsar/pull/14920#discussion_r837079883



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
##########
@@ -2606,40 +2606,30 @@ private void createPendingLoadTopic() {
             return FutureUtil.failedFuture(new NamingException("namespace service is not ready"));
         }
         return pulsar.getNamespaceService().checkTopicExists(topicName)
-                .thenCompose(topicExists -> {
-                    return fetchPartitionedTopicMetadataAsync(topicName)
-                            .thenCompose(metadata -> {
-                                CompletableFuture<PartitionedTopicMetadata> future = new CompletableFuture<>();
-
-                                // There are a couple of potentially blocking calls, which we cannot make from the
-                                // MetadataStore callback thread.
-                                pulsar.getExecutor().execute(() -> {
-                                    // If topic is already exist, creating partitioned topic is not allowed.
-
-                                    if (metadata.partitions == 0
-                                            && !topicExists
-                                            && !topicName.isPartitioned()
-                                            && pulsar.getBrokerService().isAllowAutoTopicCreation(topicName)
-                                            && pulsar.getBrokerService().isDefaultTopicTypePartitioned(topicName)) {
-
-                                        pulsar.getBrokerService().createDefaultPartitionedTopicAsync(topicName)
-                                                .thenAccept(md -> future.complete(md))
-                                                .exceptionally(ex -> {
-                                                    future.completeExceptionally(ex);
-                                                    return null;
-                                                });
-                                    } else {
-                                        future.complete(metadata);
-                                    }
-                                });
-
-                                return future;
-                            });
-                });
+                .thenCompose(topicExists -> fetchPartitionedTopicMetadataAsync(topicName)
+                        .thenComposeAsync(metadata -> {
+                            // There are a couple of potentially blocking calls, which we cannot make from the
+                            // MetadataStore callback thread.
+                            // If topic is already exist, creating partitioned topic is not allowed.
+                            if (metadata.partitions == 0
+                                    && !topicExists
+                                    && !topicName.isPartitioned()
+                                    && pulsar.getBrokerService().isAllowAutoTopicCreation(topicName)
+                                    && pulsar.getBrokerService().isDefaultTopicTypePartitioned(topicName)) {
+                                return pulsar.getBrokerService().createDefaultPartitionedTopicAsync(topicName);
+                            } else {
+                                return CompletableFuture.completedFuture(null);
+                            }
+                        }, pulsar.getExecutor())
+                );

Review comment:
       Yes, only for removing redundant future.




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