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:
parent
68676f8cf1
commit
d3f8329a3d
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue