Skip to content

KAFKA-19440: Handle top-level errors in AlterShareGroupOffsets RPC#20049

Merged
AndrewJSchofield merged 5 commits into
apache:trunkfrom
AndrewJSchofield:KAFKA-19440
Jul 3, 2025
Merged

KAFKA-19440: Handle top-level errors in AlterShareGroupOffsets RPC#20049
AndrewJSchofield merged 5 commits into
apache:trunkfrom
AndrewJSchofield:KAFKA-19440

Conversation

@AndrewJSchofield

@AndrewJSchofield AndrewJSchofield commented Jun 26, 2025

Copy link
Copy Markdown
Member

While testing the code in #19820, it
became clear that the error handling problems were due to the underlying
Admin API. This PR fixes the error handling for top-level errors in the
AlterShareGroupOffsets RPC.

Reviewers: Apoorv Mittal apoorvmittal10@gmail.com, Lan Ding
isDing_L@163.com, TaiJuWu tjwu1217@gmail.com

List<TopicPartition> partitionsFailed = topicPartitionErrorsMap.entrySet()
.stream()
.filter(e -> e.getValue() != Errors.NONE)
.filter(e -> e.getValue() != null)

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.

Thanks for the patch, just out of curiosity, would the AlterConsumerGroupOffsets RPC have the same issue?

return this.future.thenApply(topicPartitionErrorsMap -> {
List<TopicPartition> partitionsFailed = topicPartitionErrorsMap.entrySet()
.stream()
.filter(e -> e.getValue() != Errors.NONE)
.map(Map.Entry::getKey)
.collect(Collectors.toList());
for (Errors error : topicPartitionErrorsMap.values()) {
if (error != Errors.NONE) {
throw error.exception(
"Failed altering group offsets for the following partitions: " + partitionsFailed);
}
}

@AndrewJSchofield AndrewJSchofield Jun 30, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll check it out before I merge, but the important difference here is in KafkaApis.scala. For DeleteSGO, it already handled a non-zero error code. For AlterSGO, that code was missing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, sorry. I didn't read your comment accurately. The difference is that AlterShareGroupOffsets can successfully pass back an error code, which is why this is in terms of ApiException rather than Errors. For AlterConsumerGroupOffsets, the RPC is actually OffsetCommit and this does not have an ErrorMessage field at all. So, it cannot be fixed for consumer groups until we have a version bump on the OffsetCommit RPC.

.filter(e -> e.getValue() != Errors.NONE)
.filter(e -> e.getValue() != null)
.map(Map.Entry::getKey)
.collect(Collectors.toList());

@TaiJuWu TaiJuWu Jun 30, 2025

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.

Should this change to immutable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure it matters here. The list in internal to this method, and it is just converted to a string and appended to the exception message.

@DL1231

DL1231 commented Jul 2, 2025

Copy link
Copy Markdown
Collaborator

@AndrewJSchofield The last build failed with AuthorizerIntegrationTest failed. Could you please check?

@AndrewJSchofield

Copy link
Copy Markdown
Member Author

@AndrewJSchofield The last build failed with AuthorizerIntegrationTest failed. Could you please check?

Interesting. I fixed a mistake and I expect the test needs fixing too. Will do.

@DL1231 DL1231 left a comment

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.

Thanks for the patch, LGTM.

@TaiJuWu TaiJuWu left a comment

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.

LGTM.

@apoorvmittal10 apoorvmittal10 left a comment

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 for the PR, LGTM!

@AndrewJSchofield
AndrewJSchofield merged commit 729f9cc into apache:trunk Jul 3, 2025
25 checks passed
@AndrewJSchofield
AndrewJSchofield deleted the KAFKA-19440 branch July 3, 2025 10:01
jiafu1115 pushed a commit to jiafu1115/kafka that referenced this pull request Jul 3, 2025
…pache#20049)

While testing the code in apache#19820, it
became clear that the error handling problems were due to the underlying
Admin API. This PR fixes the error handling for top-level errors in the
AlterShareGroupOffsets RPC.

Reviewers: Apoorv Mittal <apoorvmittal10@gmail.com>, Lan Ding
 <isDing_L@163.com>, TaiJuWu <tjwu1217@gmail.com>
} else {
response.data().responses().forEach(topic -> topic.partitions().forEach(partition -> {
if (partition.errorCode() != Errors.NONE.code()) {
final Errors partitionError = Errors.forCode(partition.errorCode());

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.

nit: we can reuse the Errors

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.

nit: the debug message should use placeholder for partitionErrorMessage

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.

for example:

                var partitionError = Errors.forCode(partition.errorCode());
                var partitionErrorMessage = partition.errorMessage();
                if (partitionError != Errors.NONE) {
                    log.debug("AlterShareGroupOffsets request for group id {} and topic-partition {}-{} failed and returned error {}. {}",
                        groupId.idValue, topic.topicName(), partition.partitionIndex(), partitionError, partitionErrorMessage);
                }
                partitionResults.put(new TopicPartition(topic.topicName(), partition.partitionIndex()), partitionError.exception(partitionErrorMessage));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks @chia7712 . I'll put in a minor PR today.

chia7712 pushed a commit that referenced this pull request Jul 9, 2025
Minor tidying up in AlterShareGroupOffsetsHandler based on review
comment
#20049 (comment).

Reviewers: Jimmy Wang <wangzhiwang611@gmail.com>, Lan Ding
 <isDing_L@163.com>, TaiJuWu <tjwu1217@gmail.com>, Ken Huang
 <s7133700@gmail.com>, Jhen-Yung Hsu <jhenyunghsu@gmail.com>, Chia-Ping
 Tsai <chia7712@gmail.com>
k-apol pushed a commit to k-apol/kafka that referenced this pull request Aug 8, 2025
…pache#20049)

While testing the code in apache#19820, it
became clear that the error handling problems were due to the underlying
Admin API. This PR fixes the error handling for top-level errors in the
AlterShareGroupOffsets RPC.

Reviewers: Apoorv Mittal <apoorvmittal10@gmail.com>, Lan Ding
 <isDing_L@163.com>, TaiJuWu <tjwu1217@gmail.com>
k-apol pushed a commit to k-apol/kafka that referenced this pull request Aug 8, 2025
Minor tidying up in AlterShareGroupOffsetsHandler based on review
comment
apache#20049 (comment).

Reviewers: Jimmy Wang <wangzhiwang611@gmail.com>, Lan Ding
 <isDing_L@163.com>, TaiJuWu <tjwu1217@gmail.com>, Ken Huang
 <s7133700@gmail.com>, Jhen-Yung Hsu <jhenyunghsu@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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants