KAFKA-12329; kafka-reassign-partitions command should give a better error message when a topic does not exist#10141
Conversation
chia7712
left a comment
There was a problem hiding this comment.
@dajac Nice improvement. Some minor comments are left. Please take a look.
- https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java#L1893 also check the existence of topic. Will it become a redundant check after we merge this PR?
- Should we apply this readable error message to other APIs?
deleteTopics, for example.
There was a problem hiding this comment.
How about using topicError.exception("Topic " + topicName + " not found.")
@chia7712 Thanks for your comment. To answer your questions:
|
…rror message when a topic does not exist, refactored
65c5f75 to
e6a031a
Compare
|
@chia7712 I just pushed an update. Please take a look and let me know what you think about it. |
chia7712
left a comment
There was a problem hiding this comment.
overall +1
one small suggestion is left.
| topicName -> topicDescriptionFuture.get | ||
| } | ||
| catch { | ||
| case t: ExecutionException if t.getCause != null => |
There was a problem hiding this comment.
How about using classOf[UnknownTopicOrPartitionException].isInstance(t.getCause)? That includes null check.
|
@chia7712 Thanks. I just pushed a commit to address your comment. Could you take another look? |
|
Failed test is not related. Merging to trunk. |
| } | ||
| catch { | ||
| case t: ExecutionException => | ||
| if (classOf[UnknownTopicOrPartitionException].isInstance(t.getCause)) { |
There was a problem hiding this comment.
Hmm. why not write this as t.getCause.isInstanceOf[UnknownTopicOrPartitionException]?
There was a problem hiding this comment.
Also, you can have the if in the case t line and then a second case for the rethrow case.
There was a problem hiding this comment.
I initially used t.getCause != null && t.getCause.isInstanceOf[UnknownTopicOrPartitionException]. @chia7712 suggested to use classOf[UnknownTopicOrPartitionException].isInstance(t.getCause) to avoid having to do the null check as isInstance does it. That seemed reasonable to me so I went with it. Is there a reason not to use it?
I do agree with your second comment.
There was a problem hiding this comment.
Hmm, I think this is an example of code that is less readable. If cause may be nullable, it's better to write code that makes that clear rather than a non obvious alternative that could have been used for many other reasons (using Option to handle nullables is fine as a counter example since it's common usage to do that to handle nulls).
What do you think?
There was a problem hiding this comment.
Oh, one more thing, did you check that the null check is actually needed? I think isInstanceOf is defined for null too.
There was a problem hiding this comment.
I think isInstanceOf is defined for null too.
you are right. Scala does define it. https://scala-lang.org/files/archive/spec/2.13/spec.pdf
‘’’
isInstanceOf[T] always returns false.
‘’’
Good to know that :)
+1 to use ‘t.getCause.isInstanceOf[UnknownTopicOrPartitionException]‘ as it can deal with null check.
Sorry for my imprecise comment :(
There was a problem hiding this comment.
@ijuma Yeah, I do agree with you. For the null check, I was not aware that isInstanceOf handles it. That's good to know, thanks.
I will open a small PR to fix this.
* apache-github/trunk: (37 commits) KAFKA-10357: Extract setup of changelog from Streams partition assignor (apache#10163) KAFKA-10251: increase timeout for consuming records (apache#10228) KAFKA-12394; Return `TOPIC_AUTHORIZATION_FAILED` in delete topic response if no describe permission (apache#10223) MINOR: Disable transactional/idempotent system tests for Raft quorums (apache#10224) KAFKA-10766: Unit test cases for RocksDBRangeIterator (apache#9717) KAFKA-12289: Adding test cases for prefix scan in InMemoryKeyValueStore (apache#10052) KAFKA-12268: Implement task idling semantics via currentLag API (apache#10137) MINOR: Time and log producer state recovery phases (apache#10241) MINOR: correct the error message of validating uint32 (apache#10193) MINOR: Format the revoking active log output in `StreamsPartitionAssignor` (apache#10242) KAFKA-12323 Follow-up: Refactor the unit test a bit (apache#10205) MINOR: Remove stack trace of the lock exception in a debug log4j (apache#10231) MINOR: Word count should account for extra whitespaces between words (apache#10229) MINOR; Small refactor in `GroupMetadata` (apache#10236) KAFKA-10340: Proactively close producer when cancelling source tasks (apache#10016) KAFKA-12329; kafka-reassign-partitions command should give a better error message when a topic does not exist (apache#10141) KAFKA-12254: Ensure MM2 creates topics with source topic configs (apache#10217) MINOR: fix kafka-metadata-shell.sh (apache#10226) KAFKA-12374: Add missing config sasl.mechanism.controller.protocol (apache#10199) KAFKA-10101: Fix edge cases in Log.recoverLog and LogManager.loadLogs (apache#8812) ...
kafka-reassign-partitionscommand gives a generic error message when one tries to reassign a topic which does not exist:When the reassignment contains multiple topics, it is hard to find out the correct one. This PR improves this to give the name of the topic in the error:
Committer Checklist (excluded from commit message)