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

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


The following commit(s) were added to refs/heads/master by this push:
     new 47cac391 [#762] If the storage path is not exist, get file store for 
its parent. (#763)
47cac391 is described below

commit 47cac3918ff6cdd3873754acc4d6524c4326c604
Author: xianjingfeng <[email protected]>
AuthorDate: Sun Mar 26 10:39:09 2023 +0800

    [#762] If the storage path is not exist, get file store for its parent. 
(#763)
    
    ### What changes were proposed in this pull request?
    If the storage path is not exist, get file store for its parent.
    
    ### Why are the changes needed?
    Fix: #762
    
    ### Does this PR introduce any user-facing change?
    No.
    
    ### How was this patch tested?
    UT
---
 .../storage/common/DefaultStorageMediaProvider.java     | 17 ++++++++++++++++-
 .../storage/common/DefaultStorageMediaProviderTest.java | 12 ++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git 
a/storage/src/main/java/org/apache/uniffle/storage/common/DefaultStorageMediaProvider.java
 
b/storage/src/main/java/org/apache/uniffle/storage/common/DefaultStorageMediaProvider.java
index a2da93fe..51d6dd49 100644
--- 
a/storage/src/main/java/org/apache/uniffle/storage/common/DefaultStorageMediaProvider.java
+++ 
b/storage/src/main/java/org/apache/uniffle/storage/common/DefaultStorageMediaProvider.java
@@ -23,6 +23,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.nio.file.FileStore;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Arrays;
 import java.util.List;
 
@@ -60,7 +61,10 @@ public class DefaultStorageMediaProvider implements 
StorageMediaProvider {
       // `/sys/block/sdx/queue/rotational`.
       try {
         File baseFile = new File(baseDir);
-        FileStore store = Files.getFileStore(baseFile.toPath());
+        FileStore store = getFileStore(baseFile.toPath());
+        if (store == null) {
+          throw new IOException("Can't get FileStore for path:" + 
baseFile.getAbsolutePath());
+        }
         String deviceName = getDeviceName(store.name());
         File blockFile = new File(String.format(BLOCK_PATH_FORMAT, 
deviceName));
         if (blockFile.exists()) {
@@ -83,6 +87,17 @@ public class DefaultStorageMediaProvider implements 
StorageMediaProvider {
     return StorageMedia.HDD;
   }
 
+  @VisibleForTesting
+  FileStore getFileStore(Path path) throws IOException {
+    while (!Files.exists(path)) {
+      path = path.getParent();
+      if (path == null) {
+        return null;
+      }
+    }
+    return Files.getFileStore(path);
+  }
+
   @VisibleForTesting
   static String getDeviceName(String mountPoint) {
     // mountPoint would be /dev/sda1, /dev/vda1, rootfs, etc.
diff --git 
a/storage/src/test/java/org/apache/uniffle/storage/common/DefaultStorageMediaProviderTest.java
 
b/storage/src/test/java/org/apache/uniffle/storage/common/DefaultStorageMediaProviderTest.java
index 2d719e3a..37c670eb 100644
--- 
a/storage/src/test/java/org/apache/uniffle/storage/common/DefaultStorageMediaProviderTest.java
+++ 
b/storage/src/test/java/org/apache/uniffle/storage/common/DefaultStorageMediaProviderTest.java
@@ -17,11 +17,16 @@
 
 package org.apache.uniffle.storage.common;
 
+import java.io.File;
+import java.nio.file.FileStore;
+
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
 import org.apache.uniffle.common.storage.StorageMedia;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 public class DefaultStorageMediaProviderTest {
   @Test
@@ -47,4 +52,11 @@ public class DefaultStorageMediaProviderTest {
     assertEquals("sda", 
DefaultStorageMediaProvider.getDeviceName("/dev/sda1"));
     assertEquals("cl-home", 
DefaultStorageMediaProvider.getDeviceName("/dev/mapper/cl-home"));
   }
+
+  @Test
+  public void getGetFileStore(@TempDir File tempDir) throws Exception {
+    DefaultStorageMediaProvider provider = new DefaultStorageMediaProvider();
+    FileStore fileStore = provider.getFileStore(new File(tempDir, 
"/q/w").toPath());
+    assertNotNull(fileStore);
+  }
 }

Reply via email to