in server/src/main/java/org/apache/uniffle/server/LocalStorageChecker.java [214:266]
boolean checkStorageReadAndWrite() {
if (storage.isCorrupted()) {
return false;
}
// Use the hidden file to avoid being cleanup
File checkDir = new File(storageDir, CHECKER_DIR_NAME);
try {
if (!checkDir.mkdirs()) {
return false;
}
File writeFile = new File(checkDir, "test");
if (!writeFile.createNewFile()) {
return false;
}
byte[] data = RandomUtils.nextBytes(1024);
try (FileOutputStream fos = new FileOutputStream(writeFile)) {
fos.write(data);
fos.flush();
fos.getFD().sync();
}
byte[] readData = new byte[1024];
int readBytes = -1;
try (FileInputStream fis = new FileInputStream(writeFile)) {
int hasReadBytes = 0;
do {
readBytes = fis.read(readData);
if (hasReadBytes < 1024) {
for (int i = 0; i < readBytes; i++) {
if (data[hasReadBytes + i] != readData[i]) {
return false;
}
}
}
hasReadBytes += readBytes;
} while (readBytes != -1);
}
} catch (Exception e) {
LOG.error("Storage read and write error. Storage dir: {}", storageDir, e);
// avoid check bad track failure due to lack of disk space
if (e.getMessage() != null && DEVICE_NO_SPACE_ERROR_MESSAGE.equals(e.getMessage())) {
return true;
}
return false;
} finally {
try {
FileUtils.deleteDirectory(checkDir);
} catch (IOException ioe) {
LOG.error("delete directory fail. Storage dir: {}", storageDir, ioe);
return false;
}
}
return true;
}