[
https://issues.apache.org/jira/browse/KAFKA-21188?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18145635#comment-18145635
]
Lucas Brutschy commented on KAFKA-21188:
----------------------------------------
Yes, that reasoning makes sense, and your reading of both scenarios matches the
code. One thing to add: a failed callback isn’t a state the member stays in.
The exception from {{onTasksAssigned}} or {{onTasksRevoked}} is rethrown from
{{poll()}} into the {{StreamThread}}. If it’s a {{TaskMigratedException}}, the
thread closes all its tasks in {{handleLostAll()}}, unsubscribes and subscribes
again, so it comes back without owned tasks. Any other exception kills the
thread: it requests to leave the group, closes its tasks and goes to the
uncaught exception handler. So the partially created tasks get cleaned up on
those paths, and the non-fetchable partitions cover the time in between, as you
said. I don’t think the membership manager needs to track partially applied
tasks for cleanup, and I’d keep the callback failure cases out of the scope of
this ticket.
While checking this, I found something I need to correct from my last comment.
The coordinator only skips the revocation if the heartbeat actually carries the
owned tasks. {{StreamsGroupHeartbeatRequestManager}} only sends
{{ActiveTasks}}, {{StandbyTasks}} and {{WarmupTasks}} when the reconciled
assignment has changed since the last heartbeat. If they are left out,
{{CurrentAssignmentBuilder}} assumes the member still owns everything. With a
partially resolved assignment, that leads to a hang. The client reports [1_0],
the coordinator moves 0_0 to another member, and the next heartbeat leaves out
the owned tasks, so the coordinator waits for 0_0 to be revoked. The client
then acknowledges the partially resolved assignment, but its reconciled
assignment is still [1_0], so it never sends its owned tasks again. The member
stays in {{UNREVOKED_TASKS}}, and the new owner waits for 0_0. The consumer
doesn’t have this problem because {{ConsumerHeartbeatRequestManager}} compares
the whole {{LocalAssignment}}, including the local epoch. Every acknowledgement
of a partially resolved assignment therefore resends the owned partitions. The
Streams heartbeat should do the same, so I’d add that to the fix together with
a test for it.
> Merging topics with different partition counts leaves some records
> unprocessed under the Streams Rebalance Protocol
> -------------------------------------------------------------------------------------------------------------------
>
> Key: KAFKA-21188
> URL: https://issues.apache.org/jira/browse/KAFKA-21188
> Project: Kafka
> Issue Type: Bug
> Components: clients, streams
> Reporter: sanghyeok An
> Assignee: sanghyeok An
> Priority: Major
>
> With {*}group.protocol=streams{*}, merging two topics with different
> partition counts includes nonexistent partitions in the tasks’ inputs,
> leaving some records unprocessed.
> *Steps to Reproduce*
> 1. Create topic A with 1 partition({*}0{*}) and topic B with 3
> partitions({*}0, 1, 2{*}).
> 2. Run the following topology with {*}group.protocol=streams{*}:
> {code:java}
> KStream<String, String> streamA = builder.stream("A");
> KStream<String, String> streamB = builder.stream("B");
> streamA.merge(streamB).to("output");
> {code}
> 3. Produce records to {*}A-0{*}, {*}B-0{*}, {*}B-1{*}, and {*}B-2{*}.
> * *Expected:* All input records appear in `output`.
> * *Actual:* Records from `B-1` and `B-2` do not appear in `output`, and the
> following messages repeatedly reference nonexistent partitions:
> {code:java}
> Requesting the log end offset for A-1 in order to compute lag
> Requesting the log end offset for A-2 in order to compute lag
> {code}
>
> *Cause*
> StreamsMembershipManager#topicPartitionsForActiveTasks and
> DefaultStreamsRebalanceListener#toTopicPartitions apply the task’s partition
> ID to every input topic without checking each topic’s partition count.
> As a result, a task that should include only *B-1* also includes {*}A-1{*}.
> The same issue occurs for partition ID 2.
> The classic protocol’s PartitionGrouper checks each topic’s partition count
> and includes only existing partitions. The new protocol’s conversion paths
> need equivalent handling.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)