junrao commented on code in PR #14242:
URL: https://github.com/apache/kafka/pull/14242#discussion_r1556161125
##########
server-common/src/main/java/org/apache/kafka/server/common/CheckpointFile.java:
##########
@@ -72,18 +72,20 @@ public CheckpointFile(File file,
tempPath = Paths.get(absolutePath + ".tmp");
}
- public void write(Collection<T> entries) throws IOException {
+ public void write(Collection<T> entries, boolean sync) throws IOException {
synchronized (lock) {
// write to temp file and then swap with the existing file
try (FileOutputStream fileOutputStream = new
FileOutputStream(tempPath.toFile());
BufferedWriter writer = new BufferedWriter(new
OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8))) {
CheckpointWriteBuffer<T> checkpointWriteBuffer = new
CheckpointWriteBuffer<>(writer, version, formatter);
checkpointWriteBuffer.write(entries);
writer.flush();
- fileOutputStream.getFD().sync();
+ if (sync) {
+ fileOutputStream.getFD().sync();
Review Comment:
@ocadaruma : I realized a potential issue with this change. The issue is
that if sync is false, we don't force a flush to disk. However, the OS could
flush partial content of the leader epoch file. If the broker has a hard
failure, the leader epoch file could be corrupted. In the recovery path, since
we always expect the leader epoch file to be well-formed, a corrupted leader
epoch file will fail the recovery.
--
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]