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

ethanfeng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-celeborn.git


The following commit(s) were added to refs/heads/main by this push:
     new 67bc42080 [CELEBORN-558] Bump Ratis to 2.5.1 and fix API changes 
(#1464)
67bc42080 is described below

commit 67bc4208016d2d8ac0e1702216e3ecef6fb456f4
Author: Kaijie Chen <[email protected]>
AuthorDate: Thu May 18 11:08:37 2023 +0800

    [CELEBORN-558] Bump Ratis to 2.5.1 and fix API changes (#1464)
---
 .../deploy/master/clustermeta/ha/HAHelper.java     |  3 +-
 .../deploy/master/clustermeta/ha/StateMachine.java |  7 +++--
 .../impl/SimpleStateMachineStorageUtil.java        | 33 ++++++++++++++++++++++
 .../clustermeta/ha/MasterStateMachineSuiteJ.java   |  3 +-
 pom.xml                                            |  2 +-
 5 files changed, 42 insertions(+), 6 deletions(-)

diff --git 
a/master/src/main/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/HAHelper.java
 
b/master/src/main/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/HAHelper.java
index 3dc684c9b..570c09d53 100644
--- 
a/master/src/main/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/HAHelper.java
+++ 
b/master/src/main/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/HAHelper.java
@@ -23,6 +23,7 @@ import java.io.IOException;
 import com.google.protobuf.InvalidProtocolBufferException;
 import org.apache.ratis.protocol.Message;
 import org.apache.ratis.statemachine.impl.SimpleStateMachineStorage;
+import org.apache.ratis.statemachine.impl.SimpleStateMachineStorageUtil;
 import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
 
 import org.apache.celeborn.common.exception.CelebornIOException;
@@ -117,7 +118,7 @@ public class HAHelper {
    * @throws IOException if error occurred while creating the snapshot file
    */
   public static File createTempSnapshotFile(SimpleStateMachineStorage storage) 
throws IOException {
-    File tempDir = new File(storage.getSmDir().getParentFile(), "tmp");
+    File tempDir = new 
File(SimpleStateMachineStorageUtil.getSmDir(storage).getParentFile(), "tmp");
     if (!tempDir.isDirectory() && !tempDir.mkdir()) {
       throw new IOException(
           "Cannot create temporary snapshot directory at " + 
tempDir.getAbsolutePath());
diff --git 
a/master/src/main/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/StateMachine.java
 
b/master/src/main/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/StateMachine.java
index 52c36e304..7a4a2f1ab 100644
--- 
a/master/src/main/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/StateMachine.java
+++ 
b/master/src/main/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/StateMachine.java
@@ -55,6 +55,7 @@ import org.apache.ratis.statemachine.StateMachineStorage;
 import org.apache.ratis.statemachine.TransactionContext;
 import org.apache.ratis.statemachine.impl.BaseStateMachine;
 import org.apache.ratis.statemachine.impl.SimpleStateMachineStorage;
+import org.apache.ratis.statemachine.impl.SimpleStateMachineStorageUtil;
 import org.apache.ratis.statemachine.impl.SingleFileSnapshotInfo;
 import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
 import org.apache.ratis.util.ExitUtils;
@@ -90,7 +91,7 @@ public class StateMachine extends BaseStateMachine {
             List<SingleFileSnapshotInfo> allSnapshotFiles = new ArrayList<>();
             List<SingleFileSnapshotInfo> allMD5Files = new ArrayList<>();
             try (DirectoryStream<Path> stream =
-                Files.newDirectoryStream(this.getSmDir().toPath())) {
+                
Files.newDirectoryStream(SimpleStateMachineStorageUtil.getSmDir(this).toPath()))
 {
               for (Path path : stream) {
                 if (filePatternMatches(SNAPSHOT_REGEX, allSnapshotFiles, 
path)) {
                   continue;
@@ -195,7 +196,7 @@ public class StateMachine extends BaseStateMachine {
   public void reinitialize() throws IOException {
     LOG.info("Reinitializing state machine.");
     getLifeCycle().compareAndTransition(PAUSED, STARTING);
-    storage.loadLatestSnapshot();
+    
storage.updateLatestSnapshot(SimpleStateMachineStorageUtil.findLatestSnapshot(storage));
     loadSnapshot(storage.getLatestSnapshot());
     getLifeCycle().compareAndTransition(STARTING, RUNNING);
   }
@@ -363,7 +364,7 @@ public class StateMachine extends BaseStateMachine {
         LOG.warn("Failed to rename snapshot from {} to {}.", tempFile, 
snapshotFile);
         return RaftLog.INVALID_LOG_INDEX;
       }
-      storage.loadLatestSnapshot();
+      
storage.updateLatestSnapshot(SimpleStateMachineStorageUtil.findLatestSnapshot(storage));
     } catch (Exception e) {
       tempFile.delete();
       LOG.warn("Failed to complete snapshot: {}.", snapshotFile, e);
diff --git 
a/master/src/main/java/org/apache/ratis/statemachine/impl/SimpleStateMachineStorageUtil.java
 
b/master/src/main/java/org/apache/ratis/statemachine/impl/SimpleStateMachineStorageUtil.java
new file mode 100644
index 000000000..ceea13a74
--- /dev/null
+++ 
b/master/src/main/java/org/apache/ratis/statemachine/impl/SimpleStateMachineStorageUtil.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ratis.statemachine.impl;
+
+import java.io.File;
+import java.io.IOException;
+
+public interface SimpleStateMachineStorageUtil {
+  static SingleFileSnapshotInfo findLatestSnapshot(SimpleStateMachineStorage 
storage)
+      throws IOException {
+    final File dir = storage.getStateMachineDir();
+    return SimpleStateMachineStorage.findLatestSnapshot(dir.toPath());
+  }
+
+  static File getSmDir(SimpleStateMachineStorage storage) {
+    return storage.getStateMachineDir();
+  }
+}
diff --git 
a/master/src/test/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/MasterStateMachineSuiteJ.java
 
b/master/src/test/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/MasterStateMachineSuiteJ.java
index 8453b8a82..df2e9bc26 100644
--- 
a/master/src/test/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/MasterStateMachineSuiteJ.java
+++ 
b/master/src/test/java/org/apache/celeborn/service/deploy/master/clustermeta/ha/MasterStateMachineSuiteJ.java
@@ -33,6 +33,7 @@ import org.apache.ratis.server.storage.StorageImplUtils;
 import org.apache.ratis.statemachine.SnapshotInfo;
 import org.apache.ratis.statemachine.SnapshotRetentionPolicy;
 import org.apache.ratis.statemachine.impl.SimpleStateMachineStorage;
+import org.apache.ratis.statemachine.impl.SimpleStateMachineStorageUtil;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -159,7 +160,7 @@ public class MasterStateMachineSuiteJ extends 
RatisBaseSuiteJ {
     File md5File3 = new File(snapshotFile3.getAbsolutePath() + ".md5");
     md5File3.createNewFile();
 
-    File stateMachineDir = simpleStateMachineStorage.getSmDir();
+    File stateMachineDir = 
SimpleStateMachineStorageUtil.getSmDir(simpleStateMachineStorage);
     Assert.assertTrue(stateMachineDir.listFiles().length == 13);
     simpleStateMachineStorage.cleanupOldSnapshots(snapshotRetentionPolicy);
     File[] remainingFiles = stateMachineDir.listFiles();
diff --git a/pom.xml b/pom.xml
index 4b1d274fc..500a460c8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -83,7 +83,7 @@
     <mockito-scalatest.version>1.16.37</mockito-scalatest.version>
     <netty.version>4.1.92.Final</netty.version>
     <protobuf.version>3.19.2</protobuf.version>
-    <ratis.version>2.4.1</ratis.version>
+    <ratis.version>2.5.1</ratis.version>
     <scalamock.version>5.1.0</scalamock.version>
     <scalatest.version>3.2.3</scalatest.version>
     <slf4j.version>1.7.36</slf4j.version>

Reply via email to