def add_replica(self, partition_name, count=1):
        """Increase the replication-factor for a partition.

        The replication-group to add to is determined as follows:
            1. Find all replication-groups that have brokers not already
                replicating the partition.
            2. Of these, find replication-groups that have fewer than the
                average number of replicas for this partition.
            3. Choose the replication-group with the fewest overall partitions.

        :param partition_name: (topic_id, partition_id) of the partition to add
            replicas of.
        :param count: The number of replicas to add.
        :raises InvalidReplicationFactorError when the resulting replication
        factor is greater than the number of brokers in the cluster.
        """
        try:
            partition = self.cluster_topology.partitions[partition_name]
        except KeyError:
            raise InvalidPartitionError(
                "Partition name {name} not found".format(name=partition_name),
            )
        if partition.replication_factor + count > len(self.cluster_topology.brokers):
            raise InvalidReplicationFactorError(
                "Cannot increase replication factor to {0}. There are only "
                "{1} brokers."
                .format(
                    partition.replication_factor + count,
                    len(self.cluster_topology.brokers),
                )
            )

        non_full_rgs = [
            rg
            for rg in self.cluster_topology.rgs.values()
            if rg.count_replica(partition) < len(rg.brokers)
        ]
        for _ in range(count):
            total_replicas = sum(
                rg.count_replica(partition)
                for rg in non_full_rgs
            )
            opt_replicas, _ = compute_optimum(
                len(non_full_rgs),
                total_replicas,
            )
            under_replicated_rgs = [
                rg
                for rg in non_full_rgs
                if rg.count_replica(partition) < opt_replicas
            ]
            candidate_rgs = under_replicated_rgs or non_full_rgs
            rg = min(candidate_rgs, key=lambda rg: len(rg.partitions))

            rg.add_replica(partition)

            if rg.count_replica(partition) >= len(rg.brokers):
                non_full_rgs.remove(rg)
Increase the replication-factor for a partition.

        The replication-group to add to is determined as follows:
            1. Find all replication-groups that have brokers not already
                replicating the partition.
            2. Of these, find replication-groups that have fewer than the
                average number of replicas for this partition.
            3. Choose the replication-group with the fewest overall partitions.

        :param partition_name: (topic_id, partition_id) of the partition to add
            replicas of.
        :param count: The number of replicas to add.
        :raises InvalidReplicationFactorError when the resulting replication
        factor is greater than the number of brokers in the cluster.