fix: re-add consumer group STABLE check in hasLeaderPartition - #17639
fix: re-add consumer group STABLE check in hasLeaderPartition#17639waterWang wants to merge 2 commits into
Conversation
Before PR apache#14395, hasLeaderPartition() only returned true when the consumer group was in the STABLE state, ensuring the cg-control consumer had joined before the coordinator started firing commits. PR apache#14395 removed this check, causing the cg-control consumer group to never reach STABLE when the data topic goes idle after initial consumption. This commit restores the STABLE state guard. Fixes apache#17193
Add ConsumerGroupState.STABLE mock to testHasLeaderPartition and add a new testHasLeaderPartitionNotStable test that verifies hasLeaderPartition returns false when the group is not STABLE.
|
Re-adding a readiness gate may well be the right call, but three statements in the stated root cause 1. The removed check was on the Connect group, not 2. 3. A poll gap does not expire None of this says the symptom in #17193 is not real; #11818 reports the same thing. My concern is The thing that would settle it is which group the reporter's Happy to be shown wrong on any of the three points — they are all checkable against Kafka 3.9 |
Fix
Re-add the
ConsumerGroupState.STABLEcheck inhasLeaderPartition()that was removed in PR #14395.Root cause
PR #14395 ("Don't check that consumer group is stable for coordinator leader election") removed the
groupDesc.state() == ConsumerGroupState.STABLEguard fromhasLeaderPartition(). Without this check, the coordinator can start firing commits before thecg-controlconsumer group has stabilized. When the data topic goes idle after initial consumption, the main consumer'spoll()blocks formax.poll.interval.ms(default 60s), during which thecg-controlconsumer cannot heartbeat, causing its session timeout (45s) to expire and the group to never reach STABLE.Fix
Restore the STABLE state check: only consider this worker the leader when the consumer group is in the
STABLEstate, ensuring thecg-controlconsumer has joined before the coordinator starts commit cycles.Changes
import org.apache.kafka.common.ConsumerGroupStateand re-addedif (groupDesc.state() == ConsumerGroupState.STABLE)guardConsumerGroupState.STABLEmock totestHasLeaderPartition, addedtestHasLeaderPartitionNotStabletest for the non-STABLE caseFixes #17193