Skip to content

Commit d15aa21

Browse files
committed
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 a22121b commit d15aa21

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,10 @@ public void close() throws IOException {
149149
Path finalPath = stateLocation.resolve(fileName);
150150
try {
151151
Files.copy(finalStatePath, tmpPath);
152+
IOUtils.fsync(tmpPath, false); // fsync the state file
152153
// we are on the same FileSystem / Partition here we can do an atomic move
153154
Files.move(tmpPath, finalPath, StandardCopyOption.ATOMIC_MOVE);
154-
IOUtils.fsync(stateLocation, true); // we just fsync the dir here..
155+
IOUtils.fsync(stateLocation, true);
155156
} finally {
156157
Files.deleteIfExists(tmpPath);
157158
}

0 commit comments

Comments
 (0)