hachikuji commented on a change in pull request #11186: URL: https://github.com/apache/kafka/pull/11186#discussion_r700614819
########## 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: To be honest, it wasn't clear to me why we passed the unclean flag through a function while we use the builder to specify whether preferred election is desired. It would be nice if we could pass through the `ElectionType` directly to make the pattern more consistent and I agree that having an `ANY` option might enable that. -- 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