nodece opened a new pull request, #21802: URL: https://github.com/apache/pulsar/pull/21802
### Motivation The `org.apache.pulsar.broker.admin.AdminResource#checkTopicExistsAsync` cannot correctly check the topic exists. Create a non-persistent topic with partitions 3: ```java admin.topics().createPartitionedTopic(partitionedTopicName, 3); // 1 admin.topics().createPartitionedTopic(partitionedTopicName, 3); // 2 ``` See the following log: ``` 2023-12-26T15:33:21,419 - WARN - [AsyncHttpClient-83-1:BaseResource$1@135] - [http://localhost:57405/admin/v2/non-persistent/my-property/my-ns/tp_-5d732a7b-6ace-4a71-b2f9-35d103215fc1/partitions?createLocalTopicOnly=false] Failed to perform http put request: javax.ws.rs.ClientErrorException: HTTP 409 {"reason":"Partitioned topic already exists"} ``` `Partitioned topic already exists` has been thrown by `org.apache.pulsar.broker.admin.AdminResource#provisionPartitionedTopicPath`, but I expect this error is `This topic already exists`: ```java protected void internalCreatePartitionedTopic(AsyncResponse asyncResponse, int numPartitions, boolean createLocalTopicOnly, Map<String, String> properties) { // .... .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"); } }) .thenCompose(__ -> provisionPartitionedTopicPath(numPartitions, createLocalTopicOnly, properties)) .thenCompose(__ -> tryCreatePartitionsAsync(numPartitions)) // .... } ``` This means `checkTopicExistsAsync` is incorrect. ### Modifications - Make the `checkTopicExistsAsync` to call the `org.apache.pulsar.broker.namespace.NamespaceService#checkTopicExists`. - Use `checkTopicExistsAsync` in the `internalCreateNonPartitionedTopicAsync`. ### Verifying this change `org.apache.pulsar.broker.namespace.NamespaceServiceTest#testCheckTopicExists` can cover this change. ### Documentation <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. --> - [ ] `doc` <!-- Your PR contains doc changes. --> - [ ] `doc-required` <!-- Your PR changes impact docs and you will update later --> - [x] `doc-not-needed` <!-- Your PR changes do not impact docs --> - [ ] `doc-complete` <!-- Docs have been already added --> -- 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]
