add explit fsync on checkpoint write

Fixes #6430
This commit is contained in:
Colin Surprenant 2016-12-16 13:54:13 -05:00 committed by Jordan Sissel
parent 824c3ca476
commit 1d156aaf14

View file

@ -5,8 +5,13 @@ import org.logstash.ackedqueue.Checkpoint;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.WRITE;
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
import static java.nio.file.StandardOpenOption.DSYNC;
public class FileCheckpointIO implements CheckpointIO {
// Checkpoint file structure
@ -50,10 +55,11 @@ public class FileCheckpointIO implements CheckpointIO {
@Override
public void write(String fileName, Checkpoint checkpoint) throws IOException {
OpenOption[] options = new OpenOption[] { WRITE, CREATE, TRUNCATE_EXISTING, DSYNC };
Path path = Paths.get(dirPath, fileName);
final byte[] buffer = new byte[BUFFER_SIZE];
write(checkpoint, buffer);
Files.write(path, buffer);
Files.write(path, buffer, options);
}
@Override