Skip to content

Commit ff8ce2c

Browse files
authored
Fsync state file before exposing it (#30929)
With multiple data paths, we write the state files for index metadata to all data paths. We only properly fsync on the first location, though. For other locations, we possibly expose the file before its contents is properly fsynced. This can lead to situations where, after a crash, and where the first data path is not available anymore, ES will see a partially-written state file, preventing the node to start up.
1 parent e33d107 commit ff8ce2c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

server/src/main/java/org/elasticsearch/gateway/MetaDataStateFormat.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ public void close() throws IOException {
141141
Path finalPath = stateLocation.resolve(fileName);
142142
try {
143143
Files.copy(finalStatePath, tmpPath);
144+
IOUtils.fsync(tmpPath, false); // fsync the state file
144145
// we are on the same FileSystem / Partition here we can do an atomic move
145146
Files.move(tmpPath, finalPath, StandardCopyOption.ATOMIC_MOVE);
146-
IOUtils.fsync(stateLocation, true); // we just fsync the dir here..
147+
IOUtils.fsync(stateLocation, true);
147148
} finally {
148149
Files.deleteIfExists(tmpPath);
149150
}

0 commit comments

Comments
 (0)