
    9h                         S SK r S SKrS SKJrJr  S SKJr  S SKJr  S SK	J
r
Jr  \R                  " \5      r " S S\5      rg)    N)IterableMapping)ClusterMetadata)AbstractPartitionAssignor) ConsumerProtocolMemberAssignmentConsumerProtocolMemberMetadatac            	           \ rS rSrSrSrSr\S\S\	\
\4   S\\
\4   4S j5       r\S	\\
   S\4S
 j5       r\S\SS4S j5       rSrg)RangePartitionAssignor   a  
The range assignor works on a per-topic basis. For each topic, we lay out
the available partitions in numeric order and the consumers in
lexicographic order. We then divide the number of partitions by the total
number of consumers to determine the number of partitions to assign to each
consumer. If it does not evenly divide, then the first few consumers will
have one extra partition.

For example, suppose there are two consumers C0 and C1, two topics t0 and
t1, and each topic has 3 partitions, resulting in partitions t0p0, t0p1,
t0p2, t1p0, t1p1, and t1p2.

The assignment will be:
    C0: [t0p0, t0p1, t1p0, t1p1]
    C1: [t0p2, t1p2]
ranger   clustermembersreturnc                    [         R                  " [        5      nUR                  5        H+  u  pEUR                   H  nX6   R                  U5        M     M-     [         R                  " [        5      nUR                  5        H  u  phUR                  U5      n	U	c  [        R                  SU5        M1  [        U	5      n
UR                  5         [        U
5      [        U5      -  n[        U
5      [        U5      -  n[        U5       H2  u  pX-  nU[        X5      -  nUnUS-   U:  d  US-  nXX-    Xt   U'   M4     M     0 nU H7  n[        U R                   [        UU   R                  5       5      S5      UU'   M9     U$ )Nz"No partition metadata for topic %s       )collectionsdefaultdictlistitemssubscriptionappenddictpartitions_for_topiclogwarningsortedsortlen	enumerateminr   version)clsr   r   consumers_per_topicmembermetadatatopic
assignmentconsumers_for_topic
partitionspartitions_listpartitions_per_consumerconsumers_with_extraistartlengthprotocol_assignment	member_ids                     iC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\aiokafka/coordinator/assignors/range.pyassignRangePartitionAssignor.assign$   s    5@4K4KD4Q 'F!..#*11&9 / !0
 7B6M6Md6S
*=*C*C*E&E 55e<J!@%H$Z0O$$&&)/&:cBU>V&V##&#7#>Q:R#R &':;	/3Q5501u33aKF,;EN,S
"5) < +F& LN I-MVJy$9$?$?$ABC.	* ! #"r   topicsc                 B    [        U R                  [        U5      S5      $ )Nr   )r   r"   r   )r#   r6   s     r3   r&   RangePartitionAssignor.metadataL   s    -ckk4<MMr   r(   Nc                     g )N )r#   r(   s     r3   on_assignment$RangePartitionAssignor.on_assignmentP   s    r   r:   )__name__
__module____qualname____firstlineno____doc__namer"   classmethodr   r   strr   r   r   r4   r   r&   r;   __static_attributes__r:   r   r3   r
   r
      s    " DG%# %# <<=%# 
c33	4	%# %#N Nhsm N0N N N 'G D  r   r
   )r   loggingcollections.abcr   r   aiokafka.clusterr   'aiokafka.coordinator.assignors.abstractr   aiokafka.coordinator.protocolr   r   	getLoggerr=   r   r
   r:   r   r3   <module>rL      s:      - , M
 !C6 Cr   