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,17 +897,20 @@ public final class NodeEnvironment extends AbstractComponent implements Closeabl
|
||||||
for (NodePath nodePath : nodePaths) {
|
for (NodePath nodePath : nodePaths) {
|
||||||
assert Files.isDirectory(nodePath.path) : nodePath.path + " is not a directory";
|
assert Files.isDirectory(nodePath.path) : nodePath.path + " is not a directory";
|
||||||
final Path src = nodePath.path.resolve("__es__.tmp");
|
final Path src = nodePath.path.resolve("__es__.tmp");
|
||||||
Files.createFile(src);
|
|
||||||
final Path target = nodePath.path.resolve("__es__.final");
|
final Path target = nodePath.path.resolve("__es__.final");
|
||||||
try {
|
try {
|
||||||
|
Files.createFile(src);
|
||||||
Files.move(src, target, StandardCopyOption.ATOMIC_MOVE);
|
Files.move(src, target, StandardCopyOption.ATOMIC_MOVE);
|
||||||
} catch (AtomicMoveNotSupportedException ex) {
|
} catch (AtomicMoveNotSupportedException ex) {
|
||||||
throw new IllegalStateException("atomic_move is not supported by the filesystem on path ["
|
throw new IllegalStateException("atomic_move is not supported by the filesystem on path ["
|
||||||
+ nodePath.path
|
+ nodePath.path
|
||||||
+ "] atomic_move is required for elasticsearch to work correctly.", ex);
|
+ "] atomic_move is required for elasticsearch to work correctly.", ex);
|
||||||
} finally {
|
} finally {
|
||||||
Files.deleteIfExists(src);
|
try {
|
||||||
Files.deleteIfExists(target);
|
Files.deleteIfExists(src);
|
||||||
|
} finally {
|
||||||
|
Files.deleteIfExists(target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue