You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uniffle.apache.org by ro...@apache.org on 2023/05/23 14:26:07 UTC

[incubator-uniffle] branch branch-0.7 updated: [MINOR] fix: Fix LocalStorageManager divide by zero exception (#900)

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

roryqi pushed a commit to branch branch-0.7
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git


The following commit(s) were added to refs/heads/branch-0.7 by this push:
     new 50175850 [MINOR] fix: Fix LocalStorageManager divide by zero exception (#900)
50175850 is described below

commit 5017585032f13697396d07638d5f20d9ec71044a
Author: Xianming Lei <31...@users.noreply.github.com>
AuthorDate: Tue May 23 22:24:19 2023 +0800

    [MINOR] fix: Fix LocalStorageManager divide by zero exception (#900)
    
    ### What changes were proposed in this pull request?
    
    Fix LocalStorageManager divide by zero exception when all local disks corrupted.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    UT.
    
    Co-authored-by: leixianming <le...@didiglobal.com>
---
 .../java/org/apache/uniffle/server/storage/LocalStorageManager.java | 4 ++++
 .../org/apache/uniffle/server/storage/LocalStorageManagerTest.java  | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/server/src/main/java/org/apache/uniffle/server/storage/LocalStorageManager.java b/server/src/main/java/org/apache/uniffle/server/storage/LocalStorageManager.java
index 6ea3ef97..151038fd 100644
--- a/server/src/main/java/org/apache/uniffle/server/storage/LocalStorageManager.java
+++ b/server/src/main/java/org/apache/uniffle/server/storage/LocalStorageManager.java
@@ -187,6 +187,10 @@ public class LocalStorageManager extends SingleStorageManager {
         .stream()
         .filter(x -> x.canWrite() && !x.isCorrupted())
         .collect(Collectors.toList());
+
+    if (candidates.size() == 0) {
+      return null;
+    }
     final LocalStorage selectedStorage = candidates.get(
         ShuffleStorageUtils.getStorageIndex(
             candidates.size(),
diff --git a/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java b/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java
index 6fdcf20e..f5707a56 100644
--- a/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java
+++ b/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java
@@ -44,6 +44,7 @@ import org.apache.uniffle.storage.util.StorageType;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.fail;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
@@ -156,6 +157,11 @@ public class LocalStorageManagerTest {
     ((LocalStorage)restStorage).markCorrupted();
     Storage storage8 = localStorageManager.selectStorage(dataReadEvent);
     assertEquals(storage7, storage8);
+
+    // make all storage corrupted
+    ((LocalStorage)localStorageManager.selectStorage(dataFlushEvent1)).markCorrupted();
+    ShuffleDataFlushEvent dataFlushEvent3 = toDataFlushEvent(appId, 1, 2);
+    assertNull(localStorageManager.selectStorage(dataFlushEvent3));
   }
 
   @Test