5
5
from kafka .coordinator .assignors .abstract import AbstractPartitionAssignor
6
6
from kafka .coordinator .assignors .sticky .partition_movements import PartitionMovements
7
7
from kafka .coordinator .assignors .sticky .sorted_set import SortedSet
8
- from kafka .coordinator .protocol import ConsumerProtocolMemberMetadata , ConsumerProtocolMemberAssignment
8
+ from kafka .coordinator .protocol import ConsumerProtocolMemberMetadata_v0 , ConsumerProtocolMemberAssignment_v0
9
9
from kafka .coordinator .protocol import Schema
10
10
from kafka .protocol .struct import Struct
11
11
from kafka .protocol .types import String , Array , Int32
@@ -66,6 +66,7 @@ class StickyAssignorUserDataV1(Struct):
66
66
67
67
class StickyAssignmentExecutor :
68
68
def __init__ (self , cluster , members ):
69
+ # a mapping of member_id => StickyAssignorMemberMetadataV1
69
70
self .members = members
70
71
# a mapping between consumers and their assigned partitions that is updated during assignment procedure
71
72
self .current_assignment = defaultdict (list )
@@ -603,7 +604,7 @@ def assign(cls, cluster, members):
603
604
604
605
assignment = {}
605
606
for member_id in members :
606
- assignment [member_id ] = ConsumerProtocolMemberAssignment (
607
+ assignment [member_id ] = ConsumerProtocolMemberAssignment_v0 (
607
608
cls .version , sorted (executor .get_final_assignment (member_id )), b''
608
609
)
609
610
return assignment
@@ -625,24 +626,24 @@ def parse_member_metadata(cls, metadata):
625
626
user_data = metadata .user_data
626
627
if not user_data :
627
628
return StickyAssignorMemberMetadataV1 (
628
- partitions = [], generation = cls .DEFAULT_GENERATION_ID , subscription = metadata .subscription
629
+ partitions = [], generation = cls .DEFAULT_GENERATION_ID , subscription = metadata .topics
629
630
)
630
631
631
632
try :
632
633
decoded_user_data = StickyAssignorUserDataV1 .decode (user_data )
633
- except Exception as e :
634
+ except Exception :
634
635
# ignore the consumer's previous assignment if it cannot be parsed
635
- log .error ("Could not parse member data" , e ) # pylint: disable=logging-too-many-args
636
+ log .exception ("Could not parse member data" )
636
637
return StickyAssignorMemberMetadataV1 (
637
- partitions = [], generation = cls .DEFAULT_GENERATION_ID , subscription = metadata .subscription
638
+ partitions = [], generation = cls .DEFAULT_GENERATION_ID , subscription = metadata .topics
638
639
)
639
640
640
641
member_partitions = []
641
642
for topic , partitions in decoded_user_data .previous_assignment : # pylint: disable=no-member
642
643
member_partitions .extend ([TopicPartition (topic , partition ) for partition in partitions ])
643
644
return StickyAssignorMemberMetadataV1 (
644
645
# pylint: disable=no-member
645
- partitions = member_partitions , generation = decoded_user_data .generation , subscription = metadata .subscription
646
+ partitions = member_partitions , generation = decoded_user_data .generation , subscription = metadata .topics
646
647
)
647
648
648
649
@classmethod
@@ -661,7 +662,7 @@ def _metadata(cls, topics, member_assignment_partitions, generation=-1):
661
662
partitions_by_topic [topic_partition .topic ].append (topic_partition .partition )
662
663
data = StickyAssignorUserDataV1 (list (partitions_by_topic .items ()), generation )
663
664
user_data = data .encode ()
664
- return ConsumerProtocolMemberMetadata (cls .version , list (topics ), user_data )
665
+ return ConsumerProtocolMemberMetadata_v0 (cls .version , list (topics ), user_data )
665
666
666
667
@classmethod
667
668
def on_assignment (cls , assignment ):
0 commit comments