Tighten ensure atomic move cleanup

This commit tightens the cleanup after possible errors while ensuring
the filesystem supports atomic move.

Relates #19309
This commit is contained in:
Jason Tedor 2016-07-07 14:40:05 -04:00 committed by GitHub
parent 68676f8cf1
commit d3f8329a3d
1 changed files with 6 additions and 3 deletions

View File

@ -897,20 +897,23 @@ public final class NodeEnvironment extends AbstractComponent implements Closeabl
for (NodePath nodePath : nodePaths) {
assert Files.isDirectory(nodePath.path) : nodePath.path + " is not a directory";
final Path src = nodePath.path.resolve("__es__.tmp");
Files.createFile(src);
final Path target = nodePath.path.resolve("__es__.final");
try {
Files.createFile(src);
Files.move(src, target, StandardCopyOption.ATOMIC_MOVE);
} catch (AtomicMoveNotSupportedException ex) {
throw new IllegalStateException("atomic_move is not supported by the filesystem on path ["
+ nodePath.path
+ "] atomic_move is required for elasticsearch to work correctly.", ex);
} finally {
try {
Files.deleteIfExists(src);
} finally {
Files.deleteIfExists(target);
}
}
}
}
Settings getSettings() { // for testing
return settings;