From ff8ce2c575ec579710694528609d5dcfe2356fa0 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Wed, 30 May 2018 10:15:12 +0200 Subject: [PATCH] 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. --- .../java/org/elasticsearch/gateway/MetaDataStateFormat.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/gateway/MetaDataStateFormat.java b/server/src/main/java/org/elasticsearch/gateway/MetaDataStateFormat.java index f6c190fee09..0821b176e75 100644 --- a/server/src/main/java/org/elasticsearch/gateway/MetaDataStateFormat.java +++ b/server/src/main/java/org/elasticsearch/gateway/MetaDataStateFormat.java @@ -141,9 +141,10 @@ public abstract class MetaDataStateFormat { Path finalPath = stateLocation.resolve(fileName); try { Files.copy(finalStatePath, tmpPath); + IOUtils.fsync(tmpPath, false); // fsync the state file // we are on the same FileSystem / Partition here we can do an atomic move Files.move(tmpPath, finalPath, StandardCopyOption.ATOMIC_MOVE); - IOUtils.fsync(stateLocation, true); // we just fsync the dir here.. + IOUtils.fsync(stateLocation, true); } finally { Files.deleteIfExists(tmpPath); }