-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix get partition metadata problem for a non-existed topic #8818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
BewareMyPower
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check this PR and push later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @aloyszhang
| // 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not rely on strings, can we test the actual class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add test case to protect this part of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
eolivelli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
@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.