void validateManualPartitionAssignment(
        List<Integer> assignment,
        OptionalInt replicationFactor
    ) {
        if (assignment.isEmpty()) {
            throw new InvalidReplicaAssignmentException("The manual partition " +
                "assignment includes an empty replica list.");
        }
        List<Integer> sortedBrokerIds = new ArrayList<>(assignment);
        sortedBrokerIds.sort(Integer::compare);
        Integer prevBrokerId = null;
        for (Integer brokerId : sortedBrokerIds) {
            BrokerRegistration brokerRegistration = clusterControl.brokerRegistrations().get(brokerId);
            if (brokerRegistration == null) {
                throw new InvalidReplicaAssignmentException("The manual partition " +
                    "assignment includes broker " + brokerId + ", but no such broker is " +
                    "registered.");
            }
            if (brokerRegistration.fenced()) {
                throw new InvalidReplicaAssignmentException("The manual partition " +
                    "assignment includes broker " + brokerId + ", but this broker is " +
                    "currently fenced.");
            }
            if (brokerId.equals(prevBrokerId)) {
                throw new InvalidReplicaAssignmentException("The manual partition " +
                    "assignment includes the broker " + prevBrokerId + " more than " +
                    "once.");
            }
            prevBrokerId = brokerId;
        }
        if (replicationFactor.isPresent() &&
                sortedBrokerIds.size() != replicationFactor.getAsInt()) {
            throw new InvalidReplicaAssignmentException("The manual partition " +
                "assignment includes a partition with " + sortedBrokerIds.size() +
                " replica(s), but this is not consistent with previous " +
                "partitions, which have " + replicationFactor.getAsInt() + " replica(s).");
        }
    }
Attempt to elect a preferred leader for all topic partitions which have a leader that is not the preferred replica.

The response() method in the return object is true if this method returned without electing all possible preferred replicas.
The quorum controller should reschedule this operation immediately if it is true.

@return All of the election records and if there may be more available preferred replicas to elect as leader
metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java