[
https://issues.apache.org/jira/browse/KAFKA-21612?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
sanghyeok An updated KAFKA-21612:
---------------------------------
Description:
*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)
was:
*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}}{*}.
*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)
> 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)