Skip to content

KAFKA-16684: Remove cache in responseData#16532

Merged
soarez merged 5 commits intoapache:trunkfrom
m1a2st:KAFKA-16684
Jul 9, 2024
Merged

KAFKA-16684: Remove cache in responseData#16532
soarez merged 5 commits intoapache:trunkfrom
m1a2st:KAFKA-16684

Conversation

@m1a2st
Copy link
Copy Markdown
Collaborator

@m1a2st m1a2st commented Jul 5, 2024

The response data should change accordingly to the input, however with the current design, it will not change even if the input changes. We should remove this cache logic to avoid returning wrong data.
Jira: https://issues.apache.org/jira/browse/KAFKA-16684

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

LGTM if it does not hurt CI

}

@Test
public void testFetcherDontCacheAnyData() {
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 part is good but it's gone too far. Maybe we can create a FetchResponse and then test the method responseData?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I will simplify this test

@m1a2st
Copy link
Copy Markdown
Collaborator Author

m1a2st commented Jul 6, 2024

@chia7712, Thanks for your comments, PTAL

FetchResponse fetchResponse = fetchResponse(tidp0, records, Errors.NONE, 100L, -1L, 0L, 0);
fetchResponse.responseData(topicNames, version)
.forEach((topicPartition, partitionData) -> assertEquals(records, partitionData.records()));
fetchResponse.responseData(new HashMap<>(), version)
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.

Collections.emptyMap()

@m1a2st
Copy link
Copy Markdown
Collaborator Author

m1a2st commented Jul 7, 2024

@chia7712, Thanks for your comments, PTAL

Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@m1a2st thanks for updated patch. one last comment is left

public void testFetcherDontCacheAnyData() {
short version = 17;
FetchResponse fetchResponse = fetchResponse(tidp0, records, Errors.NONE, 100L, -1L, 0L, 0);
fetchResponse.responseData(topicNames, version)
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 you please verify the size first?

@m1a2st
Copy link
Copy Markdown
Collaborator Author

m1a2st commented Jul 8, 2024

@chia7712, Thanks for your comments, add assert for size()

@chia7712
Copy link
Copy Markdown
Member

chia7712 commented Jul 8, 2024

@apoorvmittal10 you had reviewed on #15966, so could you please take a look at this PR? thanks!

Copy link
Copy Markdown
Contributor

@apoorvmittal10 apoorvmittal10 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. LGTM! Just a query.


@Test
public void testFetcherDontCacheAnyData() {
short version = 17;
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.

Do we have any existing test where version < 13? If not then can we please add one.

Copy link
Copy Markdown
Collaborator Author

@m1a2st m1a2st Jul 9, 2024

Choose a reason for hiding this comment

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

@apoorvmittal10, Thanks for your comments, In testFetchWithNoTopicId have been test for version 12, Should I add a test only for FetchResponse#responseData this method to test version 12? WDYT

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.

Confirmed, org.apache.kafka.clients.consumer.internals.FetcherTest#testFetchWithNoTopicId is testing org.apache.kafka.common.requests.FetchResponse#responseData with version = 12, so I don't think we need a new test.

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.

Thansk for looking into, if there already exists a test then we can skip new one.

Copy link
Copy Markdown
Member

@soarez soarez left a comment

Choose a reason for hiding this comment

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

Thanks for this patch.

I could not find a good reason to keep the reponseData cached.

Test failures are unrelated.

LGTM

@soarez soarez merged commit 5608b5c into apache:trunk Jul 9, 2024
abhi-ksolves pushed a commit to ksolves/kafka that referenced this pull request Jul 31, 2024
The response data should change accordingly to the input, however
with the current design, it will not change even if the input changes.
We remove this cache logic to avoid returning wrong data.

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>, Apoorv Mittal <apoorvmittal10@gmail.com>, Igor Soarez <soarez@apple.com>
responseData.forEach((topicPartition, partitionData) -> assertEquals(records, partitionData.records()));
LinkedHashMap<TopicPartition, FetchResponseData.PartitionData> nonResponseData = fetchResponse.responseData(emptyMap(), version);
assertEquals(emptyMap().size(), nonResponseData.size());
nonResponseData.forEach((topicPartition, partitionData) -> assertEquals(MemoryRecords.EMPTY, partitionData.records()));
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 line is never executed. We can remove this assertion.

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.

nice find

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we can also replace emptyMap().size() with 0.

Copy link
Copy Markdown
Contributor

@Parkerhiphop Parkerhiphop Apr 4, 2025

Choose a reason for hiding this comment

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

I've opened a minor PR #19376 to remove it.

Thanks @FrankYang0529 for pointing it out!

chia7712 pushed a commit that referenced this pull request Apr 5, 2025
…19357)

Jira: https://issues.apache.org/jira/browse/KAFKA-19074

Similar fix #16532

2b8aff5
make it accept input to return "partial" data.
The content of output is based on the input but we cache the output ...
It will return same output even though we pass different input. That is
a potential bug.

Reviewers: PoAn Yang <payang@apache.org>, Chia-Ping Tsai
<chia7712@gmail.com>
chia7712 pushed a commit that referenced this pull request Apr 6, 2025
This is from [#16532's comment](https://github.com/apache/kafka/pull/16532/files#r2028985028):

The forEach loop in the assertion will never execute because
`nonResponseData` is empty.

This happens because the above assertion `emptyMap()` has a size of 0,
so there are no elements to iterate over.

Reviewers: PoAn Yang <payang@apache.org>, Ken Huang
<s7133700@gmail.com>, TaiJuWu <tjwu1217@gmail.com>, TengYao Chi
<kitingiao@gmail.com>, Chia-Ping Tsai <chia7712@gmail.com>
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.

7 participants