CalvinConfluent commented on code in PR #14312:
URL: https://github.com/apache/kafka/pull/14312#discussion_r1361388430


##########
metadata/src/main/java/org/apache/kafka/controller/PartitionChangeBuilder.java:
##########
@@ -328,13 +346,38 @@ public Optional<ApiMessageAndVersion> build() {
 
         completeReassignmentIfNeeded();
 
+        boolean isElrEnabled = metadataVersion.isElrSupported();
+        if (isElrEnabled) {
+            populateTargetElr();
+        }
+
         tryElection(record);
 
         triggerLeaderEpochBumpIfNeeded(record);
 
-        if (record.isr() == null && !targetIsr.isEmpty() && 
!targetIsr.equals(Replicas.toList(partition.isr))) {
-            // Set the new ISR if it is different from the current ISR and 
unclean leader election didn't already set it.
-            record.setIsr(targetIsr);
+        // During the leader election, it can set the record isr if an unclean 
leader election happens.
+        boolean isCleanLeaderElection = record.isr() == null;
+
+        // Clean the ELR related fields if it is an unclean election or ELR is 
disabled.
+        if (!isCleanLeaderElection || !isElrEnabled) {
+            targetElr = Collections.emptyList();
+            targetLastKnownElr = Collections.emptyList();
+        }
+
+        if (!targetElr.equals(Replicas.toList(partition.elr))) {
+            record.setEligibleLeaderReplicas(targetElr);
+        }
+        if 
(!targetLastKnownElr.equals(Replicas.toList(partition.lastKnownElr))) {
+            record.setLastKnownELR(targetLastKnownElr);
+        }
+
+        // The record.isr is null if it is a clean election. In this case, it 
will
+        // 1. Set the new ISR if it is different from the current ISR.
+        // 2. Set the new ELR/LastKnowElr if it is different from the current 
ones.
+        if (isCleanLeaderElection) {

Review Comment:
   The file has been updated, and this part has been removed. 
   Yeah, it may be straightforward to call it "isIsrSet". But it is more 
comprehensive to translate to isCleanLeaderElection because we also need to 
reset the ELR when unclean leader election happens(see the latest update). it 
may not be clear to connect why ELR has to be cleaned if record.isr() is set.



##########
metadata/src/main/java/org/apache/kafka/controller/PartitionChangeBuilder.java:
##########
@@ -328,13 +346,38 @@ public Optional<ApiMessageAndVersion> build() {
 
         completeReassignmentIfNeeded();
 
+        boolean isElrEnabled = metadataVersion.isElrSupported();
+        if (isElrEnabled) {
+            populateTargetElr();
+        }
+
         tryElection(record);
 
         triggerLeaderEpochBumpIfNeeded(record);
 
-        if (record.isr() == null && !targetIsr.isEmpty() && 
!targetIsr.equals(Replicas.toList(partition.isr))) {
-            // Set the new ISR if it is different from the current ISR and 
unclean leader election didn't already set it.
-            record.setIsr(targetIsr);
+        // During the leader election, it can set the record isr if an unclean 
leader election happens.
+        boolean isCleanLeaderElection = record.isr() == null;
+
+        // Clean the ELR related fields if it is an unclean election or ELR is 
disabled.
+        if (!isCleanLeaderElection || !isElrEnabled) {
+            targetElr = Collections.emptyList();
+            targetLastKnownElr = Collections.emptyList();
+        }
+
+        if (!targetElr.equals(Replicas.toList(partition.elr))) {
+            record.setEligibleLeaderReplicas(targetElr);
+        }
+        if 
(!targetLastKnownElr.equals(Replicas.toList(partition.lastKnownElr))) {
+            record.setLastKnownELR(targetLastKnownElr);
+        }
+
+        // The record.isr is null if it is a clean election. In this case, it 
will
+        // 1. Set the new ISR if it is different from the current ISR.
+        // 2. Set the new ELR/LastKnowElr if it is different from the current 
ones.

Review Comment:
   Removed.



-- 
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