OneSizeFitsQuorum commented on code in PR #14505:
URL: https://github.com/apache/iotdb/pull/14505#discussion_r1893682332


##########
iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/pipe/PipeConsensus.java:
##########
@@ -146,33 +147,61 @@ private void initAndRecover() throws IOException {
       }
     } else {
       // asynchronously recover, retry logic is implemented at 
PipeConsensusImpl
-      CompletableFuture.runAsync(
-              () -> {
-                try (DirectoryStream<Path> stream = 
Files.newDirectoryStream(storageDir.toPath())) {
-                  for (Path path : stream) {
-                    ConsensusGroupId consensusGroupId =
-                        parsePeerFileName(path.getFileName().toString());
-                    PipeConsensusServerImpl consensus =
-                        new PipeConsensusServerImpl(
-                            new Peer(consensusGroupId, thisNodeId, thisNode),
-                            registry.apply(consensusGroupId),
-                            path.toString(),
-                            new ArrayList<>(),
-                            config,
-                            consensusPipeManager,
-                            syncClientManager);
-                    stateMachineMap.put(consensusGroupId, consensus);
-                    consensus.start(true);
-                  }
-                } catch (Exception e) {
-                  LOGGER.error("Failed to recover consensus from {}", 
storageDir, e);
-                }
-              })
-          .exceptionally(
-              e -> {
-                LOGGER.error("Failed to recover consensus from {}", 
storageDir, e);
-                return null;
-              });
+      CompletableFuture<Void> future =
+          CompletableFuture.runAsync(
+                  () -> {
+                    try (DirectoryStream<Path> stream =
+                        Files.newDirectoryStream(storageDir.toPath())) {
+                      for (Path path : stream) {
+                        ConsensusGroupId consensusGroupId =
+                            parsePeerFileName(path.getFileName().toString());
+                        PipeConsensusServerImpl consensus =
+                            new PipeConsensusServerImpl(
+                                new Peer(consensusGroupId, thisNodeId, 
thisNode),
+                                registry.apply(consensusGroupId),
+                                path.toString(),
+                                new ArrayList<>(),
+                                config,
+                                consensusPipeManager,
+                                syncClientManager);
+                        stateMachineMap.put(consensusGroupId, consensus);
+                        consensus.start(true);

Review Comment:
   maybe we can put all logic in compelableFuture but start them in the last?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to