-
Notifications
You must be signed in to change notification settings - Fork 15k
KAFKA-14367; Add OffsetFetch to the new GroupCoordinator interface
#12870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4b1b652
d15dbdc
15a1a16
307b585
4258cbf
3f80d6f
ecd893e
23fbbb1
31f843f
6f913d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| import java.util.Map.Entry; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I follow-up, I would like to clean this class. There are way too many ways to construct this object and the logic is pretty complicated. It is the same for the request. Let's do this separately.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds like a good plan. Thanks! |
||
| import java.util.stream.Collectors; | ||
| import org.apache.kafka.common.TopicPartition; | ||
| import org.apache.kafka.common.errors.UnsupportedVersionException; | ||
| import org.apache.kafka.common.message.OffsetFetchResponseData; | ||
| import org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup; | ||
| import org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartition; | ||
|
|
@@ -119,12 +120,6 @@ public int hashCode() { | |
| } | ||
| } | ||
|
|
||
| public OffsetFetchResponse(OffsetFetchResponseData data) { | ||
| super(ApiKeys.OFFSET_FETCH); | ||
| this.data = data; | ||
| this.error = null; | ||
| } | ||
|
|
||
| /** | ||
| * Constructor without throttle time. | ||
| * @param error Potential coordinator or group level error code (for api version 2 and later) | ||
|
|
@@ -208,6 +203,59 @@ public OffsetFetchResponse(int throttleTimeMs, | |
| this.error = null; | ||
| } | ||
|
|
||
| public OffsetFetchResponse(List<OffsetFetchResponseGroup> groups, short version) { | ||
| super(ApiKeys.OFFSET_FETCH); | ||
| data = new OffsetFetchResponseData(); | ||
|
|
||
| if (version >= 8) { | ||
| data.setGroups(groups); | ||
| error = null; | ||
|
|
||
| for (OffsetFetchResponseGroup group : data.groups()) { | ||
| this.groupLevelErrors.put(group.groupId(), Errors.forCode(group.errorCode())); | ||
| } | ||
dajac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| if (groups.size() != 1) { | ||
| throw new UnsupportedVersionException( | ||
| "Version " + version + " of OffsetFetchResponse only supports one group." | ||
| ); | ||
| } | ||
|
|
||
| OffsetFetchResponseGroup group = groups.get(0); | ||
| data.setErrorCode(group.errorCode()); | ||
| error = Errors.forCode(group.errorCode()); | ||
|
|
||
| group.topics().forEach(topic -> { | ||
| OffsetFetchResponseTopic newTopic = new OffsetFetchResponseTopic().setName(topic.name()); | ||
| data.topics().add(newTopic); | ||
|
|
||
| topic.partitions().forEach(partition -> { | ||
| OffsetFetchResponsePartition newPartition; | ||
|
|
||
| if (version < 2 && group.errorCode() != Errors.NONE.code()) { | ||
| // Versions prior to version 2 do not support a top level error. Therefore, | ||
| // we put it at the partition level. | ||
| newPartition = new OffsetFetchResponsePartition() | ||
| .setPartitionIndex(partition.partitionIndex()) | ||
| .setErrorCode(group.errorCode()) | ||
| .setCommittedOffset(INVALID_OFFSET) | ||
| .setMetadata(NO_METADATA) | ||
| .setCommittedLeaderEpoch(NO_PARTITION_LEADER_EPOCH); | ||
| } else { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm a bit confused on the else statement. we can hit this either when version >= 2 or group error == NONE. based on the comment above, it seems that for version >= 2 we don't have to put error at the partition level. also, do we need to add offset/metadata if there is an error for version >= 2?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is still possible to have a partition level error with version >= 2 (e.g. UNSTABLE_OFFSET_COMMIT). To answer your second point, if there is an error, the offset/metadata should be correctly set at this stage so we can just copy whatever we have got here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that makes sense. thanks for the clarification |
||
| newPartition = new OffsetFetchResponsePartition() | ||
| .setPartitionIndex(partition.partitionIndex()) | ||
| .setErrorCode(partition.errorCode()) | ||
| .setCommittedOffset(partition.committedOffset()) | ||
| .setMetadata(partition.metadata()) | ||
| .setCommittedLeaderEpoch(partition.committedLeaderEpoch()); | ||
| } | ||
|
|
||
| newTopic.partitions().add(newPartition); | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| public OffsetFetchResponse(OffsetFetchResponseData data, short version) { | ||
| super(ApiKeys.OFFSET_FETCH); | ||
| this.data = data; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.