cmccabe commented on code in PR #16866:
URL: https://github.com/apache/kafka/pull/16866#discussion_r1727811280


##########
metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java:
##########
@@ -1632,21 +1632,58 @@ boolean arePartitionLeadersImbalanced() {
     }
 
     /**
-     * Attempt to elect a preferred leader for all topic partitions which have 
a leader that is not the preferred replica.
+     * Check if we can do an election for partitions with no leader or a 
leader other than the preferred one.
      *
      * 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
      */
-    ControllerResult<Boolean> maybeBalancePartitionLeaders() {
+    ControllerResult<Boolean> maybeAdjustPartitionLeaders() {
         List<ApiMessageAndVersion> records = new ArrayList<>();
+        maybeTriggerUncleanLeaderElectionForLeaderlessPartitions(records, 
maxElectionsPerImbalance);
+        maybeTriggerLeaderChangeForPartitionsWithoutPreferredLeader(records, 
maxElectionsPerImbalance);
+        boolean rescheduleImmediately = records.size() >= 
maxElectionsPerImbalance;
+        return ControllerResult.of(records, rescheduleImmediately);
+    }
 
-        boolean rescheduleImmediately = false;
+    /**
+     * Trigger unclean leader election for partitions without leader (visiable 
for testing)
+     *
+     * @param records  The record list to append to.
+     */
+    void maybeTriggerUncleanLeaderElectionForLeaderlessPartitions(

Review Comment:
   I changed the test to configure the periodic task to run more frequently. I 
would prefer not to do the edge-triggered thing here since it's complex, and 
people who want quick response times should just use the existing 
`electLeaders` API which works immediately and requires no configuration.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to