Repository navigation
Fix StickyPartitionAssignor infinite loop with mixed subscriptions - #3164
Open
mstojcevich wants to merge 1 commit into
Open
mstojcevich wants to merge 1 commit into
mstojcevich wants to merge 1 commit into
Conversation
Suppose a partition already moved from X to C during this rebalance and is then reassigned from C to N. PartitionMovements.get_partition_to_be_moved may return a same-topic substitute that moved from N to X. X owns that substitute, so moving only the substitute leaves C's load unchanged, and _perform_reassignments never terminates. Also move the original partition back to X. Both earlier movements are undone, and C gives up one partition to N. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3163
Problem
With mixed topic subscriptions,
StickyAssignmentExecutor._perform_reassignmentscan loop forever. The group leader then never completes the rebalance. This affectsStickyPartitionAssignorandCooperativeStickyAssignor.Root cause
_reassign_partition_to_consumer(partition, new_consumer)may receive a substitute fromPartitionMovements.get_partition_to_be_moved(). This happens whenpartitionalready moved X ->consumerand a same-topic partition movednew_consumer-> X. X owns the substitute, notconsumer. Moving only the substitute leavesconsumeroverloaded, so the balance loop repeats the same move forever.Fix
When the substitute's owner differs from
consumer, also movepartitionback to that owner. Both earlier movement records cancel, so stickiness holds and no cycle is created. The net effect is one partition moved fromconsumertonew_consumer, which has at least 2 fewer partitions. The sum of squared assignment sizes therefore strictly decreases, and the loop terminates.Tests
Added
test_reassignment_with_mixed_subscriptions_terminatestotest/consumer/test_assignors.py. It runs the reproduction from the issue and caps_move_partitioncalls at 1000, so a regression fails fast instead of hanging. With the fix, the assignment needs 15 moves. Without the fix, the test fails withToo many partition movements.With the fix:
I used an AI coding assistant (Claude) to investigate this and write the fix and this description.