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

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

commit 50a5f18a0f12bd0de08bfd1b29c8602d25e8050c
Author: Potato <[email protected]>
AuthorDate: Sat Mar 23 00:53:30 2024 +0800

    RATIS-2047. Avoid unnecessary warn log when creating raft group (#1054)
---
 .../apache/ratis/server/storage/RaftStorageImpl.java    | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/storage/RaftStorageImpl.java
 
b/ratis-server/src/main/java/org/apache/ratis/server/storage/RaftStorageImpl.java
index fbb7bf7d4..ce809cad8 100644
--- 
a/ratis-server/src/main/java/org/apache/ratis/server/storage/RaftStorageImpl.java
+++ 
b/ratis-server/src/main/java/org/apache/ratis/server/storage/RaftStorageImpl.java
@@ -19,7 +19,6 @@ package org.apache.ratis.server.storage;
 
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.nio.file.NoSuchFileException;
 import java.util.concurrent.atomic.AtomicReference;
 import org.apache.ratis.proto.RaftProtos.LogEntryProto;
 import org.apache.ratis.server.RaftConfiguration;
@@ -153,14 +152,16 @@ public class RaftStorageImpl implements RaftStorage {
 
   public RaftConfiguration readRaftConfiguration() {
     File confFile = storageDir.getMetaConfFile();
-    try (InputStream fio = FileUtils.newInputStream(confFile)) {
-      LogEntryProto confProto = 
LogEntryProto.newBuilder().mergeFrom(fio).build();
-      return LogProtoUtils.toRaftConfiguration(confProto);
-    } catch (FileNotFoundException | NoSuchFileException e) {
-      return null;
-    } catch (Exception e) {
-      LOG.error("Failed reading configuration from file:" + confFile, e);
+    if (!confFile.exists()) {
       return null;
+    } else {
+      try (InputStream fio = FileUtils.newInputStream(confFile)) {
+        LogEntryProto confProto = 
LogEntryProto.newBuilder().mergeFrom(fio).build();
+        return LogProtoUtils.toRaftConfiguration(confProto);
+      } catch (Exception e) {
+        LOG.error("Failed reading configuration from file:" + confFile, e);
+        return null;
+      }
     }
   }
 

Reply via email to