private void maybeUpdateLastKnownLeader(PartitionChangeRecord record) {
        if (!useLastKnownLeaderInBalancedRecovery || !eligibleLeaderReplicasEnabled) return;
        if (record.isr() != null && record.isr().isEmpty() && (partition.lastKnownElr.length != 1 ||
            partition.lastKnownElr[0] != partition.leader)) {
            // Only update the last known leader when the first time the partition becomes leaderless.
            record.setLastKnownElr(Collections.singletonList(partition.leader));
        } else if ((record.leader() >= 0 || (partition.leader != NO_LEADER && record.leader() != NO_LEADER))
            && partition.lastKnownElr.length > 0) {
            // Clear the LastKnownElr field if the partition will have or continues to have a valid leader.
            record.setLastKnownElr(Collections.emptyList());
        }
    }
Trigger a leader epoch bump if one is needed because of an ISR shrink.

Note that it's important to call this function only after we have set the ISR field in
the PartitionChangeRecord.
metadata/src/main/java/org/apache/kafka/controller/PartitionChangeBuilder.java