private void performReassignments() {
        boolean modified;
        boolean reassignmentOccurred;
        // Repeat reassignment until no partition can be moved to improve the balance.
        do {
            modified = false;
            reassignmentOccurred = false;
            // Reassign all reassignable partitions sorted in descending order
            // by totalPartitions/number of subscribed members,
            // until the full list is processed or a balance is achieved.
            List<TopicIdPartition> reassignablePartitions = sortTopicIdPartitions(unassignedPartitions);

            for (TopicIdPartition reassignablePartition : reassignablePartitions) {
                // Only check if there is any change in balance if any moves were made.
                if (reassignmentOccurred && isBalanced()) {
                    return;
                }
                reassignmentOccurred = false;

                // The topicIdPartition must have at least two members.
                if (membersPerTopic.get(reassignablePartition.topicId()).size() <= 1)
                    throw new PartitionAssignorException(String.format("Expected more than one potential member for " +
                        "topicIdPartition '%s'", reassignablePartition)
                    );

                // The topicIdPartition must have a current target owner.
                String currentTargetOwner = partitionOwnerInTargetAssignment.get(reassignablePartition);
                if (currentTargetOwner == null)
                    throw new PartitionAssignorException(String.format("Expected topicIdPartition '%s' to be assigned " +
                        "to a member", reassignablePartition)
                    );

                for (String otherMember : membersPerTopic.get(reassignablePartition.topicId())) {
                    if (assignmentManager.targetAssignmentSize(currentTargetOwner) > assignmentManager.targetAssignmentSize(otherMember) + 1) {
                        reassignPartition(reassignablePartition);
                        modified = true;
                        reassignmentOccurred = true;
                        break;
                    }
                }
            }
        } while (modified);
    }
Performs reassignments of partitions to balance the load across members.
This method iteratively reassigns partitions until no further moves can improve the balance.

The method uses a do-while loop to ensure at least one pass over the partitions and continues
reassigning as long as there are modifications to the current assignments. It checks for balance
after each reassignment and exits if the balance is achieved.

@throws PartitionAssignorException if there are inconsistencies in expected members per partition
        or if a partition is expected to already be assigned but isn't.
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/assignor/UniformHeterogeneousAssignmentBuilder.java