Skip to content

KAFKA-10606: Disable auto topic creation for fetch-all-topic-metadata request#9435

Merged
chia7712 merged 9 commits into
apache:trunkfrom
Lincong:disable-atc-bug
Dec 9, 2020
Merged

KAFKA-10606: Disable auto topic creation for fetch-all-topic-metadata request#9435
chia7712 merged 9 commits into
apache:trunkfrom
Lincong:disable-atc-bug

Conversation

@Lincong

@Lincong Lincong commented Oct 14, 2020

Copy link
Copy Markdown
Contributor

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.

@ijuma

ijuma commented Oct 14, 2020

Copy link
Copy Markdown
Member

Thanks for the PR. Thoughts on how to test this?

@Lincong

Lincong commented Oct 14, 2020

Copy link
Copy Markdown
Contributor Author

@ijuma One way to test it could be to mock objects passed to the KafkaApis class. The MetadataCache object should be mocked in a way that upon the first invocation on the method getAllTopics to simulate the scenario in which the metadata cache got updated "concurrently" with handleTopicMetadataRequest.

However, IMO, this change is pretty minor. So, I am wondering how necessary it is to add tests for it?

@ijuma

ijuma commented Oct 14, 2020

Copy link
Copy Markdown
Member

KafkaApisTest has a few tests like that. Could we add one there? The main concern is that we will regress here if we don't have tests.

@Lincong

Lincong commented Oct 14, 2020

Copy link
Copy Markdown
Contributor Author

@ijuma Will do! Thanks

@ijuma ijuma changed the title MINOR KAFKA-10606 Disable auto topic creation for fetch-all-topic-metadata request KAFKA-10606: Disable auto topic creation for fetch-all-topic-metadata request Oct 20, 2020

@chia7712 chia7712 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lincong Nice finding and patch. I left a small question.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

@Lincong Lincong Nov 12, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@chia7712

Copy link
Copy Markdown
Member

@Lincong Thanks for updating code. Could you fix the conflicting files as well?

@Lincong

Lincong commented Nov 13, 2020

Copy link
Copy Markdown
Contributor Author

@Lincong Thanks for updating code. Could you fix the conflicting files as well?

Conflicts resolved

@Lincong Lincong requested a review from chia7712 November 17, 2020 08:23
@chia7712

Copy link
Copy Markdown
Member

@Lincong Could you take a look at those failed tests? I will give a review later :)

@chia7712 chia7712 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lincong Thanks for your patch. overall LGTM. Just leave a small suggestion. Please take a look.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @chia7712 @ijuma ,

This is Joseph and I'm @Lincong 's colleague working on this patch with him. I think this is a good point and just updated the PR accordingly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ijuma I will merge this PR tomorrow if there is no objection.

@lmr3796 lmr3796 force-pushed the disable-atc-bug branch 2 times, most recently from 7188454 to a089259 Compare November 19, 2020 20:51
@chia7712

Copy link
Copy Markdown
Member

+1 to last commit. Will merge it to trunk tomorrow if no object.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove this @Before code? Changing modifier of metadataCache from "val" to "var" is enough.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lmr3796 lmr3796 force-pushed the disable-atc-bug branch 2 times, most recently from c2ec49c to aebfafe Compare November 25, 2020 06:29

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we not avoid this altogether instead of doing the filter later?

@lmr3796 lmr3796 Dec 1, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I added the assertion of no UNKNOWN_TOPIC_OR_PARTITION into the unit test

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you use flatMap, you don't need the filter and it's still readable. Thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ijuma That's a good point. I've updated it.

@lmr3796 lmr3796 force-pushed the disable-atc-bug branch 4 times, most recently from 92e554d to 38f9de2 Compare December 1, 2020 19:03
@Lincong Lincong requested a review from ijuma December 2, 2020 18:36

@chia7712 chia7712 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lincong @lmr3796 Thanks for the updating. one small question is raised. Please take a look.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Some/None more readable than List/Nil?

@lmr3796 lmr3796 Dec 3, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chia7712 Thanks, you're right. Just updated accordingly and rebased latest trunk

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ijuma ,

To follow the convention in Kafka, I just updated the comments. Let me know if you have there are any other thoughts!

@chia7712

chia7712 commented Dec 8, 2020

Copy link
Copy Markdown
Member

@lmr3796 Thanks for your updating. Could you rebase code to include recent big commits to trigger QA again?

@lmr3796

lmr3796 commented Dec 8, 2020

Copy link
Copy Markdown
Contributor

@chia7712 @ijuma I just rebased to latest trunk. Please take a look

@chia7712

chia7712 commented Dec 9, 2020

Copy link
Copy Markdown
Member

@ijuma I'd like to merge it tomorrow. would be helpful if you could give a final review :)

@ijuma

ijuma commented Dec 9, 2020

Copy link
Copy Markdown
Member

@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:

#9435 (comment)

@chia7712

chia7712 commented Dec 9, 2020

Copy link
Copy Markdown
Member

I thought my suggested comment in the following was clear and concise, but I'm interested in other opinions:
#9435 (comment)

@ijuma Sorry that I neglected that conversation.

@lmr3796 FYI ~

@lmr3796

lmr3796 commented Dec 9, 2020

Copy link
Copy Markdown
Contributor

Hi thanks @ijuma @chia7712 ,

I updated the comments accordingly to make it more concise and rebased latest trunk.
Please let me know if there are any other issues.

@chia7712

chia7712 commented Dec 9, 2020

Copy link
Copy Markdown
Member

I updated the comments accordingly to make it more concise and rebased latest trunk.
Please let me know if there are any other issues.

@lmr3796 Thanks for updating. waiting for response from @ijuma :)

@ijuma

ijuma commented Dec 9, 2020

Copy link
Copy Markdown
Member

@chia7712 feel free to merge if it looks good to you. Thanks @lmr3796 for the patience.

@chia7712 chia7712 merged commit ff88874 into apache:trunk Dec 9, 2020
@chia7712

chia7712 commented Dec 9, 2020

Copy link
Copy Markdown
Member

@Lincong @lmr3796 Thanks for your efforts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants