fix get partition metadata problem for a non-existed topic#8818
Conversation
BewareMyPower
left a comment
There was a problem hiding this comment.
A unit test should be added to cover the case when a PulsarAdmin tries to get the partition metadata of a non-existed topic.
|
Please rebase to the latest master since the master branch was broken before. |
|
@BewareMyPower I'll do this later. |
41b824b to
533e000
Compare
|
@BewareMyPower Please take a look this change again, thanks. |
|
@aloyszhang could you rebase to latest master? |
| if (e.getCause().getMessage().contains("Topic not exist.")) { | ||
| throw new org.apache.pulsar.broker.web.RestException(Response.Status.NOT_FOUND, "Topic not exist."); | ||
| } |
There was a problem hiding this comment.
Could you please clarify why throw (RestException) e.getCause() does not work here? If e.getCause is instance of RestException, I think we can throw it directly. I might be missing something here.
There was a problem hiding this comment.
I'll check this PR and push later.
| // Since CompletableFuture wrappers exception, so we will lost the Status | ||
| // rebuild the Status if exception message contains "Topic not exist." | ||
| if (e.getCause().getMessage().contains("Topic not exist.")) { | ||
| throw new org.apache.pulsar.broker.web.RestException(Response.Status.NOT_FOUND, "Topic not exist."); | ||
| } |
There was a problem hiding this comment.
Same as the above comment.
| } | ||
| } catch (RestException restException) { | ||
| if (Status.NOT_FOUND.getStatusCode() != restException.getResponse().getStatus()) { | ||
| throw restException; |
There was a problem hiding this comment.
I think it's not correct handling here, If got 404 here, it means the partitioned metadata does not exist right? If the partitioned metadata does exist, why should we prevent the non-partitioned topic creation?
| CompletableFuture<List<String>> future = new CompletableFuture<>(); | ||
| pulsar.getBrokerService().fetchPartitionedTopicMetadataAsync(topicName).whenComplete((meta, t) -> { | ||
| if (t != null) { | ||
| future.completeExceptionally(t); | ||
| return; | ||
| } | ||
| List<String> result = Lists.newArrayList(); | ||
| for (int i = 0; i < meta.partitions; i++) { | ||
| result.add(topicName.getPartition(i).toString()); | ||
| } | ||
| return CompletableFuture.completedFuture(result); | ||
| future.complete(result); | ||
| }); | ||
| return future; |
There was a problem hiding this comment.
What is the difference between these changes? Why we change the thenCompose to whenComplete?
| if (e.getCause() instanceof RestException) { | ||
| // Since CompletableFuture wrappers exception, so we will lost the Status | ||
| // rebuild the Status if exception message contains "Topic not exist." | ||
| if (e.getCause().getMessage().contains("Topic not exist.")) { |
There was a problem hiding this comment.
Please do not rely on strings, can we test the actual class?
There was a problem hiding this comment.
Yes, I'll change this PR and push again.
| pulsar().getBrokerService().fetchPartitionedTopicMetadataAsync(topicName).get(); | ||
| if (partitionedTopicMetadata.partitions < 1) { | ||
| if (!pulsar().getNamespaceService().checkTopicExists(topicName).get() | ||
| && checkAllowAutoCreation |
There was a problem hiding this comment.
Here is not covered by tests? I noticed the tests only cover the checkAllowAutoCreation=false, could you please help add a test for cover checkAllowAutoCreation=true?
There was a problem hiding this comment.
I'll add test case to protect this part of code.
|
@codelipenghui It seems merge |
|
/pulsarbot run-failure-checks |
|
/pulsarbot run-failure-checks |
2 similar comments
|
/pulsarbot run-failure-checks |
|
/pulsarbot run-failure-checks |
Fixes #8813 Currently, getting the partition metadata for a non-existed topic, it returns 0 instead of throwing an exception. This pr fix this by throwing an exception. If no metadata found in global zk, then will check whether the topic is exist, if yes, will return 0, otherwise will throw an exception. (cherry picked from commit a3dfb2a)
Fixes #8813 Currently, getting the partition metadata for a non-existed topic, it returns 0 instead of throwing an exception. This pr fix this by throwing an exception. If no metadata found in global zk, then will check whether the topic is exist, if yes, will return 0, otherwise will throw an exception. (cherry picked from commit a3dfb2a)
Fixes apache#8813 ### Motivation Currently, getting the partition metadata for a non-existed topic, it returns 0 instead of throwing an exception. This pr fix this by throwing an exception. ### Modifications If no metadata found in global zk, then will check whether the topic is exist, if yes, will return 0, otherwise will throw an exception.
Fixes #8813
Motivation
Currently, getting the partition metadata for a non-existed topic, it returns 0 instead of throwing an exception.
This pr fix this by throwing an exception.
Modifications
If no metadata found in global zk, then will check whether the topic is exist, if yes, will return 0, otherwise will throw an exception.