You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by sz...@apache.org on 2022/08/23 23:42:26 UTC

[ratis] branch master updated: RATIS-1681. Use atomic_move to enhance robustness (#720)

This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new 8267e87ac RATIS-1681. Use atomic_move to enhance robustness (#720)
8267e87ac is described below

commit 8267e87ac42bb32323555e18db1a11dd6d930a6b
Author: William Song <48...@users.noreply.github.com>
AuthorDate: Wed Aug 24 07:42:21 2022 +0800

    RATIS-1681. Use atomic_move to enhance robustness (#720)
---
 .../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);
+    }
   }
 
   /**