[
https://issues.apache.org/jira/browse/KAFKA-21188?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18141139#comment-18141139
]
Lucas Brutschy commented on KAFKA-21188:
----------------------------------------
[~chickenchickenlove] thanks for digging into this, and for the PoC!
You’re right about both cases. I checked the client’s {{Metadata}}: a new
snapshot is built only from the partitions in the response, and leader epochs
protect existing partitions but don’t keep missing ones. So a lagging broker
can make the cached partition count go down. For the client-only fix, I’d guard
against that by never using a partition count lower than the one we already
reconciled the task with. Since partition counts only grow, taking the maximum
is safe, and it fixes your second case. Your first case, a client that never
learned about the new partitions, can’t be fixed on the client alone, I agree.
I still think the client-only fix is worth doing as a first step. It fully
fixes the reported case and with it the migration blocker, and it can be
backported, while the KIP needs a new heartbeat version and only helps once
brokers are upgraded. What remains open after the client fix only shows up when
a source topic is expanded while the application runs, which already isn’t
supported for stateful applications. If we build the client fix along the lines
of the consumer’s {{AbstractMembershipManager}}, most of it carries over to the
KIP: reconcile the tasks whose source topics are resolved, request a metadata
update for the rest, acknowledge a partially resolved assignment, and keep the
partition counts with the reconciled assignment so that the owned partitions
and the task manager always use the same counts. For the client fix, a source
topic is resolved once its partition count is known. With the KIP, it is
resolved once its topic ID can be mapped to a name, and the partition count
comes from the coordinator. The client-only lookup then stays as the fallback
for coordinators without the KIP. It would be great if you took on the KIP as
well.
Some thoughts on the PoC, mostly on the protocol, since that’s what the KIP
will be about. These can of course be discussed in more detail in the KIP
discussion.
The topic metadata doesn’t have to be the exact snapshot the assignment was
computed from. Partition counts on the coordinator only grow, so pairing an
assignment with newer counts is still correct: the client just includes
partitions that exist. That would let us avoid persisting the snapshot in the
target assignment record. Consumer groups moved away from persisting topic
metadata in KIP-1101 and keep only a metadata hash, which streams groups
already have too. We could reuse that hash as the version: the client sends the
hash of the metadata it has, and the coordinator only sends the topic metadata
when the hash differs. Same pattern as the endpoint information epoch, but no
new state.
I’d also stay close to the consumer group protocol and identify topics by ID
only, with the client resolving IDs to names through its metadata as described
above.
On per subtopology vs. a flat list: I think a flat list is enough, also for
regex. Grouping topics by subtopology wouldn’t be enough for regex sources
anyway, since the client also needs to know which source node a topic belongs
to, and a subtopology can have several. So the client has to match topic names
against the source patterns of its topology either way, as the classic protocol
does today, and a flat list avoids repeating topics shared between
subtopologies. This is similar to the consumer group protocol, where the
coordinator resolves the regex, but the assignment only carries topic IDs. For
this to work, the coordinator and the client need to agree on what a pattern
matches. KIP-848 resolves patterns with RE2J, while Streams topologies use Java
regular expressions. I think we should follow the consumer here and add a
{{SubscriptionPattern}}-based source API to Kafka Streams with RE2J semantics,
evaluated with RE2J on both the coordinator and the client. The existing
{{Pattern}}-based sources would keep working with the classic protocol.
What do you think?
> 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)