소스 검색

.es_temp_file remains after system crash, causing it not to start again #21007

When system starts, it creates a temporary file named .es_temp_file to ensure the data directories are writable.

If system crashes after creating the .es_temp_file but before deleting this file, next time the system will not be able to start because the Files.createFile(resolve) will throw an exception if the file already exists.
Li Weinan 9 년 전
부모
커밋
d4e42b77a5
1개의 변경된 파일6개의 추가작업 그리고 1개의 파일을 삭제
  1. 6 1
      core/src/main/java/org/elasticsearch/env/NodeEnvironment.java

+ 6 - 1
core/src/main/java/org/elasticsearch/env/NodeEnvironment.java

@@ -1002,11 +1002,16 @@ public final class NodeEnvironment  implements Closeable {
     private static void tryWriteTempFile(Path path) throws IOException {
         if (Files.exists(path)) {
             Path resolve = path.resolve(".es_temp_file");
+            boolean tempFileCreated = false;
             try {
                 Files.createFile(resolve);
-                Files.deleteIfExists(resolve);
+                tempFileCreated = true;
             } catch (IOException ex) {
                 throw new IOException("failed to write in data directory [" + path + "] write permission is required", ex);
+            } finally {
+                if (tempFileCreated) {
+                    Files.deleteIfExists(resolve);
+                }
             }
         }
     }