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/02/10 08:16:55 UTC

[ratis] 01/02: cherry-pick merge

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

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

commit 55abd1de57e552af5db9bdd17072f3ba0b2be532
Author: William Song <48...@users.noreply.github.com>
AuthorDate: Thu Jan 5 13:45:42 2023 +0800

    cherry-pick merge
---
 pom.xml                                                   |  2 +-
 ratis-assembly/pom.xml                                    |  2 +-
 ratis-client/pom.xml                                      |  2 +-
 ratis-common/pom.xml                                      |  2 +-
 .../src/main/java/org/apache/ratis/util/FileUtils.java    | 15 +++++++++++++++
 ratis-docs/pom.xml                                        |  2 +-
 ratis-examples/pom.xml                                    |  2 +-
 ratis-experiments/pom.xml                                 |  2 +-
 ratis-grpc/pom.xml                                        |  2 +-
 ratis-metrics/pom.xml                                     |  2 +-
 ratis-netty/pom.xml                                       |  2 +-
 ratis-proto/pom.xml                                       |  2 +-
 ratis-replicated-map/pom.xml                              |  2 +-
 ratis-resource-bundle/pom.xml                             |  2 +-
 ratis-server-api/pom.xml                                  |  2 +-
 ratis-server/pom.xml                                      |  2 +-
 .../java/org/apache/ratis/server/impl/ServerState.java    |  2 +-
 .../org/apache/ratis/server/storage/SnapshotManager.java  |  8 +++-----
 ratis-shell/pom.xml                                       |  2 +-
 ratis-test/pom.xml                                        |  2 +-
 ratis-tools/pom.xml                                       |  2 +-
 21 files changed, 37 insertions(+), 24 deletions(-)

diff --git a/pom.xml b/pom.xml
index a63135097..d3a9efe29 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,7 +24,7 @@
 
   <artifactId>ratis</artifactId>
   <groupId>org.apache.ratis</groupId>
-  <version>2.4.2-SNAPSHOT</version>
+  <version>2.4.2-SNAPSHOT-1</version>
   <name>Apache Ratis</name>
   <packaging>pom</packaging>
   <description>
diff --git a/ratis-assembly/pom.xml b/ratis-assembly/pom.xml
index 19eee578b..da903b2c8 100644
--- a/ratis-assembly/pom.xml
+++ b/ratis-assembly/pom.xml
@@ -17,7 +17,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-assembly</artifactId>
diff --git a/ratis-client/pom.xml b/ratis-client/pom.xml
index d307a1561..ef241bd63 100644
--- a/ratis-client/pom.xml
+++ b/ratis-client/pom.xml
@@ -17,7 +17,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-client</artifactId>
diff --git a/ratis-common/pom.xml b/ratis-common/pom.xml
index 3f2f7ddba..a0de8f3f3 100644
--- a/ratis-common/pom.xml
+++ b/ratis-common/pom.xml
@@ -17,7 +17,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-common</artifactId>
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 40a51e9f9..e50edaf6d 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,6 +71,21 @@ 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-docs/pom.xml b/ratis-docs/pom.xml
index 380fa9ac4..2d6838f0a 100644
--- a/ratis-docs/pom.xml
+++ b/ratis-docs/pom.xml
@@ -20,7 +20,7 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-docs</artifactId>
diff --git a/ratis-examples/pom.xml b/ratis-examples/pom.xml
index 33f4b4ae8..87b0b9dd6 100644
--- a/ratis-examples/pom.xml
+++ b/ratis-examples/pom.xml
@@ -17,7 +17,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-examples</artifactId>
diff --git a/ratis-experiments/pom.xml b/ratis-experiments/pom.xml
index c768243c7..72b929146 100644
--- a/ratis-experiments/pom.xml
+++ b/ratis-experiments/pom.xml
@@ -17,7 +17,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-experiments</artifactId>
diff --git a/ratis-grpc/pom.xml b/ratis-grpc/pom.xml
index 9b37a73bd..d48afafa6 100644
--- a/ratis-grpc/pom.xml
+++ b/ratis-grpc/pom.xml
@@ -17,7 +17,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-grpc</artifactId>
diff --git a/ratis-metrics/pom.xml b/ratis-metrics/pom.xml
index 7098409b7..c9347b02b 100644
--- a/ratis-metrics/pom.xml
+++ b/ratis-metrics/pom.xml
@@ -18,7 +18,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-metrics</artifactId>
diff --git a/ratis-netty/pom.xml b/ratis-netty/pom.xml
index af5175694..b64790815 100644
--- a/ratis-netty/pom.xml
+++ b/ratis-netty/pom.xml
@@ -17,7 +17,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-netty</artifactId>
diff --git a/ratis-proto/pom.xml b/ratis-proto/pom.xml
index 194c98000..86e9267b0 100644
--- a/ratis-proto/pom.xml
+++ b/ratis-proto/pom.xml
@@ -17,7 +17,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-proto</artifactId>
diff --git a/ratis-replicated-map/pom.xml b/ratis-replicated-map/pom.xml
index 8183cf7d1..7fa5e858e 100644
--- a/ratis-replicated-map/pom.xml
+++ b/ratis-replicated-map/pom.xml
@@ -17,7 +17,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-replicated-map</artifactId>
diff --git a/ratis-resource-bundle/pom.xml b/ratis-resource-bundle/pom.xml
index 4e5b15e95..e45ecda4d 100644
--- a/ratis-resource-bundle/pom.xml
+++ b/ratis-resource-bundle/pom.xml
@@ -23,7 +23,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
     <relativePath>..</relativePath>
   </parent>
 
diff --git a/ratis-server-api/pom.xml b/ratis-server-api/pom.xml
index 36a5f6b37..d0551d882 100644
--- a/ratis-server-api/pom.xml
+++ b/ratis-server-api/pom.xml
@@ -17,7 +17,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-server-api</artifactId>
diff --git a/ratis-server/pom.xml b/ratis-server/pom.xml
index 3fcaa39ef..2df77cdc3 100644
--- a/ratis-server/pom.xml
+++ b/ratis-server/pom.xml
@@ -17,7 +17,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-server</artifactId>
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 b1422db4f..820f2a9f0 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
@@ -478,7 +478,7 @@ class ServerState implements Closeable {
     // 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(sm, request);
+    snapshotManager.installSnapshot(request, sm);
     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 294f0a205..2ce8f9143 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,10 +77,8 @@ public class SnapshotManager {
         c -> smDir.relativize(new File(dir.getRoot(), c.getFilename()).toPath()).toString();
   }
 
-  public void installSnapshot(StateMachine stateMachine,
-      InstallSnapshotRequestProto request) throws IOException {
-    final InstallSnapshotRequestProto.SnapshotChunkProto snapshotChunkRequest =
-        request.getSnapshotChunk();
+  public void installSnapshot(InstallSnapshotRequestProto request, StateMachine stateMachine) throws IOException {
+    final InstallSnapshotRequestProto.SnapshotChunkProto snapshotChunkRequest = request.getSnapshotChunk();
     final long lastIncludedIndex = snapshotChunkRequest.getTermIndex().getIndex();
 
     // create a unique temporary directory
@@ -103,7 +101,7 @@ public class SnapshotManager {
       }
 
       final File tmpSnapshotFile = new File(tmpDir, getRelativePath.apply(chunk));
-      FileUtils.createDirectories(tmpSnapshotFile);
+      FileUtils.createDirectoriesDeleteExistingNonDirectory(tmpSnapshotFile.getParentFile());
 
       FileOutputStream out = null;
       try {
diff --git a/ratis-shell/pom.xml b/ratis-shell/pom.xml
index 32961b958..a1c63b726 100644
--- a/ratis-shell/pom.xml
+++ b/ratis-shell/pom.xml
@@ -17,7 +17,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-shell</artifactId>
diff --git a/ratis-test/pom.xml b/ratis-test/pom.xml
index 6f438917c..487871dde 100644
--- a/ratis-test/pom.xml
+++ b/ratis-test/pom.xml
@@ -17,7 +17,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-test</artifactId>
diff --git a/ratis-tools/pom.xml b/ratis-tools/pom.xml
index 3414461e5..2f9ae59a7 100644
--- a/ratis-tools/pom.xml
+++ b/ratis-tools/pom.xml
@@ -17,7 +17,7 @@
   <parent>
     <artifactId>ratis</artifactId>
     <groupId>org.apache.ratis</groupId>
-    <version>2.4.2-SNAPSHOT</version>
+    <version>2.4.2-SNAPSHOT-1</version>
   </parent>
 
   <artifactId>ratis-tools</artifactId>