HDFS-14700. Clean up pmem cache before setting pmem cache capacity. Contributed by Feilong He.

This commit is contained in:
Rakesh Radhakrishnan 2019-08-09 14:07:54 +05:30
parent e0c21c6da9
commit f6fa865d6f
1 changed files with 12 additions and 7 deletions

View File

@ -218,6 +218,8 @@ public final class PmemVolumeManager {
try {
File pmemDir = new File(volumes[n]);
File realPmemDir = verifyIfValidPmemVolume(pmemDir);
// Clean up the cache left before, if any.
cleanup(realPmemDir);
this.pmemVolumes.add(realPmemDir.getPath());
long maxBytes;
if (maxBytesPerPmem == -1) {
@ -242,17 +244,20 @@ public final class PmemVolumeManager {
throw new IOException(
"At least one valid persistent memory volume is required!");
}
cleanup();
}
void cleanup(File realPmemDir) {
try {
FileUtils.cleanDirectory(realPmemDir);
} catch (IOException e) {
LOG.error("Failed to clean up " + realPmemDir.getPath(), e);
}
}
void cleanup() {
// Remove all files under the volume.
for (String pmemDir: pmemVolumes) {
try {
FileUtils.cleanDirectory(new File(pmemDir));
} catch (IOException e) {
LOG.error("Failed to clean up " + pmemDir, e);
}
for (String pmemVolume : pmemVolumes) {
cleanup(new File(pmemVolume));
}
}