jsancio commented on a change in pull request #11186: URL: https://github.com/apache/kafka/pull/11186#discussion_r697544035
########## File path: metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java ########## @@ -856,21 +867,24 @@ ApiError electLeader(String topic, int partitionId, boolean uncleanOk, return new ApiError(UNKNOWN_TOPIC_OR_PARTITION, "No such partition as " + topic + "-" + partitionId); } + if ((electionType == ElectionType.PREFERRED && partition.hasPreferredLeader()) + || (electionType == ElectionType.UNCLEAN && partition.hasLeader())) { + return new ApiError(Errors.ELECTION_NOT_NEEDED); + } + PartitionChangeBuilder builder = new PartitionChangeBuilder(partition, topicId, partitionId, r -> clusterControl.unfenced(r), - () -> uncleanOk || configurationControl.uncleanLeaderElectionEnabledForTopic(topic)); - builder.setAlwaysElectPreferredIfPossible(true); + () -> electionType == ElectionType.UNCLEAN); + + builder.setAlwaysElectPreferredIfPossible(electionType == ElectionType.PREFERRED); Review comment: Outside the scope of this change but do you think that it would help if internally we supported 3 elections: PREFERRED, ANY, UNCLEAN. With this enum we can change the constructor for `PartitionChangeBuilder` to take a function that returns this enum. Would that help with the API for `PartitionChangeBuilder` and address all of its uses? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org