Skip to content

Commit

Permalink
[#2251] fix(server): fix wrong disk used space while config multiply …
Browse files Browse the repository at this point in the history
…dirs in one mount point (#2252)

### What changes were proposed in this pull request?

fix wrong disk used space while config multiply dirs in one mount point

Fix: [#2251](#2251)

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

No need.
  • Loading branch information
maobaolong authored Nov 18, 2024
1 parent b00b67c commit 99eaa9d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public StorageMedia getType() {
return type;
}

public long getUsedBytes() {
return usedBytes;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
5 changes: 4 additions & 1 deletion server/src/main/java/org/apache/uniffle/server/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

package org.apache.uniffle.server;

import com.google.common.annotations.VisibleForTesting;

public abstract class Checker {

Checker(ShuffleServerConf conf) {}

abstract boolean checkIsHealthy();
@VisibleForTesting
public abstract boolean checkIsHealthy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,6 @@ public Map<String, StorageInfo> getStorageInfo() {
Map<String, StorageInfo> result = Maps.newHashMap();
for (LocalStorage storage : localStorages) {
String mountPoint = storage.getMountPoint();
long capacity = storage.getCapacity();
long wroteBytes = storage.getServiceUsedBytes();
StorageStatus status = StorageStatus.NORMAL;
if (storage.isCorrupted()) {
status = StorageStatus.UNHEALTHY;
Expand All @@ -443,6 +441,13 @@ public Map<String, StorageInfo> getStorageInfo() {
if (media == null) {
media = StorageMedia.UNKNOWN;
}
StorageInfo existingMountPoint = result.get(mountPoint);
long wroteBytes = storage.getServiceUsedBytes();
// if there is already a storage on the mount point, we should sum up the used bytes.
if (existingMountPoint != null) {
wroteBytes += existingMountPoint.getUsedBytes();
}
long capacity = storage.getCapacity();
StorageInfo info = new StorageInfo(mountPoint, media, capacity, wroteBytes, status);
result.put(mountPoint, info);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public HealthyMockChecker(ShuffleServerConf conf) {
}

@Override
boolean checkIsHealthy() {
public boolean checkIsHealthy() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public UnHealthyMockChecker(ShuffleServerConf conf) {
}

@Override
boolean checkIsHealthy() {
public boolean checkIsHealthy() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -281,20 +283,39 @@ public void testInitializeLocalStorage() throws IOException {
}

@Test
public void testGetLocalStorageInfo() {
String[] storagePaths = {"/tmp/rss-data1", "/tmp/rss-data2", "/tmp/rss-data3"};

public void testGetLocalStorageInfo() throws IOException {
Path testBaseDir = Files.createTempDirectory("rss-test");
final Path storageBaseDir1 =
Files.createDirectory(Paths.get(testBaseDir.toString(), "rss-data-1"));
final Path storageBaseDir2 =
Files.createDirectory(Paths.get(testBaseDir.toString(), "rss-data-2"));
final Path storageBaseDir3 =
Files.createDirectory(Paths.get(testBaseDir.toString(), "rss-data-3"));
String[] storagePaths = {
storageBaseDir1.toString(), storageBaseDir2.toString(), storageBaseDir3.toString(),
};
ShuffleServerConf conf = new ShuffleServerConf();
conf.set(ShuffleServerConf.RSS_STORAGE_BASE_PATH, Arrays.asList(storagePaths));
conf.setLong(ShuffleServerConf.DISK_CAPACITY, 1024L);
conf.setString(
ShuffleServerConf.RSS_STORAGE_TYPE.key(),
org.apache.uniffle.storage.util.StorageType.LOCALFILE.name());
conf.setDouble(ShuffleServerConf.HEALTH_STORAGE_MAX_USAGE_PERCENTAGE, 100.0D);
LocalStorageManager localStorageManager = new LocalStorageManager(conf);
// Create and write 3 files in each storage dir
final Path file1 = Files.createFile(Paths.get(storageBaseDir1.toString(), "partition1.data"));
final Path file2 = Files.createFile(Paths.get(storageBaseDir2.toString(), "partition2.data"));
final Path file3 = Files.createFile(Paths.get(storageBaseDir3.toString(), "partition3.data"));
FileUtils.writeByteArrayToFile(file1.toFile(), new byte[] {0x1});
FileUtils.writeByteArrayToFile(file2.toFile(), new byte[] {0x2});
FileUtils.writeByteArrayToFile(file3.toFile(), new byte[] {0x3});

boolean healthy = localStorageManager.getStorageChecker().checkIsHealthy();
assertTrue(healthy, "should be healthy");
Map<String, StorageInfo> storageInfo = localStorageManager.getStorageInfo();
assertEquals(1, storageInfo.size());
try {
final String path = "/tmp";
final String path = testBaseDir.toString();
final String mountPoint = Files.getFileStore(new File(path).toPath()).name();
assertNotNull(storageInfo.get(mountPoint));
// on Linux environment, it can detect SSD as local storage type
Expand All @@ -315,6 +336,7 @@ public void testGetLocalStorageInfo() {
assertEquals(StorageMedia.HDD, storageInfo.get(mountPoint).getType());
}
assertEquals(StorageStatus.NORMAL, storageInfo.get(mountPoint).getStatus());
assertEquals(3L, storageInfo.get(mountPoint).getUsedBytes());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 99eaa9d

Please sign in to comment.