Lauri Mäkinen
12/10/2024, 1:17 PMAly Ayman
12/11/2024, 4:27 AMstatic int getSplitOwner(TopicPartition tp, int numReaders) {
int startIndex = ((tp.topic().hashCode() * 31) & 0x7FFFFFFF) % numReaders;
// here, the assumption is that the id of Kafka partitions are always ascending
// starting from 0, and therefore can be used directly as the offset clockwise from the
// start index
return (startIndex + tp.partition()) % numReaders;
}
Your case hit an unlucky scenario where the hash of all your topic names modulo numReaders (4) resulted in the same starting index (likely 0). After that, partitions are distributed in a round-robin fashion from this starting point.
So, with 4 slots:
• All topics started distribution from slot 0
• Partition 0 of each topic went to slot 0
• Partition 1 of each topic went to slot 1
• Slots 2 and 3 got nothing
This is why reducing to 2 slots fixed the issue - even with the same starting point, the round-robin distribution covered all slots evenly.
You can retry using a prime number for slot count can help reduce the likelihood of uneven distribution! (2,3,5,7,Lauri Mäkinen
12/11/2024, 1:49 PMAly Ayman
12/11/2024, 4:07 PMLauri Mäkinen
12/11/2024, 6:48 PMAly Ayman
12/12/2024, 12:16 AMAly Ayman
12/12/2024, 12:23 AMLauri Mäkinen
12/18/2024, 2:17 PMINFO org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumerBase - Consumer subtask 2 will start reading the following 2 partitions from the committed group offsets in Kafka: [KafkaTopicPartition{topic='TOPIC_A', partition=1}, KafkaTopicPartition{topic='TOPIC_B', partition=1}]
INFO org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumerBase - Consumer subtask 0 will start reading the following 1 partitions from the committed group offsets in Kafka: [KafkaTopicPartition{topic='TOPIC_C', partition=0}]
INFO org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumerBase - Consumer subtask 1 will start reading the following 3 partitions from the committed group offsets in Kafka: [KafkaTopicPartition{topic='TOPIC_A', partition=0}, KafkaTopicPartition{topic='TOPIC_C', partition=1}, KafkaTopicPartition{topic='TOPIC_B', partition=0}]
INFO org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumerBase - Consumer subtask 3 initially has no partitions to read from.Lauri Mäkinen
12/18/2024, 2:17 PMLauri Mäkinen
12/18/2024, 3:26 PM