.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.
This commit is contained in:
parent
f6f129b21f
commit
d4e42b77a5
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue