Skip to content

Conversation

@dajac
Copy link
Member

@dajac dajac commented May 12, 2025

This patch adds the TopicId field to the OffsetCommitValue record as
a tagged field. It will be later used on the offset fetch path to ensure
that the persisted offset matches the requested one.

Reviewers: Dongnuo Lyu dlyu@confluent.io, Sean Quah
squah@confluent.io, Lianet Magrans lmagrans@confluent.io

@dajac dajac added the KIP-848 The Next Generation of the Consumer Rebalance Protocol label May 12, 2025
@github-actions github-actions bot added the tools label May 12, 2025
@dajac dajac requested a review from Copilot May 13, 2025 06:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for persisting the TopicId in OffsetCommit records to ensure that the persisted offset matches the requested one. The changes include updates to the JSON schema, modifications to the OffsetAndMetadata and record helper implementations, and corresponding adjustments in test cases across multiple modules.

  • Updated JSON schema and production code to include the TopicId field.
  • Modified OffsetAndMetadata construction, conversion methods (fromRecord/fromRequest), and record creation in GroupCoordinatorRecordHelpers.
  • Revised and added tests in tools and group-coordinator modules to verify the correct handling of TopicId.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tools/src/test/java/org/apache/kafka/tools/consumer/OffsetMessageFormatterTest.java Added TopicId to OffsetCommitValue in tests.
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/streams/StreamsGroupTest.java Updated OffsetAndMetadata instantiation with TopicId.
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/modern/consumer/ConsumerGroupTest.java Modified tests to include TopicId in offset commit requests.
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/classic/ClassicGroupTest.java Included TopicId when constructing OffsetAndMetadata.
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/OffsetMetadataManagerTest.java Converted several tests to parameterized ones and passed TopicId where required.
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/OffsetExpirationConditionImplTest.java Passed TopicId to OffsetAndMetadata in expiration tests.
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/OffsetAndMetadataTest.java Added tests validating the TopicId field in OffsetAndMetadata.
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/GroupCoordinatorRecordHelpersTest.java Updated record creation tests to include TopicId.
group-coordinator/src/main/resources/common/message/OffsetCommitValue.json Added a new TopicId field to the JSON schema.
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/OffsetMetadataManager.java Passed TopicId from the topic to OffsetAndMetadata.
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/OffsetAndMetadata.java Extended the OffsetAndMetadata class to include and handle TopicId.
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupCoordinatorRecordHelpers.java Updated record creation to set TopicId from OffsetAndMetadata.

.setCommitTimestamp(1234L)
.setExpireTimestamp(-1L);
.setExpireTimestamp(-1L)
.setTopicId(uuid);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to confirm: when we read an older OffsetCommitValue, will we get a ZERO_UUID instead of a null?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. It uses ZERO_UUID by default.

@dajac dajac requested a review from squah-confluent May 13, 2025 19:23
.setExpireTimestamp(offsetAndMetadata.expireTimestampMs.orElse(OffsetCommitRequest.DEFAULT_TIMESTAMP)),
.setExpireTimestamp(offsetAndMetadata.expireTimestampMs.orElse(OffsetCommitRequest.DEFAULT_TIMESTAMP))
.setTopicId(offsetAndMetadata.topicId),
version
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we update offsetCommitValueVersion to return version 4 if topic id is present?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! I missed this.

Copy link
Contributor

@squah-confluent squah-confluent left a comment

Choose a reason for hiding this comment

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

Looks good to me!

// Serialize with the highest supported non-flexible version
// until a tagged field is introduced or the version is bumped.
return 3;
return 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if we can use OffsetCommitValue.highestSupportedVersion here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer to use hard coded version here to ensure that they are not bumped unintentionally. This is what we have been doing for the other records too.

Copy link
Contributor

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

@dajac dajac requested a review from lianetm May 15, 2025 18:37
Copy link
Member

@lianetm lianetm left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM.

@lianetm lianetm merged commit 199772a into apache:trunk May 16, 2025
26 checks passed
@dajac dajac deleted the KAFKA-19141 branch May 16, 2025 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

KIP-848 The Next Generation of the Consumer Rebalance Protocol tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants