Currently we skip log truncation for followers if a LeaderAndIsr request is received, but the leader does not change. This can lead to log divergence if the follower missed a leader change before the current known leader was reelected. Basically the problem is that the leader may truncate its own log prior to becoming leader again, so the follower would need to reconcile its log again.
For example, suppose that we have three replicas: r1, r2, and r3. Initially, r1 is the leader in epoch 0 and writes one record at offset 0. r3 replicates this successfully.
Suppose then that r2 becomes leader in epoch 1. r1 notices the leader change and truncates, but r3 for whatever reason, does not.
Now suppose that r2 fails and r1 becomes the leader in epoch 2. Immediately it writes a new record:
If the replica continues fetching with the old epoch, we can have log divergence as noted in
KAFKA-6880. However, if r3 successfully receives the new LeaderAndIsr request which updates the epoch to 2, but skips the truncation, then the logs will stay inconsistent.