#NEWLINE# def _adjust_replica2part2dev_size( self , to_assign ) : #NEWLINE# #INDENT# '\n        Make sure that the lengths of the arrays in _replica2part2dev\n        are correct for the current value of self.replicas.\n\n        Example:\n        self.part_power = 8\n        self.replicas = 2.25\n\n        self._replica2part2dev will contain 3 arrays: the first 2 of\n        length 256 (2**8), and the last of length 64 (0.25 * 2**8).\n\n        Update the mapping of partition => [replicas] that need assignment.\n        ' #NEWLINE# ( fractional_replicas , whole_replicas ) = math . modf ( self . replicas ) #NEWLINE# whole_replicas = int ( whole_replicas ) #NEWLINE# removed_parts = 0 #NEWLINE# new_parts = 0 #NEWLINE# desired_lengths = ( [ self . parts ] * whole_replicas ) #NEWLINE# if fractional_replicas : #NEWLINE# #INDENT# desired_lengths . append ( int ( ( self . parts * fractional_replicas ) ) ) #NEWLINE# #UNINDENT# if ( self . _replica2part2dev is not None ) : #NEWLINE# #INDENT# for part2dev in part2dev . _replica2part2dev [ len ( desired_lengths ) : ] : #NEWLINE# #INDENT# for dev_id in part2dev : #NEWLINE# #INDENT# dev_losing_part = self . devs [ dev_id ] #NEWLINE# dev_losing_part [ 'parts' ] -= 1 #NEWLINE# removed_parts -= 1 #NEWLINE# #UNINDENT# #UNINDENT# self . _replica2part2dev = self . _replica2part2dev [ : len ( desired_lengths ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _replica2part2dev = [ ] #NEWLINE# #UNINDENT# for ( replica , desired_length ) in enumerate ( desired_lengths ) : #NEWLINE# #INDENT# if ( replica < len ( self . _replica2part2dev ) ) : #NEWLINE# #INDENT# part2dev = self . _replica2part2dev [ replica ] #NEWLINE# if ( len ( part2dev ) < desired_length ) : #NEWLINE# #INDENT# for part in range ( len ( part2dev ) , desired_length ) : #NEWLINE# #INDENT# to_assign [ part ] . append ( replica ) #NEWLINE# part2dev . append ( NONE_DEV ) #NEWLINE# new_parts += 1 #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( part2dev ) > desired_length ) : #NEWLINE# #INDENT# for part in range ( desired_length , len ( part2dev ) ) : #NEWLINE# #INDENT# dev_losing_part = self . devs [ part2dev [ part ] ] #NEWLINE# dev_losing_part [ 'parts' ] -= 1 #NEWLINE# removed_parts -= 1 #NEWLINE# #UNINDENT# self . _replica2part2dev [ replica ] = part2dev [ : desired_length ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# for part in range ( desired_length ) : #NEWLINE# #INDENT# to_assign [ part ] . append ( replica ) #NEWLINE# new_parts += 1 #NEWLINE# #UNINDENT# self . _replica2part2dev . append ( array ( 'H' , itertools . repeat ( NONE_DEV , desired_length ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# self . logger . debug ( '%d new parts and %d removed parts from replica-count change' , new_parts , removed_parts )