/** * 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; }
static File getMetaFile(File f, long gs) { return new File(f.getParent(), DatanodeUtil.getMetaName(f.getName(), gs)); }
final File tmpFile = DatanodeUtil.createFileWithExistsCheck( getVolume(), b, DatanodeUtil.getUnlinkTmpFile(file), fileIoProvider); try { try (FileInputStream in = fileIoProvider.getFileInputStream(
/** * Return the parent directory path where this replica is located. * @return the parent directory path where this replica is located */ protected File getDir() { return hasSubdirs ? DatanodeUtil.idToBlockDir(baseDir, getBlockId()) : baseDir; }
File tmpFile = DatanodeUtil.createTmpFile(b, DatanodeUtil.getUnlinkTmpFile(file)); try { FileInputStream in = new FileInputStream(file);
protected final boolean verifyBlockDeletedFromDir(File dir, LocatedBlocks locatedBlocks) { for (LocatedBlock lb : locatedBlocks.getLocatedBlocks()) { File targetDir = DatanodeUtil.idToBlockDir(dir, lb.getBlock().getBlockId()); File blockFile = new File(targetDir, lb.getBlock().getBlockName()); if (blockFile.exists()) { LOG.warn("blockFile: " + blockFile.getAbsolutePath() + " exists after deletion."); return false; } File metaFile = new File(targetDir, DatanodeUtil.getMetaName(lb.getBlock().getBlockName(), lb.getBlock().getGenerationStamp())); if (metaFile.exists()) { LOG.warn("metaFile: " + metaFile.getAbsolutePath() + " exists after deletion."); return false; } } return true; }
try { blockIn = (FileInputStream)dataset.getBlockInputStream(extBlk, 0); metaIn = DatanodeUtil.getMetaDataInputStream(extBlk, dataset); } catch (ClassCastException e) { LOG.warn("Failed to cache " + key +
IOException cause = DatanodeUtil.getCauseIfDiskError(ioe); DataNode.LOG .warn("IOException in BlockReceiver constructor :" + ioe.getMessage()
private static void createUnlinkTmpFile(ReplicaInfo replicaInfo, boolean changeBlockFile, boolean isRename) throws IOException { File src; if (changeBlockFile) { src = replicaInfo.getBlockFile(); } else { src = replicaInfo.getMetaFile(); } File dst = DatanodeUtil.getUnlinkTmpFile(src); if (isRename) { src.renameTo(dst); } else { FileInputStream in = new FileInputStream(src); try { FileOutputStream out = new FileOutputStream(dst); try { IOUtils.copyBytes(in, out, 1); } finally { out.close(); } } finally { in.close(); } } }
/** * RBW files. They get moved to the finalized block directory when * the block is finalized. */ File createRbwFile(Block b) throws IOException { File f = new File(rbwDir, b.getBlockName()); return DatanodeUtil.createTmpFile(b, f); }
/** * Verify whether the actual directory location of block file has the * expected directory path computed using its block ID. */ private void verifyFileLocation(File actualBlockFile, File bpFinalizedDir, long blockId) { File expectedBlockDir = DatanodeUtil.idToBlockDir(bpFinalizedDir, blockId); File actualBlockDir = actualBlockFile.getParentFile(); if (actualBlockDir.compareTo(expectedBlockDir) != 0) { LOG.warn("Block: " + blockId + " found in invalid directory. Expected directory: " + expectedBlockDir + ". Actual directory: " + actualBlockDir); } }
File tmpFile = DatanodeUtil.createTmpFile(b, DatanodeUtil.getUnlinkTmpFile(file)); try { FileInputStream in = new FileInputStream(file);
FileInputStream[] requestShortCircuitFdsForRead(final ExtendedBlock blk, final Token<BlockTokenIdentifier> token, int maxVersion) throws ShortCircuitFdsUnsupportedException, ShortCircuitFdsVersionException, IOException { if (fileDescriptorPassingDisabledReason != null) { throw new ShortCircuitFdsUnsupportedException( fileDescriptorPassingDisabledReason); } int blkVersion = CURRENT_BLOCK_FORMAT_VERSION; if (maxVersion < blkVersion) { throw new ShortCircuitFdsVersionException("Your client is too old " + "to read this block! Its format version is " + blkVersion + ", but the highest format version you can read is " + maxVersion); } metrics.incrBlocksGetLocalPathInfo(); FileInputStream fis[] = new FileInputStream[2]; try { fis[0] = (FileInputStream)data.getBlockInputStream(blk, 0); fis[1] = DatanodeUtil.getMetaDataInputStream(blk, data); } catch (ClassCastException e) { LOG.debug("requestShortCircuitFdsForRead failed", e); throw new ShortCircuitFdsUnsupportedException("This DataNode's " + "FsDatasetSpi does not support short-circuit local reads"); } return fis; }
IOException cause = DatanodeUtil.getCauseIfDiskError(ioe); DataNode.LOG.warn("IOException in BlockReceiver constructor. Cause is ", cause);
/** * Temporary files. They get moved to the finalized block directory when * the block is finalized. */ File createTmpFile(Block b) throws IOException { File f = new File(tmpDir, b.getBlockName()); return DatanodeUtil.createTmpFile(b, f); }
private File getBlockFile(String bpid, ExtendedBlock blk) throws IOException { return new File(DatanodeUtil.idToBlockDir(getFinalizedDir(bpid), blk.getBlockId()).toString() + "/" + blk.getBlockName()); }
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; }
/** * Get the full path of this replica's meta file. * @return the full path of this replica's meta file */ @VisibleForTesting public File getMetaFile() { return new File(getDir(), DatanodeUtil.getMetaName(getBlockName(), getGenerationStamp())); }
try { blockIn = (FileInputStream)dataset.getBlockInputStream(extBlk, 0); metaIn = DatanodeUtil.getMetaDataInputStream(extBlk, dataset); } catch (ClassCastException e) { LOG.warn("Failed to cache " + key +
IOException cause = DatanodeUtil.getCauseIfDiskError(ioe); DataNode.LOG.warn("IOException in BlockReceiver constructor. Cause is ", cause);