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

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


The following commit(s) were added to refs/heads/master by this push:
     new 737c4ccea98 Fix print error log when dir is not exist (#13591)
737c4ccea98 is described below

commit 737c4ccea989f82fb3f54c1532de98e9160296f0
Author: 133tosakarin <[email protected]>
AuthorDate: Tue Sep 24 16:40:10 2024 +0800

    Fix print error log when dir is not exist (#13591)
---
 .../src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java    | 4 ++++
 .../main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java    | 3 +++
 2 files changed, 7 insertions(+)

diff --git 
a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java
 
b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java
index ed089ff63bf..4d4e38d239c 100644
--- 
a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java
+++ 
b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java
@@ -70,6 +70,7 @@ import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -435,6 +436,9 @@ public class IoTConsensus implements IConsensus {
   }
 
   public static List<ConsensusGroupId> getConsensusGroupIdsFromDir(File 
storageDir, Logger logger) {
+    if (!storageDir.exists()) {
+      return Collections.emptyList();
+    }
     List<ConsensusGroupId> consensusGroupIds = new ArrayList<>();
     try (DirectoryStream<Path> stream = 
Files.newDirectoryStream(storageDir.toPath())) {
       for (Path path : stream) {
diff --git 
a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
 
b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
index 85786cc7087..59416adbbf7 100644
--- 
a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
+++ 
b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
@@ -773,6 +773,9 @@ class RatisConsensus implements IConsensus {
 
   @Override
   public List<ConsensusGroupId> getAllConsensusGroupIdsWithoutStarting() {
+    if (!storageDir.exists()) {
+      return Collections.emptyList();
+    }
     List<ConsensusGroupId> consensusGroupIds = new ArrayList<>();
     try (DirectoryStream<Path> stream = 
Files.newDirectoryStream(storageDir.toPath())) {
       for (Path path : stream) {

Reply via email to