diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerProxy.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerProxy.java index e6408f8bc5..6e7f5384ed 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerProxy.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerProxy.java @@ -349,7 +349,17 @@ private RaftServerImpl getImpl(RaftGroupId groupId) throws IOException { List getImpls() throws IOException { final List list = new ArrayList<>(); for(CompletableFuture f : impls.getAll()) { - list.add(IOUtils.getFromFuture(f, this::getId)); + try { + RaftServerImpl result = f.exceptionally(e->{ + LOG.warn("raft groupid " + this.getId() +" initlog is error"); + return null; + }).get(); + if (result != null) { + list.add(IOUtils.getFromFuture(f, this::getId)); + } + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } } return list; } 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 29d8320d40..728f7e9c9b 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 @@ -40,6 +40,7 @@ import java.io.Closeable; import java.io.File; import java.io.IOException; +import java.nio.file.AccessDeniedException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -67,7 +68,7 @@ class ServerState implements Closeable { /** The thread that applies committed log entries to the state machine */ private final StateMachineUpdater stateMachineUpdater; /** local storage for log and snapshot */ - private final RaftStorageImpl storage; + private RaftStorageImpl storage; private final SnapshotManager snapshotManager; private volatile Timestamp lastNoLeaderTime; private final TimeDuration noLeaderTimeout; @@ -103,10 +104,17 @@ class ServerState implements Closeable { configurationManager = new ConfigurationManager(initialConf); LOG.info("{}: {}", getMemberId(), configurationManager); - // use full uuid string to create a subdirectory - final File dir = chooseStorageDir(RaftServerConfigKeys.storageDir(prop), - group.getGroupId().getUuid().toString()); - storage = new RaftStorageImpl(dir, RaftServerConfigKeys.Log.corruptionPolicy(prop)); + List directories = RaftServerConfigKeys.storageDir(prop); + while (!directories.isEmpty()) { + // use full uuid string to create a subdirectory + File dir = chooseStorageDir(directories, group.getGroupId().getUuid().toString()); + try { + storage = new RaftStorageImpl(dir, RaftServerConfigKeys.Log.corruptionPolicy(prop)); + break; + } catch (AccessDeniedException e) { + directories.remove(dir); + } + } snapshotManager = new SnapshotManager(storage, id); stateMachine.initialize(server.getRaftServer(), group.getGroupId(), storage);