junrao commented on code in PR #16660:
URL: https://github.com/apache/kafka/pull/16660#discussion_r1688327363


##########
storage/src/main/java/org/apache/kafka/storage/internals/epoch/LeaderEpochFileCache.java:
##########
@@ -525,10 +525,13 @@ private void writeToFile() {
         }
     }
 
-    private void writeToFileForTruncation() {
+    private void writeIfDirExists() {
         lock.readLock().lock();
         try {
-            checkpoint.writeForTruncation(epochs.values());
+            // Write epoch entries under the read lock to avoid older epoch 
entries overwriting the newer epoch entries.
+            // If we take a snapshot of the epoch entries here and flush to 
disk outside the read lock,
+            // the leader epoch file may have correctness issue, because the 
new epoch entry may already in the file.

Review Comment:
   Perhaps rewording to sth like the following?
   
   If we take a snapshot of the epoch entries here and flush them to disk 
outside the read lock, by the time of flushing, the leader epoch file may 
already be updated with newer epoch entries. Those newer entries will then be 
overridden with the old snapshot.



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