This is an automated email from the ASF dual-hosted git repository. dragonyliu pushed a commit to branch branch-2 in repository https://gitbox.apache.org/repos/asf/ratis.git
commit 491f85eeeab192f55d25b270f78e459ee62e954e Author: William Song <[email protected]> AuthorDate: Wed Aug 24 07:42:21 2022 +0800 RATIS-1681. Use atomic_move to enhance robustness (#720) (cherry picked from commit 8267e87ac42bb32323555e18db1a11dd6d930a6b) --- .../src/main/java/org/apache/ratis/util/FileUtils.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ratis-common/src/main/java/org/apache/ratis/util/FileUtils.java b/ratis-common/src/main/java/org/apache/ratis/util/FileUtils.java index 28a6cc197..40a51e9f9 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/FileUtils.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/FileUtils.java @@ -76,9 +76,15 @@ public interface FileUtils { } static void move(Path src, Path dst) throws IOException { - LogUtils.runAndLog(LOG, + try { + LogUtils.runAndLog(LOG, + () -> Files.move(src, dst, StandardCopyOption.ATOMIC_MOVE), + () -> "Atomic Files.move " + src + " to " + dst); + } catch (AtomicMoveNotSupportedException e) { + LogUtils.runAndLog(LOG, () -> Files.move(src, dst), - () -> "Files.move " + src + " to " + dst); + () -> "Atomic move not supported. Fallback to Files.move " + src + " to " + dst); + } } /**
