poorbarcode commented on code in PR #24225:
URL: https://github.com/apache/pulsar/pull/24225#discussion_r2086219638


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java:
##########
@@ -596,12 +598,32 @@ protected void 
internalCreatePartitionedTopic(AsyncResponse asyncResponse, int n
                     }
                 })
                 .thenCompose(__ -> checkTopicExistsAsync(topicName))
-                .thenAccept(exists -> {
-                    if (exists) {
-                        log.warn("[{}] Failed to create already existing topic 
{}", clientAppId(), topicName);
-                        throw new RestException(Status.CONFLICT, "This topic 
already exists");
+                .thenAccept(topicExistsInfo -> {
+                    try {
+                        if (topicExistsInfo.isExists()) {
+                            if 
(topicExistsInfo.getTopicType().equals(TopicType.NON_PARTITIONED)
+                                    || 
(topicExistsInfo.getTopicType().equals(TopicType.PARTITIONED)
+                                    && !createLocalTopicOnly)) {

Review Comment:
   > Once such a partition is mistakenly created as a non-partitioned topic, it 
is no longer possible to convert it into a partitioned topic, because Pulsar 
does not allow overwriting existing topics. This results in effective metadata 
loss. A similar issue can occur in geo-replication scenarios, where only the 
individual partition topics are replicated, but the partitioned topic metadata 
is not.
   > Moreover, if the partitioned topic metadata is lost, running `pulsar-admin 
topics create-partitioned-topic` fails to recreate it:
   > ```
   > > pulsar-admin topics create-partitioned-topic test-partitioned-topic -p 4
   > 2025-04-25T19:45:14,373+0800 [AsyncHttpClient-7-2] WARN  
org.apache.pulsar.client.admin.internal.BaseResource - 
[http://localhost:8080/admin/v2/persistent/public/default/test-partitioned-topic/partitions?createLocalTopicOnly=false]
 Failed to perform http put request: javax.ws.rs.ClientErrorException: HTTP 409 
{"reason":"This topic already exists"}
   > This topic already exists
   > ```
   > In this case, the partition still exist, but the partitioned topic 
metadata is missing—causing a `409 Conflict` when attempting to recreate it.
   
   The motivation of this PR is to create missed partitioned metadata if only 
partitions exist, but the purpose of the current modification is that it 
continuously creates the topic even though the partitioned metadata exists, 
right?



-- 
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-unsubscr...@pulsar.apache.org

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

Reply via email to