You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@uniffle.apache.org by GitBox <gi...@apache.org> on 2022/07/26 08:12:37 UTC

[GitHub] [incubator-uniffle] colinmjj commented on a diff in pull request #72: [Improvement]LocalStorage init use multi thread #71

colinmjj commented on code in PR #72:
URL: https://github.com/apache/incubator-uniffle/pull/72#discussion_r929659644


##########
server/src/main/java/org/apache/uniffle/server/storage/LocalStorageManager.java:
##########
@@ -63,18 +65,43 @@ public class LocalStorageManager extends SingleStorageManager {
     if (highWaterMarkOfWrite < lowWaterMarkOfWrite) {
       throw new IllegalArgumentException("highWaterMarkOfWrite must be larger than lowWaterMarkOfWrite");
     }
+
+    CountDownLatch countDownLatch = new CountDownLatch(storageBasePaths.length);
+    AtomicInteger successCount = new AtomicInteger();
     for (String storagePath : storageBasePaths) {
-      localStorages.add(LocalStorage.newBuilder()
-          .basePath(storagePath)
-          .capacity(capacity)
-          .lowWaterMarkOfWrite(lowWaterMarkOfWrite)
-          .highWaterMarkOfWrite(highWaterMarkOfWrite)
-          .shuffleExpiredTimeoutMs(shuffleExpiredTimeoutMs)
-          .build());
+      new Thread(() -> {
+        try {
+          addLocalStorage(LocalStorage.newBuilder()
+                  .basePath(storagePath)
+                  .capacity(capacity)
+                  .lowWaterMarkOfWrite(lowWaterMarkOfWrite)
+                  .highWaterMarkOfWrite(highWaterMarkOfWrite)
+                  .shuffleExpiredTimeoutMs(shuffleExpiredTimeoutMs)
+                  .build());
+          successCount.incrementAndGet();
+        } finally {
+          countDownLatch.countDown();
+        }
+      }).start();
+    }
+    try {
+      countDownLatch.await();
+    } catch (InterruptedException e) {
+      e.printStackTrace();
+    }
+
+    int failedCount = storageBasePaths.length - successCount.get();
+    if (failedCount > 0) {
+      throw new RuntimeException(String.format("[%s] local storage init failed!", failedCount));
     }
+
     this.checker = new LocalStorageChecker(conf, localStorages);
   }
 
+  private synchronized void addLocalStorage(LocalStorage localStorage) {

Review Comment:
   Does it do the clean concurrently with synchronized?



-- 
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: issues-unsubscribe@uniffle.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@uniffle.apache.org
For additional commands, e-mail: issues-help@uniffle.apache.org