[
https://issues.apache.org/jira/browse/KAFKA-21612?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18150930#comment-18150930
]
sanghyeok An commented on KAFKA-21612:
--------------------------------------
[~lucasbru]
Thanks for taking the time look into this!
{quote}Do you want to work on this problem? I have a draft PR now
{quote}
I'm happy to work on this myself, or I can help with the review if you would
prefer to work on it. (Since you already have a draft PR, I assumed you were
planning to work on this, but please let me know if I misunderstood!). Whatever
works best for you.
{quote}Does anyone see a case where an existing topic with a smaller count
should be rejected?
{quote}
Let me investigate potential edge cases.
If I find something, I will let you know here. (I might be unavailable on
weekdays this week, but I'll be available over the weekend)
> Streams group coordinator undercounts repartition topic partitions when it
> visits a downstream subtopology before its upstream dependency
> -----------------------------------------------------------------------------------------------------------------------------------------
>
> Key: KAFKA-21612
> URL: https://issues.apache.org/jira/browse/KAFKA-21612
> Project: Kafka
> Issue Type: Bug
> Components: group-coordinator, streams
> Reporter: sanghyeok An
> Assignee: sanghyeok An
> Priority: Major
>
> *Description*
> A Kafka Streams application using {{group.protocol=streams}} reads from two
> input topics, {{high}} with 3 partitions and {{low}} with 1 partition. It
> repartitions {{{}high{}}}, merges the result with {{{}low{}}}, and
> repartitions the merged stream. Both {{repartition()}} calls leave the
> partition count unspecified.
>
> {code:java}
> KStream<String, String> low = builder.stream("low");
> KStream<String, String> upstream = builder.<String, String>stream("high")
> .repartition(Repartitioned.as("upstream"));
> low.merge(upstream)
> .repartition(Repartitioned.as("downstream"))
> .to("output");
> {code}
>
> The expected partition count for {{upstream}} is 3 because its only input is
> {{{}high{}}}. The expected count for {{downstream}} is also 3, the maximum of
> its two inputs. However, the group coordinator requests {*}3 partitions for
> {{upstream}} and only 1 for {{downstream}}{*}.
> *Both classic protocol and streams protocol have same problem.*
>
> *Cause and impact*
> With {{low}} registered first in this topology, the subtopology that writes
> to {{downstream}} gets ID {{{}0{}}}, and the one that writes to {{upstream}}
> gets ID {{{}1{}}}. When the coordinator visits subtopology {{0}} first, it
> knows that {{low}} has 1 partition but has yet to determine the partition
> count for {{{}upstream{}}}.
> The coordinator skips the unresolved input and records {{{}downstream=1{}}}.
> When it later determines that {{{}upstream=3{}}}, it does not revisit
> {{downstream}} because that topic already has a recorded count. As a result,
> the coordinator can request a new {{downstream}} topic with only 1 partition.
> If the topic already exists with the expected 3 partitions, the coordinator
> can reject it with {{{}expected 1, found 3{}}}.
>
> *Subsequent member joins and coordinator failover*
> The partition count is determined at the group level. Once the group has a
> {{{}ConfiguredTopology{}}}, the coordinator reuses it when another member
> joins with a matching topology and the relevant topic metadata is unchanged.
> A subsequent join therefore does not change {{downstream}} from 1 to 3.
> On failover, the new coordinator loses the in-memory {{ConfiguredTopology}}
> but restores the group topology from {{{}__consumer_offsets{}}}. If the first
> member to join after failover supplies a matching topology, the coordinator
> recalculates the partition count from the restored group topology. With the
> same calculation logic and topic metadata, this example resolves to
> {{downstream=1}} again. If the topic has yet to be created, the coordinator
> requests 1 partition. If it already exists with 1 partition, the coordinator
> accepts it.
>
> *How to reproduce*
> {code:java}
> // Start broker and execute this commands in your terminal
> $ bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic high
> --partitions 3 --replication-factor 1 11:34:37
> $ bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic low
> --partitions 1 --replication-factor 1
> $ bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic
> output --partitions 1 --replication-factor 1
> // Run this simple stream application
> KStream<String, String> low = builder.stream("low");
> KStream<String, String> upstream = builder.<String, String>stream("high")
> .repartition(Repartitioned.as("upstream"));
> low.merge(upstream)
> .repartition(Repartitioned.as("downstream"))
> .to("output");
> // execute this command in your terminal and see the result
> $ kcat -b localhost:9092 -L | grep "repartition"
> topic "ASH-HELLO-upstream-repartition" with 3 partitions:
> topic "ASH-HELLO-downstream-repartition" with 1 partitions:{code}
> *ASH-HELLO-downstream-repartition* should be 3 partitions. (but 1 partition)
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)