hudeqi commented on code in PR #9633:
URL: https://github.com/apache/kafka/pull/9633#discussion_r1418840610


##########
core/src/main/scala/kafka/log/Log.scala:
##########
@@ -2069,6 +2069,15 @@ class Log(@volatile private var _dir: File,
         throw new IllegalArgumentException(s"Cannot truncate partition 
$topicPartition to a negative offset (%d).".format(targetOffset))
       if (targetOffset >= logEndOffset) {
         info(s"Truncating to $targetOffset has no effect as the largest offset 
in the log is ${logEndOffset - 1}")
+
+        // Always truncate epoch cache since we may have a conflicting epoch 
entry at the
+        // end of the log from the leader. This could happen if this broker 
was a leader
+        // and inserted the first start offset entry, but then failed to 
append any entries
+        // before another leader was elected.
+        lock synchronized {
+          leaderEpochCache.foreach(_.truncateFromEnd(logEndOffset))

Review Comment:
   Hi, I have a question about this PR: if the follower here has written some 
data since it became the leader last time, so that the logEndOffset is greater 
than the start offset of the newly inserted leader epoch entry, it is not 
satisfied with this change here. Will it still fall into the infinite truncate 
mentioned in this issue? @hachikuji @junrao 



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to