ElectionResult electLeader() {
        if (election == Election.PREFERRED) {
            return electPreferredLeader();
        }

        return electAnyLeader();
    }
Perform leader election based on the partition state and leader election type.

See documentation for the Election type to see more details on the election types supported.
metadata/src/main/java/org/apache/kafka/controller/PartitionChangeBuilder.java