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 d0ef8277 [MINOR] fix: allow `mountPoint` not containing '/'
d0ef8277 is described below
commit d0ef8277c487e3d6f9811a924da869a7fb36a75d
Author: xianjingfeng <[email protected]>
AuthorDate: Thu Feb 16 18:09:49 2023 +0800
[MINOR] fix: allow `mountPoint` not containing '/'
### What changes were proposed in this pull request?
Allow mountPoint do not contains '/'
### Why are the changes needed?
mountPoint is not always contains '/', such as rootfs
### Does this PR introduce any user-facing change?
No
### How was this patch tested?
No need.
---
.../uniffle/storage/common/DefaultStorageMediaProvider.java | 13 ++++++++++---
.../storage/common/DefaultStorageMediaProviderTest.java | 7 +++++++
2 files changed, 17 insertions(+), 3 deletions(-)
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 92b16742..88800fa9 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
@@ -26,6 +26,7 @@ import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
+import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.SystemUtils;
import org.apache.directory.api.util.Strings;
@@ -61,9 +62,7 @@ public class DefaultStorageMediaProvider implements
StorageMediaProvider {
try {
File baseFile = new File(baseDir);
FileStore store = Files.getFileStore(baseFile.toPath());
- String mountPoint = store.name(); // mountPoint would be /dev/sda1 or
/dev/vda1, etc.
- String deviceName =
mountPoint.substring(mountPoint.lastIndexOf(File.separator));
- deviceName = StringUtils.stripEnd(deviceName, NUMBERIC_STRING);
+ String deviceName = getDeviceName(store.name());
File blockFile = new File(String.format(BLOCK_PATH_FORMAT,
deviceName));
if (blockFile.exists()) {
List<String> contents = Files.readAllLines(blockFile.toPath());
@@ -84,4 +83,12 @@ public class DefaultStorageMediaProvider implements
StorageMediaProvider {
logger.info("Default storage type provider returns HDD by default");
return StorageMedia.HDD;
}
+
+ @VisibleForTesting
+ static String getDeviceName(String mountPoint) {
+ // mountPoint would be /dev/sda1, /dev/vda1, rootfs, etc.
+ int separatorIndex = mountPoint.lastIndexOf(File.separator);
+ String deviceName = separatorIndex > -1 ?
mountPoint.substring(separatorIndex + 1) : mountPoint;
+ return StringUtils.stripEnd(deviceName, NUMBERIC_STRING);
+ }
}
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 d105d598..2d719e3a 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
@@ -40,4 +40,11 @@ public class DefaultStorageMediaProviderTest {
// invalid uri should also be reported as HDD
assertEquals(StorageMedia.HDD,
provider.getStorageMediaFor("file@xx:///path/to/a"));
}
+
+ @Test
+ public void getGetDeviceName() {
+ assertEquals("rootfs",
DefaultStorageMediaProvider.getDeviceName("rootfs"));
+ assertEquals("sda",
DefaultStorageMediaProvider.getDeviceName("/dev/sda1"));
+ assertEquals("cl-home",
DefaultStorageMediaProvider.getDeviceName("/dev/mapper/cl-home"));
+ }
}