KAFKA-10606: Disable auto topic creation for fetch-all-topic-metadata request#9435
Conversation
|
Thanks for the PR. Thoughts on how to test this? |
|
@ijuma One way to test it could be to mock objects passed to the However, IMO, this change is pretty minor. So, I am wondering how necessary it is to add tests for it? |
|
|
|
@ijuma Will do! Thanks |
ab5e0d8 to
c877b32
Compare
There was a problem hiding this comment.
If we pass false to getTopicMetadata, it generates UNKNOWN_TOPIC_OR_PARTITION when the topic is removed, right? If so, does client-side need to handle such error? For example, KafkaAdminClient#listTopics should filter out those "nonexistent" topics (https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java#L1717). Otherwise, users want to get all "existent" topics but response say a_topic is "nonexistent".
There was a problem hiding this comment.
Hi @chia7712 , thank you for bringing up this issue and it's totally valid!
In order to preserve its behavior (not including UNKNOWN_TOPIC_OR_PARTITION in the response to fetch all topic metadata request), we implemented the below logic which filters out all entries in the response with UNKNOWN_TOPIC_OR_PARTITION if the metadata request is to get metadata for all topisc.
val completeTopicMetadata = (if (metadataRequest.isAllTopics) {
opicMetadata.filter(_.errorCode() != Errors.UNKNOWN_TOPIC_OR_PARTITION.code())
} else {
topicMetadata
}) ++ unauthorizedForCreateTopicMetadata ++ unauthorizedForDescribeTopicMetadata
We have added a unit test as well. Hope to get some feedback from you soon!
|
@Lincong Thanks for updating code. Could you fix the conflicting files as well? |
76bf1dc to
81e036e
Compare
Conflicts resolved |
|
@Lincong Could you take a look at those failed tests? I will give a review later :) |
81e036e to
8cceb13
Compare
There was a problem hiding this comment.
Could we do this filter early? For example, how about filtering getTopicMetadata directly? That makes all fixes be in one place and following authorized ops can skip "unknown partition/topic" as well.
There was a problem hiding this comment.
This is a good point. We should pass a boolean to getTopicMetadata indicating that it's an "allTopics" request and have that method handle everything.
There was a problem hiding this comment.
@ijuma I will merge this PR tomorrow if there is no objection.
7188454 to
a089259
Compare
|
+1 to last commit. Will merge it to trunk tomorrow if no object. |
There was a problem hiding this comment.
Could we remove this @Before code? Changing modifier of metadataCache from "val" to "var" is enough.
There was a problem hiding this comment.
hey @chia7712 ,
I add this to let each test case to have a clean, uncorrupted MetadataCache. Is there any historical context that we should avoid that cleanup?
There was a problem hiding this comment.
It seems to me following code is able to generate a clean, uncorrupted MetadataCache for each test case.
var metadataCache = new MetadataCache(brokerId)
Also, it is simpler than @Before block.
There was a problem hiding this comment.
Hey @chia7712 you're right. I did some reading and found that I misunderstood JUnit's behavior. Just updated that part and rebased latest trunk.
c2ec49c to
aebfafe
Compare
There was a problem hiding this comment.
Could we not avoid this altogether instead of doing the filter later?
There was a problem hiding this comment.
@ijuma I slightly changed it (and rebased latest) so the processing is a branch in the middle about isFetchAllMetadata.
It's still a map and filter structure because I don't want to sacrifice the readability, but it's handled in the middle instead of at the returning statement, which I think is more elegant and readable than the original version.
Let me know what you think!
There was a problem hiding this comment.
Also, I added the assertion of no UNKNOWN_TOPIC_OR_PARTITION into the unit test
There was a problem hiding this comment.
I think if you use flatMap, you don't need the filter and it's still readable. Thoughts?
92e554d to
38f9de2
Compare
There was a problem hiding this comment.
Is Some/None more readable than List/Nil?
There was a problem hiding this comment.
@chia7712 Thanks, you're right. Just updated accordingly and rebased latest trunk
38f9de2 to
779f6f3
Compare
There was a problem hiding this comment.
We don't usually include JIRA references in the code unless it's a very complex issue. I think the comment here could be something like:
"A metadata request for all topics should never result in topic auto creation. A topic may be deleted between the creation of topics and topicResponses, so we make sure to always return None for this case."
There was a problem hiding this comment.
Thanks @ijuma ,
To follow the convention in Kafka, I just updated the comments. Let me know if you have there are any other thoughts!
63d7cd6 to
b6b6713
Compare
|
@lmr3796 Thanks for your updating. Could you rebase code to include recent big commits to trigger QA again? |
b6b6713 to
6778e69
Compare
|
@ijuma I'd like to merge it tomorrow. would be helpful if you could give a final review :) |
|
@chia7712 The code changes seen fine. The comment in KafkaApis still seems a bit convoluted. For example, not returning UnknownTopicOrPartition is not related to backwards compatibility, it doesn't make sense to return that if the given topic wasn't explicitly requested. Similarly, the fact that allowAutoTopicCreation is true for some clients isn't that relevant, the code needs to handle it irrespective of what some clients do or don't do. I thought my suggested comment in the following was clear and concise, but I'm interested in other opinions: |
…request There is a bug that causes fetch-all-topic-metadata request triggering auto topic creation. Details are described in KAFKA-10606. This is the simplest way to fix this bug on the broker side.
6778e69 to
19e323e
Compare
There is a bug that causes fetch-all-topic-metadata requests triggering
auto topic creation. Details are described in KAFKA-10606. This is the
simplest way to fix this bug on the broker side.