'Make sure that the lengths of the arrays in _replica2part2dev
are correct for the current value of self.replicas.
Example:
self.part_power = 8
self.replicas = 2.25
self._replica2part2dev will contain 3 arrays: the first 2 of
length 256 (2**8), and the last of length 64 (0.25 * 2**8).
Update the mapping of partition => [replicas] that need assignment.'

def _adjust_replica2part2dev_size(self, to_assign):

    (fractional_replicas, whole_replicas) = math.modf(self.replicas)
    whole_replicas = int(whole_replicas)
    removed_parts = 0
    new_parts = 0
    desired_lengths = ([self.parts] * whole_replicas)
    if fractional_replicas:
        desired_lengths.append(int((self.parts * fractional_replicas)))
    if (self._replica2part2dev is not None):
        for part2dev in self._replica2part2dev[len(desired_lengths):]:
            for dev_id in part2dev:
                dev_losing_part = self.devs[dev_id]
                dev_losing_part['parts'] -= 1
                removed_parts -= 1
        self._replica2part2dev = self._replica2part2dev[:len(desired_lengths)]
    else:
        self._replica2part2dev = []
    for (replica, desired_length) in enumerate(desired_lengths):
        if (replica < len(self._replica2part2dev)):
            part2dev = self._replica2part2dev[replica]
            if (len(part2dev) < desired_length):
                for part in range(len(part2dev), desired_length):
                    to_assign[part].append(replica)
                    part2dev.append(NONE_DEV)
                    new_parts += 1
            elif (len(part2dev) > desired_length):
                for part in range(desired_length, len(part2dev)):
                    dev_losing_part = self.devs[part2dev[part]]
                    dev_losing_part['parts'] -= 1
                    removed_parts -= 1
                self._replica2part2dev[replica] = part2dev[:desired_length]
        else:
            for part in range(desired_length):
                to_assign[part].append(replica)
                new_parts += 1
            self._replica2part2dev.append(array('H', itertools.repeat(NONE_DEV, desired_length)))
    self.logger.debug('%d    new    parts    and    %d    removed    parts    from    replica-count    change', new_parts, removed_parts)
