/** * Checks whether there are any files anywhere in the directory tree rooted * at dir (directories don't count as files). dir must exist * @return true if there are no files * @throws IOException if unable to list subdirectories */ public static boolean dirNoFilesRecursive( FsVolumeSpi volume, File dir, FileIoProvider fileIoProvider) throws IOException { File[] contents = fileIoProvider.listFiles(volume, dir); if (contents == null) { throw new IOException("Cannot list contents of " + dir); } for (File f : contents) { if (!f.isDirectory() || (f.isDirectory() && !dirNoFilesRecursive( volume, f, fileIoProvider))) { return false; } } return true; }
boolean isBPDirEmpty(String bpid) throws IOException { File volumeCurrentDir = this.getCurrentDir(); File bpDir = new File(volumeCurrentDir, bpid); File bpCurrentDir = new File(bpDir, DataStorage.STORAGE_DIR_CURRENT); File finalizedDir = new File(bpCurrentDir, DataStorage.STORAGE_DIR_FINALIZED); File rbwDir = new File(bpCurrentDir, DataStorage.STORAGE_DIR_RBW); if (fileIoProvider.exists(this, finalizedDir) && !DatanodeUtil.dirNoFilesRecursive(this, finalizedDir, fileIoProvider)) { return false; } if (fileIoProvider.exists(this, rbwDir) && fileIoProvider.list(this, rbwDir).length != 0) { return false; } return true; }
throw new IOException("Failed to delete " + rbwDir); if (!DatanodeUtil.dirNoFilesRecursive( this, finalizedDir, fileIoProvider) || !fileIoProvider.fullyDelete( ((!DatanodeUtil.dirNoFilesRecursive( this, lazypersistDir, fileIoProvider) || !fileIoProvider.fullyDelete(this, lazypersistDir)))) {
/** * Checks whether there are any files anywhere in the directory tree rooted * at dir (directories don't count as files). dir must exist * @return true if there are no files * @throws IOException if unable to list subdirectories */ public static boolean dirNoFilesRecursive(File dir) throws IOException { File[] contents = dir.listFiles(); if (contents == null) { throw new IOException("Cannot list contents of " + dir); } for (File f : contents) { if (!f.isDirectory() || (f.isDirectory() && !dirNoFilesRecursive(f))) { return false; } } return true; }
/** * Checks whether there are any files anywhere in the directory tree rooted * at dir (directories don't count as files). dir must exist * @return true if there are no files * @throws IOException if unable to list subdirectories */ public static boolean dirNoFilesRecursive(File dir) throws IOException { File[] contents = dir.listFiles(); if (contents == null) { throw new IOException("Cannot list contents of " + dir); } for (File f : contents) { if (!f.isDirectory() || (f.isDirectory() && !dirNoFilesRecursive(f))) { return false; } } return true; }
boolean isBPDirEmpty(String bpid) throws IOException { File volumeCurrentDir = this.getCurrentDir(); File bpDir = new File(volumeCurrentDir, bpid); File bpCurrentDir = new File(bpDir, DataStorage.STORAGE_DIR_CURRENT); File finalizedDir = new File(bpCurrentDir, DataStorage.STORAGE_DIR_FINALIZED); File rbwDir = new File(bpCurrentDir, DataStorage.STORAGE_DIR_RBW); if (finalizedDir.exists() && !DatanodeUtil.dirNoFilesRecursive( finalizedDir)) { return false; } if (rbwDir.exists() && FileUtil.list(rbwDir).length != 0) { return false; } return true; }
boolean isBPDirEmpty(String bpid) throws IOException { File volumeCurrentDir = this.getCurrentDir(); File bpDir = new File(volumeCurrentDir, bpid); File bpCurrentDir = new File(bpDir, DataStorage.STORAGE_DIR_CURRENT); File finalizedDir = new File(bpCurrentDir, DataStorage.STORAGE_DIR_FINALIZED); File rbwDir = new File(bpCurrentDir, DataStorage.STORAGE_DIR_RBW); if (finalizedDir.exists() && !DatanodeUtil.dirNoFilesRecursive( finalizedDir)) { return false; } if (rbwDir.exists() && FileUtil.list(rbwDir).length != 0) { return false; } return true; }
throw new IOException("Failed to delete " + rbwDir); if (!DatanodeUtil.dirNoFilesRecursive(finalizedDir) || !FileUtil.fullyDelete(finalizedDir)) { throw new IOException("Failed to delete " + finalizedDir); ((!DatanodeUtil.dirNoFilesRecursive(lazypersistDir) || !FileUtil.fullyDelete(lazypersistDir)))) { throw new IOException("Failed to delete " + lazypersistDir);
throw new IOException("Failed to delete " + rbwDir); if (!DatanodeUtil.dirNoFilesRecursive(finalizedDir) || !FileUtil.fullyDelete(finalizedDir)) { throw new IOException("Failed to delete " + finalizedDir); ((!DatanodeUtil.dirNoFilesRecursive(lazypersistDir) || !FileUtil.fullyDelete(lazypersistDir)))) { throw new IOException("Failed to delete " + lazypersistDir);
while ((!DatanodeUtil.dirNoFilesRecursive(finalDir1)) || (!DatanodeUtil.dirNoFilesRecursive(finalDir2))) { try { Thread.sleep(3000);