You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by wi...@apache.org on 2023/01/05 05:50:33 UTC

[ratis] 01/01: Revert "create parent directory (#802)"

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

williamsong pushed a commit to branch revert-802-recover_md5
in repository https://gitbox.apache.org/repos/asf/ratis.git

commit 986945fc44f9438e6617cee9a28df83cb96ea4c0
Author: William Song <48...@users.noreply.github.com>
AuthorDate: Thu Jan 5 13:50:26 2023 +0800

    Revert "create parent directory (#802)"
    
    This reverts commit c2d103ef9d3d9d7d2c199b8e28c7709f64ea71e9.
---
 .../src/main/java/org/apache/ratis/util/FileUtils.java    | 15 ---------------
 .../java/org/apache/ratis/server/impl/ServerState.java    |  2 +-
 .../org/apache/ratis/server/storage/SnapshotManager.java  |  5 +++--
 3 files changed, 4 insertions(+), 18 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 be736b09f..15ec6ea94 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
@@ -71,21 +71,6 @@ public interface FileUtils {
         () -> "Files.createDirectories " + dir);
   }
 
-  static void createDirectoriesDeleteExistingNonDirectory(File dir) throws IOException {
-    createDirectoriesDeleteExistingNonDirectory(dir.toPath());
-  }
-
-  static void createDirectoriesDeleteExistingNonDirectory(Path dir) throws IOException {
-    try {
-      createDirectories(dir);
-    } catch (FileAlreadyExistsException e) {
-      LOG.warn("Failed to create directory " + dir
-          + " since it already exists as a non-directory.  Trying to delete it ...", e);
-      delete(dir);
-      createDirectories(dir);
-    }
-  }
-
   static void move(File src, File dst) throws IOException {
     move(src.toPath(), dst.toPath());
   }
diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
index e0832c9be..826c4cff8 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
@@ -441,7 +441,7 @@ class ServerState {
     // TODO: verify that we need to install the snapshot
     StateMachine sm = server.getStateMachine();
     sm.pause(); // pause the SM to prepare for install snapshot
-    snapshotManager.installSnapshot(request, sm);
+    snapshotManager.installSnapshot(request, sm, getStorage().getStorageDir());
     updateInstalledSnapshotIndex(TermIndex.valueOf(request.getSnapshotChunk().getTermIndex()));
   }
 
diff --git a/ratis-server/src/main/java/org/apache/ratis/server/storage/SnapshotManager.java b/ratis-server/src/main/java/org/apache/ratis/server/storage/SnapshotManager.java
index 1e2f70a68..dbde86940 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/storage/SnapshotManager.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/storage/SnapshotManager.java
@@ -77,7 +77,8 @@ public class SnapshotManager {
         new File(dir.get().getRoot(), c.getFilename()).toPath()).toString();
   }
 
-  public void installSnapshot(InstallSnapshotRequestProto request, StateMachine stateMachine) throws IOException {
+  public void installSnapshot(InstallSnapshotRequestProto request, StateMachine stateMachine, RaftStorageDirectory dir)
+      throws IOException {
     final InstallSnapshotRequestProto.SnapshotChunkProto snapshotChunkRequest = request.getSnapshotChunk();
     final long lastIncludedIndex = snapshotChunkRequest.getTermIndex().getIndex();
 
@@ -101,7 +102,7 @@ public class SnapshotManager {
       }
 
       final File tmpSnapshotFile = new File(tmpDir, getRelativePath.apply(chunk));
-      FileUtils.createDirectoriesDeleteExistingNonDirectory(tmpSnapshotFile.getParentFile());
+      FileUtils.createDirectories(tmpSnapshotFile);
 
       FileOutputStream out = null;
       try {