@Override public final boolean isFile() { return referred.isFile(); }
/** Cast INode to INodeFile. */ public static INodeFile valueOf(INode inode, String path, boolean acceptNull) throws FileNotFoundException { if (inode == null) { if (acceptNull) { return null; } else { throw new FileNotFoundException("File does not exist: " + path); } } if (!inode.isFile()) { throw new FileNotFoundException("Path is not a file: " + path); } return inode.asFile(); }
private static boolean inodeHasSatisfyXAttr(INode inode) { final XAttrFeature f = inode.getXAttrFeature(); if (inode.isFile() && f != null && f.getXAttr(XATTR_SATISFY_STORAGE_POLICY) != null) { return true; } return false; }
private synchronized INode[] getINodesWithLease() { List<INode> inodes = new ArrayList<>(leasesById.size()); INode currentINode; for (long inodeId : leasesById.keySet()) { currentINode = fsnamesystem.getFSDirectory().getInode(inodeId); // A file with an active lease could get deleted, or its // parent directories could get recursively deleted. if (currentINode != null && currentINode.isFile() && !fsnamesystem.isFileDeleted(currentINode.asFile())) { inodes.add(currentINode); } } return inodes.toArray(new INode[0]); }
/** * Load the deleted list from the fsimage. * * @param parent The directory that the deleted list belongs to. * @param createdList The created list associated with the deleted list in * the same Diff. * @param in The {@link DataInput} to read. * @param loader The {@link Loader} instance. * @return The deleted list. */ private static List<INode> loadDeletedList(INodeDirectory parent, List<INode> createdList, DataInput in, FSImageFormat.Loader loader) throws IOException { int deletedSize = in.readInt(); List<INode> deletedList = new ArrayList<INode>(deletedSize); for (int i = 0; i < deletedSize; i++) { final INode deleted = loader.loadINodeWithLocalName(true, in, true); deletedList.add(deleted); // set parent: the parent field of an INode in the deleted list is not // useful, but set the parent here to be consistent with the original // fsdir tree. deleted.setParent(parent); if (deleted.isFile()) { loader.updateBlocksMap(deleted.asFile()); } } return deletedList; }
@Override public List<INodesInPath> call() { List<INodesInPath> iNodesInPaths = Lists.newArrayList(); for (int idx = startIdx; idx < inodeCount; idx += workerCount) { INode inode = inodes[idx]; if (!inode.isFile()) { continue; } INodesInPath inodesInPath = INodesInPath.fromINode( fsnamesystem.getFSDirectory().getRoot(), inode.asFile()); if (ancestorDir != null && !inodesInPath.isDescendant(ancestorDir)) { continue; } iNodesInPaths.add(inodesInPath); } return iNodesInPaths; } };
private void addToDeletedList(INode dnode, INodeDirectory parent) { dnode.setParent(parent); if (dnode.isFile()) { updateBlocksMap(dnode.asFile(), fsn.getBlockManager()); } }
/** * Caches frequently used file names to reuse file name objects and * reduce heap size. */ void cacheName(INode inode) { // Name is cached only for files if (!inode.isFile()) { return; } ByteArray name = new ByteArray(inode.getLocalNameBytes()); name = nameCache.put(name); if (name != null) { inode.setLocalName(name.getBytes()); } }
static boolean unprotectedSatisfyStoragePolicy(INode inode, FSDirectory fsd) { if (inode.isFile() && inode.asFile().numBlocks() == 0) { return false; } else { // Adding directory in the pending queue, so FileInodeIdCollector process // directory child in batch and recursively StoragePolicySatisfyManager spsManager = fsd.getBlockManager().getSPSManager(); if (spsManager != null) { spsManager.addPathId(inode.getId()); } return true; } }
if (child.isDirectory()) { dirNum++; } else if (inSnapshot && child.isFile() && child.asFile().isUnderConstruction()) { this.snapshotUCMap.put(child.getId(), child.asFile());
private void save(OutputStream out, INode n) throws IOException { if (n.isDirectory()) { save(out, n.asDirectory()); } else if (n.isFile()) { save(out, n.asFile()); } else if (n.isSymlink()) { save(out, n.asSymlink()); } }
/** * Add the child node to parent and, if child is a file, update block map. * This method is only used for image loading so that synchronization, * modification time update and space count update are not needed. */ private void addToParent(INodeDirectory parent, INode child) throws IllegalReservedPathException { FSDirectory fsDir = namesystem.dir; if (parent == fsDir.rootDir) { child.setLocalName(renameReservedRootComponentOnUpgrade( child.getLocalNameBytes(), getLayoutVersion())); } // NOTE: This does not update space counts for parents if (!parent.addChild(child)) { return; } namesystem.dir.cacheName(child); if (child.isFile()) { updateBlocksMap(child.asFile()); } }
private void addToParent(INodeDirectory parent, INode child) { if (parent == dir.rootDir && FSDirectory.isReservedName(child)) { throw new HadoopIllegalArgumentException("File name \"" + child.getLocalName() + "\" is reserved. Please " + " change the name of the existing file or directory to another " + "name before upgrading to this release."); } // NOTE: This does not update space counts for parents if (!parent.addChild(child)) { return; } dir.cacheName(child); if (child.isFile()) { updateBlocksMap(child.asFile(), fsn.getBlockManager()); } }
+ leaseExceptionString(src, fileId, holder)); if (!inode.isFile()) { throw new LeaseExpiredException("INode is not a regular file: " + leaseExceptionString(src, fileId, holder));
/** * Save one inode's attributes to the image. */ public static void saveINode2Image(INode node, DataOutput out, boolean writeUnderConstruction, ReferenceMap referenceMap) throws IOException { if (node.isReference()) { writeINodeReference(node.asReference(), out, writeUnderConstruction, referenceMap); } else if (node.isDirectory()) { writeINodeDirectory(node.asDirectory(), out); } else if (node.isSymlink()) { writeINodeSymlink(node.asSymlink(), out); } else if (node.isFile()) { writeINodeFile(node.asFile(), out, writeUnderConstruction); } }
long blocksize = 0; if (inode.isFile()) { final INodeFile fileNode = inode.asFile(); size = fileNode.computeFileSize(snapshot);
if (inode.isFile()) { if (policyId != HdfsConstants.BLOCK_STORAGE_POLICY_ID_UNSPECIFIED) { BlockStoragePolicy newPolicy = bm.getStoragePolicy(policyId);
private int getSelfSnapshot() { INode referred = getReferredINode().asReference().getReferredINode(); int snapshot = Snapshot.NO_SNAPSHOT_ID; if (referred.isFile() && referred.asFile().isWithSnapshot()) { snapshot = referred.asFile().getDiffs().getPrior(lastSnapshotId); } else if (referred.isDirectory()) { DirectoryWithSnapshotFeature sf = referred.asDirectory() .getDirectoryWithSnapshotFeature(); if (sf != null) { snapshot = sf.getDiffs().getPrior(lastSnapshotId); } } return snapshot; } }
private int getSelfSnapshot(final int prior) { WithCount wc = (WithCount) getReferredINode().asReference(); INode referred = wc.getReferredINode(); int lastSnapshot = Snapshot.CURRENT_STATE_ID; if (referred.isFile() && referred.asFile().isWithSnapshot()) { lastSnapshot = referred.asFile().getDiffs().getLastSnapshotId(); } else if (referred.isDirectory()) { DirectoryWithSnapshotFeature sf = referred.asDirectory() .getDirectoryWithSnapshotFeature(); if (sf != null) { lastSnapshot = sf.getLastSnapshotId(); } } if (lastSnapshot != Snapshot.CURRENT_STATE_ID && lastSnapshot != prior) { return lastSnapshot; } else { return Snapshot.CURRENT_STATE_ID; } } }
/** * When destroying a reference node (WithName or DstReference), we call this * method to identify the snapshot which is the latest snapshot before the * reference node's creation. */ static int getPriorSnapshot(INodeReference ref) { WithCount wc = (WithCount) ref.getReferredINode(); WithName wn = null; if (ref instanceof DstReference) { wn = wc.getLastWithName(); } else if (ref instanceof WithName) { wn = wc.getPriorWithName((WithName) ref); } if (wn != null) { INode referred = wc.getReferredINode(); if (referred.isFile() && referred.asFile().isWithSnapshot()) { return referred.asFile().getDiffs().getPrior(wn.lastSnapshotId); } else if (referred.isDirectory()) { DirectoryWithSnapshotFeature sf = referred.asDirectory() .getDirectoryWithSnapshotFeature(); if (sf != null) { return sf.getDiffs().getPrior(wn.lastSnapshotId); } } } return Snapshot.NO_SNAPSHOT_ID; }