jerqi commented on code in PR #72:
URL: https://github.com/apache/incubator-uniffle/pull/72#discussion_r932932987
##########
server/src/main/java/org/apache/uniffle/server/storage/LocalStorageManager.java:
##########
@@ -63,15 +71,45 @@ public class LocalStorageManager extends
SingleStorageManager {
if (highWaterMarkOfWrite < lowWaterMarkOfWrite) {
throw new IllegalArgumentException("highWaterMarkOfWrite must be larger
than lowWaterMarkOfWrite");
}
- for (String storagePath : storageBasePaths) {
- localStorages.add(LocalStorage.newBuilder()
- .basePath(storagePath)
- .capacity(capacity)
- .lowWaterMarkOfWrite(lowWaterMarkOfWrite)
- .highWaterMarkOfWrite(highWaterMarkOfWrite)
- .shuffleExpiredTimeoutMs(shuffleExpiredTimeoutMs)
- .build());
+
+ // We must make sure the order of `storageBasePaths` and `localStorages`
is same, or some unit test may be fail
+ CountDownLatch countDownLatch = new
CountDownLatch(storageBasePaths.length);
+ AtomicInteger successCount = new AtomicInteger();
+ ExecutorService executorService = Executors.newCachedThreadPool();
+ LocalStorage[] localStorageArray = new
LocalStorage[storageBasePaths.length];
+ for (int i = 0; i < storageBasePaths.length; i++) {
+ final int idx = i;
+ String storagePath = storageBasePaths[i];
+ executorService.submit(() -> {
+ try {
+ localStorageArray[idx] = LocalStorage.newBuilder()
+ .basePath(storagePath)
+ .capacity(capacity)
+ .lowWaterMarkOfWrite(lowWaterMarkOfWrite)
+ .highWaterMarkOfWrite(highWaterMarkOfWrite)
+ .shuffleExpiredTimeoutMs(shuffleExpiredTimeoutMs)
+ .build();
+ successCount.incrementAndGet();
+ } catch (Exception e) {
+ LOG.error("LocalStorage init failed!", e);
+ } finally {
+ countDownLatch.countDown();
+ }
+ });
+ }
+
+ 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));
+ }
+
Review Comment:
Should we shutdown the executor pool after we finished to use them?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]