Fix too many dentry cache slab objs#7508. (#7509)

This commit is contained in:
Qi Chen 2019-04-20 11:39:50 +08:00 committed by Fangjin Yang
parent 3487663de9
commit b59b9ef8c7
1 changed files with 6 additions and 1 deletions

View File

@ -54,6 +54,8 @@ public class LimitedTemporaryStorage implements Closeable
private volatile boolean closed = false; private volatile boolean closed = false;
private boolean createdStorageDirectory = false;
public LimitedTemporaryStorage(File storageDirectory, long maxBytesUsed) public LimitedTemporaryStorage(File storageDirectory, long maxBytesUsed)
{ {
this.storageDirectory = storageDirectory; this.storageDirectory = storageDirectory;
@ -81,6 +83,9 @@ public class LimitedTemporaryStorage implements Closeable
} }
FileUtils.forceMkdir(storageDirectory); FileUtils.forceMkdir(storageDirectory);
if (!createdStorageDirectory) {
createdStorageDirectory = true;
}
final File theFile = new File(storageDirectory, StringUtils.format("%08d.tmp", files.size())); final File theFile = new File(storageDirectory, StringUtils.format("%08d.tmp", files.size()));
final EnumSet<StandardOpenOption> openOptions = EnumSet.of( final EnumSet<StandardOpenOption> openOptions = EnumSet.of(
@ -126,7 +131,7 @@ public class LimitedTemporaryStorage implements Closeable
delete(file); delete(file);
} }
files.clear(); files.clear();
if (storageDirectory.exists() && !storageDirectory.delete()) { if (createdStorageDirectory && storageDirectory.exists() && !storageDirectory.delete()) {
log.warn("Cannot delete storageDirectory: %s", storageDirectory); log.warn("Cannot delete storageDirectory: %s", storageDirectory);
} }
} }