in storage/src/main/java/org/apache/uniffle/storage/common/DefaultStorageMediaProvider.java [47:90]
public StorageMedia getStorageMediaFor(String baseDir) {
try {
URI uri = new URI(baseDir);
String scheme = uri.getScheme();
if (HDFS.equals(scheme)) {
return StorageMedia.HDFS;
} else if (scheme != null && OBJECT_STORE_SCHEMAS.contains(scheme.toLowerCase())) {
return StorageMedia.OBJECT_STORE;
}
} catch (URISyntaxException e) {
logger.warn("invalid uri input from " + baseDir + ", with exception:", e);
}
// if baseDir starts with HDFS, the hdfs storage type should be reported
if (SystemUtils.IS_OS_LINUX) {
// according to https://unix.stackexchange.com/a/65602, we can detect disk types by looking at
// the
// `/sys/block/sdx/queue/rotational`.
try {
File baseFile = new File(baseDir);
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()) {
List<String> contents = Files.readAllLines(blockFile.toPath());
// this should always hold true
if (contents.size() >= 1) {
String rotational = contents.get(0);
if (rotational.equals("0")) {
return StorageMedia.SSD;
} else if (rotational.equals("1")) {
return StorageMedia.HDD;
}
}
}
} catch (IOException ioe) {
logger.warn("Get storage type failed with exception", ioe);
}
}
logger.info("Default storage type provider returns HDD by default");
return StorageMedia.HDD;
}