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); }
/** * Compute the difference between two snapshots of a directory, or between a * snapshot of the directory and its current tree. */ public SnapshotDiffReport diff(final INodesInPath iip, final String snapshotPath, final String from, final String to) throws IOException { // Find the source root directory path where the snapshots were taken. // All the check for path has been included in the valueOf method. INodeDirectory snapshotRootDir; if (this.snapshotDiffAllowSnapRootDescendant) { snapshotRootDir = getSnapshottableAncestorDir(iip); } else { snapshotRootDir = getSnapshottableRoot(iip); } Preconditions.checkNotNull(snapshotRootDir); INodeDirectory snapshotDescendantDir = INodeDirectory.valueOf( iip.getLastINode(), snapshotPath); if ((from == null || from.isEmpty()) && (to == null || to.isEmpty())) { // both fromSnapshot and toSnapshot indicate the current tree return new SnapshotDiffReport(snapshotPath, from, to, Collections.<DiffReportEntry> emptyList()); } final SnapshotDiffInfo diffs = snapshotRootDir .getDirectorySnapshottableFeature().computeDiff( snapshotRootDir, snapshotDescendantDir, from, to); return diffs != null ? diffs.generateReport() : new SnapshotDiffReport( snapshotPath, from, to, Collections.<DiffReportEntry> emptyList()); }
/** * Find the source root directory where the snapshot will be taken * for a given path. * * @return Snapshottable directory. * @throws IOException * Throw IOException when the given path does not lead to an * existing snapshottable directory. */ public INodeDirectory getSnapshottableRoot(final INodesInPath iip) throws IOException { final String path = iip.getPath(); final INodeDirectory dir = INodeDirectory.valueOf(iip.getLastINode(), path); if (!dir.isSnapshottable()) { throw new SnapshotException( "Directory is not a snapshottable directory: " + path); } return dir; }
/** * Get the snapshot root directory for the given directory. The given * directory must either be a snapshot root or a descendant of any * snapshot root directories. * @param iip INodesInPath for the directory to get snapshot root. * @return the snapshot root INodeDirectory */ public INodeDirectory getSnapshottableAncestorDir(final INodesInPath iip) throws IOException { final String path = iip.getPath(); final INodeDirectory dir = INodeDirectory.valueOf(iip.getLastINode(), path); if (dir.isSnapshottable()) { return dir; } else { for (INodeDirectory snapRoot : this.snapshottables.values()) { if (dir.isAncestorDirectory(snapRoot)) { return snapRoot; } } throw new SnapshotException("Directory is neither snapshottable nor" + " under a snap root!"); } }
/** * Load all children of a directory * * @param in input to load from * @param counter Counter to increment for namenode startup progress * @return number of child inodes read * @throws IOException */ private int loadDirectory(DataInput in, Counter counter) throws IOException { String parentPath = FSImageSerialization.readString(in); // Rename .snapshot paths if we're doing an upgrade parentPath = renameReservedPathsOnUpgrade(parentPath, getLayoutVersion()); final INodeDirectory parent = INodeDirectory.valueOf( namesystem.dir.getINode(parentPath, DirOp.READ), parentPath); return loadChildren(parent, in, counter); }
/** * Compute the partial difference between two snapshots of a directory, * or between a snapshot of the directory and its current tree. */ public SnapshotDiffReportListing diff(final INodesInPath iip, final String snapshotPath, final String from, final String to, byte[] startPath, int index, int snapshotDiffReportLimit) throws IOException { // Find the source root directory path where the snapshots were taken. // All the check for path has been included in the valueOf method. INodeDirectory snapshotRootDir; if (this.snapshotDiffAllowSnapRootDescendant) { snapshotRootDir = getSnapshottableAncestorDir(iip); } else { snapshotRootDir = getSnapshottableRoot(iip); } Preconditions.checkNotNull(snapshotRootDir); INodeDirectory snapshotDescendantDir = INodeDirectory.valueOf( iip.getLastINode(), snapshotPath); final SnapshotDiffListingInfo diffs = snapshotRootDir.getDirectorySnapshottableFeature() .computeDiff(snapshotRootDir, snapshotDescendantDir, from, to, startPath, index, snapshotDiffReportLimit); return diffs != null ? diffs.generateReport() : new SnapshotDiffReportListing(); }
/** * Set the given directory as a snapshottable directory. * If the path is already a snapshottable directory, update the quota. */ public void setSnapshottable(final String path, boolean checkNestedSnapshottable) throws IOException { final INodesInPath iip = fsdir.getINodesInPath(path, DirOp.WRITE); final INodeDirectory d = INodeDirectory.valueOf(iip.getLastINode(), path); if (checkNestedSnapshottable) { checkNestedSnapshottable(d, path); } if (d.isSnapshottable()) { //The directory is already a snapshottable directory. d.setSnapshotQuota(DirectorySnapshottableFeature.SNAPSHOT_QUOTA_DEFAULT); } else { d.addSnapshottableFeature(); } addSnapshottable(d); }
final String dirPath = iip.getPath(); final INode node = iip.getLastINode(); final INodeDirectory dirNode = INodeDirectory.valueOf(node, dirPath); final DirectorySnapshottableFeature sf = dirNode.getDirectorySnapshottableFeature(); if (sf == null) {
/** * Set the given snapshottable directory to non-snapshottable. * * @throws SnapshotException if there are snapshots in the directory. */ public void resetSnapshottable(final String path) throws IOException { final INodesInPath iip = fsdir.getINodesInPath(path, DirOp.WRITE); final INodeDirectory d = INodeDirectory.valueOf(iip.getLastINode(), path); DirectorySnapshottableFeature sf = d.getDirectorySnapshottableFeature(); if (sf == null) { // the directory is already non-snapshottable return; } if (sf.getNumSnapshots() > 0) { throw new SnapshotException("The directory " + path + " has snapshot(s). " + "Please redo the operation after removing all the snapshots."); } if (d == fsdir.getRoot()) { d.setSnapshotQuota(0); } else { d.removeSnapshottableFeature(); } removeSnapshottable(d); }
INodeDirectory.valueOf(iip.getLastINode(), iip.getPath()); if (dirNode.isRoot() && nsQuota == HdfsConstants.QUOTA_RESET) { throw new IllegalArgumentException("Cannot clear namespace quota on root.");
private INodeDirectory getParentINodeDirectory(byte[][] pathComponents ) throws FileNotFoundException, PathIsNotDirectoryException, UnresolvedLinkException { if (pathComponents.length < 2) { // root return null; } // Gets the parent INode final INodesInPath inodes = namesystem.dir.getExistingPathINodes( pathComponents); return INodeDirectory.valueOf(inodes.getINode(-2), pathComponents); }
private INodeDirectory getParentINodeDirectory(byte[][] pathComponents ) throws FileNotFoundException, PathIsNotDirectoryException, UnresolvedLinkException { if (pathComponents.length < 2) { // root return null; } // Gets the parent INode final INodesInPath inodes = namesystem.dir.getExistingPathINodes( pathComponents); return INodeDirectory.valueOf(inodes.getINode(-2), pathComponents); }
private static INodeDirectory getDir(final FSDirectory fsdir, final Path dir) throws IOException { final String dirStr = dir.toString(); return INodeDirectory.valueOf(fsdir.getINode(dirStr), dirStr); }
private static INodeDirectory getDir(final FSDirectory fsdir, final Path dir) throws IOException { final String dirStr = dir.toString(); return INodeDirectory.valueOf(fsdir.getINode(dirStr), dirStr); }
/** * Find the source root directory where the snapshot will be taken * for a given path. * * @return Snapshottable directory. * @throws IOException * Throw IOException when the given path does not lead to an * existing snapshottable directory. */ public INodeDirectory getSnapshottableRoot(final INodesInPath iip) throws IOException { final String path = iip.getPath(); final INodeDirectory dir = INodeDirectory.valueOf(iip.getLastINode(), path); if (!dir.isSnapshottable()) { throw new SnapshotException( "Directory is not a snapshottable directory: " + path); } return dir; }
/** * Load all children of a directory * * @param in input to load from * @param counter Counter to increment for namenode startup progress * @return number of child inodes read * @throws IOException */ private int loadDirectory(DataInput in, Counter counter) throws IOException { String parentPath = FSImageSerialization.readString(in); // Rename .snapshot paths if we're doing an upgrade parentPath = renameReservedPathsOnUpgrade(parentPath, getLayoutVersion()); final INodeDirectory parent = INodeDirectory.valueOf( namesystem.dir.getINode(parentPath, true), parentPath); return loadChildren(parent, in, counter); }
/** * Load all children of a directory * * @param in input to load from * @param counter Counter to increment for namenode startup progress * @return number of child inodes read * @throws IOException */ private int loadDirectory(DataInput in, Counter counter) throws IOException { String parentPath = FSImageSerialization.readString(in); // Rename .snapshot paths if we're doing an upgrade parentPath = renameReservedPathsOnUpgrade(parentPath, getLayoutVersion()); final INodeDirectory parent = INodeDirectory.valueOf( namesystem.dir.getINode(parentPath, true), parentPath); return loadChildren(parent, in, counter); }
/** * Set the given directory as a snapshottable directory. * If the path is already a snapshottable directory, update the quota. */ public void setSnapshottable(final String path, boolean checkNestedSnapshottable) throws IOException { final INodesInPath iip = fsdir.getINodesInPath4Write(path); final INodeDirectory d = INodeDirectory.valueOf(iip.getLastINode(), path); if (checkNestedSnapshottable) { checkNestedSnapshottable(d, path); } if (d.isSnapshottable()) { //The directory is already a snapshottable directory. d.setSnapshotQuota(DirectorySnapshottableFeature.SNAPSHOT_LIMIT); } else { d.addSnapshottableFeature(); } addSnapshottable(d); }
@Test (timeout=60000) public void testSetQuota() throws Exception { final Path dir = new Path("/TestSnapshot"); hdfs.mkdirs(dir); // allow snapshot on dir and create snapshot s1 SnapshotTestHelper.createSnapshot(hdfs, dir, "s1"); Path sub = new Path(dir, "sub"); hdfs.mkdirs(sub); Path fileInSub = new Path(sub, "file"); DFSTestUtil.createFile(hdfs, fileInSub, BLOCKSIZE, REPLICATION, seed); INodeDirectory subNode = INodeDirectory.valueOf( fsdir.getINode(sub.toString()), sub); // subNode should be a INodeDirectory, but not an INodeDirectoryWithSnapshot assertFalse(subNode.isWithSnapshot()); hdfs.setQuota(sub, Long.MAX_VALUE - 1, Long.MAX_VALUE - 1); subNode = INodeDirectory.valueOf(fsdir.getINode(sub.toString()), sub); assertTrue(subNode.isQuotaSet()); assertFalse(subNode.isWithSnapshot()); }
/** Load the fsimage from a temp file */ private void loadFSImageFromTempFile(File imageFile) throws IOException { FSImageFormat.LoaderDelegator loader = FSImageFormat.newLoader(conf, fsn); fsn.writeLock(); fsn.getFSDirectory().writeLock(); try { loader.load(imageFile, false); FSImage.updateCountForQuota(fsn.getBlockManager().getStoragePolicySuite(), INodeDirectory.valueOf(fsn.getFSDirectory().getINode("/"), "/"), 4); } finally { fsn.getFSDirectory().writeUnlock(); fsn.writeUnlock(); } }