/** @return the last inode. */ public INode getLastINode() { return getINode(-1); }
/** * Replace an inode of the given INodesInPath in the given position. We do a * deep copy of the INode array. * @param pos the position of the replacement * @param inode the new inode * @return a new INodesInPath instance */ public static INodesInPath replace(INodesInPath iip, int pos, INode inode) { Preconditions.checkArgument(iip.length() > 0 && pos > 0 // no for root && pos < iip.length()); if (iip.getINode(pos) == null) { Preconditions.checkState(iip.getINode(pos - 1) != null); } INode[] inodes = new INode[iip.inodes.length]; System.arraycopy(iip.inodes, 0, inodes, 0, inodes.length); inodes[pos] = inode; return new INodesInPath(inodes, iip.path, iip.isRaw, iip.isSnapshot, iip.snapshotId); }
private INodeDirectory getParentINodeDirectory(byte[][] pathComponents) throws IOException { if (pathComponents.length < 2) { // root return null; } // Gets the parent INode final INodesInPath inodes = namesystem.dir.getINodesInPath(pathComponents, DirOp.WRITE); return INodeDirectory.valueOf(inodes.getINode(-2), pathComponents); }
/** * Checks file system limits (max component length and max directory items) * during a rename operation. */ static void verifyFsLimitsForRename(FSDirectory fsd, INodesInPath srcIIP, INodesInPath dstIIP) throws PathComponentTooLongException, MaxDirectoryItemsExceededException { byte[] dstChildName = dstIIP.getLastLocalName(); final String parentPath = dstIIP.getParentPath(); fsd.verifyMaxComponentLength(dstChildName, parentPath); // Do not enforce max directory items if renaming within same directory. if (srcIIP.getINode(-2) != dstIIP.getINode(-2)) { fsd.verifyMaxDirItems(dstIIP.getINode(-2).asDirectory(), parentPath); } }
/** * updates quota without verification * callers responsibility is to make sure quota is not exceeded */ static void unprotectedUpdateCount(INodesInPath inodesInPath, int numOfINodes, QuotaCounts counts) { for(int i=0; i < numOfINodes; i++) { if (inodesInPath.getINode(i).isQuotaSet()) { // a directory with quota inodesInPath.getINode(i).asDirectory().getDirectoryWithQuotaFeature() .addSpaceConsumed2Cache(counts); } } }
private boolean isDescendant(final INodesInPath ancestorDirIIP) { int ancestorDirINodesLength = ancestorDirIIP.length(); int myParentINodesLength = length() - 1; if (myParentINodesLength < ancestorDirINodesLength) { return false; } int index = 0; while (index < ancestorDirINodesLength) { if (inodes[index] != ancestorDirIIP.getINode(index)) { return false; } index++; } return true; }
private static void checkSimpleTraverse(INodesInPath iip) throws UnresolvedPathException, ParentNotDirectoryException { byte[][] components = iip.getPathComponents(); for (int i=0; i < iip.length() - 1; i++) { INode inode = iip.getINode(i); if (inode == null) { break; } checkIsDirectory(inode, components, i); } }
INode getINode4DotSnapshot(INodesInPath iip) throws UnresolvedLinkException { Preconditions.checkArgument( iip.isDotSnapshotDir(), "%s does not end with %s", iip.getPath(), HdfsConstants.SEPARATOR_DOT_SNAPSHOT_DIR); final INode node = iip.getINode(-2); if (node != null && node.isDirectory() && node.asDirectory().isSnapshottable()) { return node; } return null; }
/** * Verify that parent directory of src exists. */ void verifyParentDir(INodesInPath iip) throws FileNotFoundException, ParentNotDirectoryException { if (iip.length() > 2) { final INode parentNode = iip.getINode(-2); if (parentNode == null) { throw new FileNotFoundException("Parent directory doesn't exist: " + iip.getParentPath()); } else if (!parentNode.isDirectory()) { throw new ParentNotDirectoryException("Parent path is not a directory: " + iip.getParentPath()); } } }
/** * Verify quota for rename operation where srcInodes[srcInodes.length-1] moves * dstInodes[dstInodes.length-1] */ private static void verifyQuotaForRename(FSDirectory fsd, INodesInPath src, INodesInPath dst) throws QuotaExceededException { if (!fsd.getFSNamesystem().isImageLoaded() || fsd.shouldSkipQuotaChecks()) { // Do not check quota if edits log is still being processed return; } int i = 0; while(src.getINode(i) == dst.getINode(i)) { i++; } // src[i - 1] is the last common ancestor. BlockStoragePolicySuite bsps = fsd.getBlockStoragePolicySuite(); final QuotaCounts delta = src.getLastINode().computeQuotaUsage(bsps); // Reduce the required quota by dst that is being removed final INode dstINode = dst.getLastINode(); if (dstINode != null) { delta.subtract(dstINode.computeQuotaUsage(bsps)); } FSDirectory.verifyQuota(dst, dst.length() - 1, delta, src.getINode(i - 1)); }
/** * Remove the last inode in the path from the namespace. * Note: the caller needs to update the ancestors' quota count. * * @return -1 for failing to remove; * 0 for removing a reference whose referred inode has other * reference nodes; * 1 otherwise. */ @VisibleForTesting public long removeLastINode(final INodesInPath iip) { final int latestSnapshot = iip.getLatestSnapshotId(); final INode last = iip.getLastINode(); final INodeDirectory parent = iip.getINode(-2).asDirectory(); if (!parent.removeChild(last, latestSnapshot)) { return -1; } return (!last.isInLatestSnapshot(latestSnapshot) && INodeReference.tryRemoveReference(last) > 0) ? 0 : 1; }
return null; INode dstParent = dstIIP.getINode(-2); if (dstParent == null) { NameNode.stateChangeLog.warn("DIR* FSDirectory.unprotectedRenameTo: " +
INode dstParent = dstIIP.getINode(-2); if (dstParent == null) { error = "rename destination parent " + dst + " not found.";
checkNotSymlink(iip.getINode(last), iip.getPathComponents(), last);
try { for (int i = iip.length() - 1; i >= 0; i--) { final INode inode = iip.getINode(i); if (inode == null) { continue;
final INode inode = iip.getINode(i); if (inode == null || !inode.isDirectory()) {
INodeDirectory trgParent = targetIIP.getINode(-2).asDirectory(); trgInode.concatBlocks(srcList, fsd.getBlockManager());
isSrcInSnapshot = srcChild.isInLatestSnapshot(srcLatestSnapshotId); srcChildIsReference = srcChild.isReference(); srcParent = this.srcIIP.getINode(-2).asDirectory();