Java 无法将文件保存到磁盘";设备上没有剩余空间”;
我有一个java程序,可以将文件写入Linux虚拟机上的目录。写入490万个文件后,它失败,出现以下错误:Java 无法将文件保存到磁盘";设备上没有剩余空间”;,java,randomaccessfile,Java,Randomaccessfile,我有一个java程序,可以将文件写入Linux虚拟机上的目录。写入490万个文件后,它失败,出现以下错误: java.io.FileNotFoundException: /home/user/test/6BA30639CA0A2772AA0217312B3E847E2399E9A25F50F9960D6A670F4F2533EF.blob.lock (No space left on device) at java.io.RandomAccessFile.open0(Native
java.io.FileNotFoundException: /home/user/test/6BA30639CA0A2772AA0217312B3E847E2399E9A25F50F9960D6A670F4F2533EF.blob.lock (No space left on device)
at java.io.RandomAccessFile.open0(Native Method)
at java.io.RandomAccessFile.open(RandomAccessFile.java:316)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:243)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:124)
at com.xyz.azure.AsyncADLSHashFileUploader.SaveToLocalStore(AsyncADLSHashFileUploader.java:231)
我可以看到有超过80%的可用磁盘空间。
我还检查了文件系统上可用的索引节点
我不知道哪里出了问题
有人能在这方面帮助我吗?您是否尝试清空垃圾箱-一些文件系统包括垃圾箱,一些文件系统不包括垃圾箱。文件写入的文件系统是什么?像FAT32、NTFS、ext3等@Adder一样,我有ext4文件系统。挂载容量为1 TB
/dev/sdd1 ext4 1006G 29G 926G 4%
@JoakimDanielson,文件系统只有730万个文件。但是,从您提供的URL来看,它可以支持每个文件系统40亿条记录。这个错误是只有在删除一些文件后才会消失,还是仅仅通过重新启动Java程序就消失了?(试图找出问题是您的文件系统还是您的代码。)
public String SaveToLocalStore(byte[] bytes, String subfolder) throws Exception {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(bytes);
byte[] sha256 = md.digest();
String sha256str = bytesToHex(sha256);
Path tmpDir = Paths.get(LocalRootDirectory.toString(), subfolder);
Path tmpFile = Paths.get(tmpDir.toString(), sha256str + ".tmp");
Path localFile = Paths.get(LocalRootDirectory.toString(), subfolder, sha256str + ".blob");
String dstFile = getDestFileFromSrcFile(localFile.toString());
//noinspection ResultOfMethodCallIgnored
tmpDir.toFile().mkdirs();
//We can make a safe assumption that if the .blob file is present, that means that it has been fully written to
if (!Files.exists(localFile)) {
try (
RandomAccessFile randomAccessFile = new RandomAccessFile(localFile + ".lock", "rw");
FileChannel fc = randomAccessFile.getChannel();
FileLock fileLock = fc.tryLock()) {
//if other thread/process is already handling this file... no point of us doing anything
if (fileLock != null) {
//local file is already there, no need to write it again
try (FileOutputStream fos = new FileOutputStream(tmpFile.toString())) {
fos.write(bytes);
fos.flush();
fos.close();
Files.move(tmpFile, localFile, REPLACE_EXISTING);
if(statisticsEnabled) {
synchronized (StatsLock) {
StatsSavedHashes.add(localFile.toString());
}
}
} catch (Exception e) {
LOGGER.error("Failed to create local temp file: " + tmpFile + ": " + e, e);
//cleanup temp if it exists
Files.deleteIfExists(tmpFile);
throw e;
}
}
} catch (OverlappingFileLockException e) {
//other thread is handling it already, so just carry one as if(fileLock == null) was at play
return dstFile;
}
catch (Exception e) {
LOGGER.error("Error while saving local file: " + localFile + ": " + e, e);
throw e;
}
}
return dstFile;
}