fvaleri commented on code in PR #24034:
URL: https://github.com/apache/kafka/pull/24034#discussion_r4526628424


##########
metadata/src/main/java/org/apache/kafka/controller/PartitionChangeBuilder.java:
##########
@@ -458,13 +460,30 @@ public Optional<ApiMessageAndVersion> build() {
             record.setLeaderRecoveryState(targetLeaderRecoveryState.value());
         }
 
+        maybeSetLeaderEpoch(record);
+
         if (changeRecordIsNoOp(record)) {
             return Optional.empty();
         } else {
             return Optional.of(new ApiMessageAndVersion(record, 
metadataVersion.partitionChangeRecordVersion()));
         }
     }
 
+    /**
+     * Set the new leader epoch in the record if the metadata version supports 
it.
+     *
+     * Setting the leader field signals a leader epoch bump, so this must be 
called after every
+     * step that may set the leader field.
+     */
+    private void maybeSetLeaderEpoch(PartitionChangeRecord record) {
+        if (!metadataVersion.isClusterMirrorSupported()) {
+            return;
+        }
+        if (record.leader() != NO_LEADER_CHANGE) {
+            record.setLeaderEpoch(partition.leaderEpoch + 1);
+        }
+    }

Review Comment:
   Here we should handle a new `targetLeaderEpoch` field, that will be set by 
the `ReplicationControlManager` when handling `BumpLeaderEpochs` requests.
   
   ```sh
   if (targetLeaderEpoch >= 0) {
       record.setLeaderEpoch(Math.max(targetLeaderEpoch, 
partition.leaderEpoch));
   } else if (record.leader() != NO_LEADER_CHANGE) {
       record.setLeaderEpoch(partition.leaderEpoch + 1);
   }
   ```
   
   Max ensures the epoch never decreases. If the partition already moved past 
the bump target, we keep the current epoch.
   



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