Skip to content

Fix StickyPartitionAssignor invalid previous_assignment reassignments and generation 0 conflict check - #3209

Open
utku0dogan wants to merge 1 commit into
dpkp:masterfrom
utku0dogan:fix/sticky-assignor-previous-assignment
Open

utku0dogan wants to merge 1 commit into
dpkp:masterfrom
utku0dogan:fix/sticky-assignor-previous-assignment

Conversation

@utku0dogan

Copy link
Copy Markdown
Contributor

Summary

Fixes three related bugs in StickyAssignmentExecutor (kafka/coordinator/assignors/sticky/sticky_assignor.py):

  1. Assigning unsubscribed topics during reassignment (_perform_reassignments):
    When moving a partition back to self.previous_assignment[partition].consumer, the assignor did not verify that prev_consumer is still subscribed to partition.topic (prev_consumer in self.partition_to_all_potential_consumers[partition]). During rebalances with mixed/changing subscriptions and conflicting generations, a member could be assigned a partition for a topic it is not subscribed to.
  2. KeyError when prev_consumer was moved to fixed_assignments (_perform_reassignments):
    balance() removes fixed consumers from self.current_assignment, which is a defaultdict(list). Indexing self.current_assignment[prev_consumer] without checking prev_consumer in self.current_assignment auto-vivified an empty list (len == 0) and caused _move_partition to crash with KeyError in sorted_current_subscriptions.remove(...).
  3. generation == 0 falsy check (_init_current_assignments):
    if member_metadata.generation and member_metadata.generation in consumers: treated valid generation 0 as falsy, silently overwriting the earlier owner instead of logging a warning and preserving it like generations >= 1.

Tests

Added three regression tests in test/consumer/test_assignors.py:

  • test_reassignment_does_not_assign_unsubscribed_topic_from_previous_assignment
  • test_reassignment_skips_fixed_previous_consumer
  • test_conflicting_generation_zero_preserves_first_owner

Verified with pytest test/consumer/test_assignors.py (187 passed).

@utku0dogan

Copy link
Copy Markdown
Contributor Author

@dpkp
Both CI failures appear to be unrelated flakes (all 18 other jobs passed, including Python 3.8–3.14 and both selector/asyncio):

py 3.14 / kafka 3.9.0 / net random: test_sasl_integration.py failed during fixture setup (RuntimeError: Failed to create Zookeeper chroot node).
py 3.14 / kafka 0.10.2.2 / net random: test_metadata_growth_triggers_rejoin_end_to_end (single-member default RangePartitionAssignor timing flake).

Could someone re-run the failed jobs when convenient?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant