SnapshotDiffInfo(INodeDirectory snapshotRootDir, INodeDirectory snapshotDiffScopeDir, Snapshot start, Snapshot end) { Preconditions.checkArgument(snapshotRootDir.isSnapshottable() && snapshotDiffScopeDir.isDescendantOfSnapshotRoot(snapshotRootDir)); this.snapshotRoot = snapshotRootDir; this.snapshotDiffScopeDir = snapshotDiffScopeDir; this.from = start; this.to = end; }
SnapshotDiffListingInfo(INodeDirectory snapshotRootDir, INodeDirectory snapshotDiffScopeDir, Snapshot start, Snapshot end, int snapshotDiffReportLimit) { Preconditions.checkArgument( snapshotRootDir.isSnapshottable() && snapshotDiffScopeDir .isDescendantOfSnapshotRoot(snapshotRootDir)); this.snapshotRoot = snapshotRootDir; this.snapshotDiffScopeDir = snapshotDiffScopeDir; this.from = start; this.to = end; this.maxEntries = snapshotDiffReportLimit; }
/** Add the given snapshottable directory to {@link #snapshottables}. */ public void addSnapshottable(INodeDirectory dir) { Preconditions.checkArgument(dir.isSnapshottable()); snapshottables.put(dir.getId(), dir); }
/** * Check if this directory is a descendant directory * of a snapshot root directory. * @param snapshotRootDir the snapshot root directory * @return true if this directory is a descendant of snapshot root */ public boolean isDescendantOfSnapshotRoot(INodeDirectory snapshotRootDir) { Preconditions.checkArgument(snapshotRootDir.isSnapshottable()); INodeDirectory dir = this; while(dir != null) { if (dir.equals(snapshotRootDir)) { return true; } dir = dir.getParent(); } return false; }
/** add DirectorySnapshottableFeature */ public void addSnapshottableFeature() { Preconditions.checkState(!isSnapshottable(), "this is already snapshottable, this=%s", this); DirectoryWithSnapshotFeature s = this.getDirectoryWithSnapshotFeature(); final DirectorySnapshottableFeature snapshottable = new DirectorySnapshottableFeature(s); if (s != null) { this.removeFeature(s); } this.addFeature(snapshottable); }
/** * Serialize a {@link INodeDirectory} * @param node The node to write * @param out The {@link DataOutput} where the fields are written */ public static void writeINodeDirectory(INodeDirectory node, DataOutput out) throws IOException { writeLocalName(node, out); out.writeLong(node.getId()); out.writeShort(0); // replication out.writeLong(node.getModificationTime()); out.writeLong(0); // access time out.writeLong(0); // preferred block size out.writeInt(-1); // # of blocks writeQuota(node.getQuotaCounts(), out); if (node.isSnapshottable()) { out.writeBoolean(true); } else { out.writeBoolean(false); out.writeBoolean(node.isWithSnapshot()); } writePermissionStatus(node, out); }
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; }
void validate() { // check parent up to snapshotRootIndex if this is a snapshot path int i = 0; if (inodes[i] != null) { for(i++; i < inodes.length && inodes[i] != null; i++) { final INodeDirectory parent_i = inodes[i].getParent(); final INodeDirectory parent_i_1 = inodes[i-1].getParent(); if (parent_i != inodes[i-1] && (parent_i_1 == null || !parent_i_1.isSnapshottable() || parent_i != parent_i_1)) { throw new AssertionError( "inodes[" + i + "].getParent() != inodes[" + (i-1) + "]\n inodes[" + i + "]=" + inodes[i].toDetailString() + "\n inodes[" + (i-1) + "]=" + inodes[i-1].toDetailString() + "\n this=" + toString(false)); } } } if (i != inodes.length) { throw new AssertionError("i = " + i + " != " + inodes.length + ", this=" + toString(false)); } } }
/** * 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!"); } }
/** * 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); }
if (current.isDirectory() && current.asDirectory().isSnapshottable()) { SnapshotFSImageFormat.saveSnapshots(current.asDirectory(), out); } else {
SnapshotDiffInfo(INodeDirectory snapshotRoot, Snapshot start, Snapshot end) { Preconditions.checkArgument(snapshotRoot.isSnapshottable()); this.snapshotRoot = snapshotRoot; this.from = start; this.to = end; }
/** * Load the snapshots section from fsimage. Also add snapshottable feature * to snapshottable directories. */ public void loadSnapshotSection(InputStream in) throws IOException { SnapshotManager sm = fsn.getSnapshotManager(); SnapshotSection section = SnapshotSection.parseDelimitedFrom(in); int snum = section.getNumSnapshots(); sm.setNumSnapshots(snum); sm.setSnapshotCounter(section.getSnapshotCounter()); for (long sdirId : section.getSnapshottableDirList()) { INodeDirectory dir = fsDir.getInode(sdirId).asDirectory(); if (!dir.isSnapshottable()) { dir.addSnapshottableFeature(); } else { // dir is root, and admin set root to snapshottable before dir.setSnapshotQuota( DirectorySnapshottableFeature.SNAPSHOT_QUOTA_DEFAULT); } sm.addSnapshottable(dir); } loadSnapshots(in, snum); }
if (isDotSnapshotDir(childName) && dir.isSnapshottable()) { isSnapshot = true;
/** Add the given snapshottable directory to {@link #snapshottables}. */ public void addSnapshottable(INodeDirectory dir) { Preconditions.checkArgument(dir.isSnapshottable()); snapshottables.put(dir.getId(), dir); }
isSnapShottable = node.asDirectory().isSnapshottable();
/** add DirectorySnapshottableFeature */ public void addSnapshottableFeature() { Preconditions.checkState(!isSnapshottable(), "this is already snapshottable, this=%s", this); DirectoryWithSnapshotFeature s = this.getDirectoryWithSnapshotFeature(); final DirectorySnapshottableFeature snapshottable = new DirectorySnapshottableFeature(s); if (s != null) { this.removeFeature(s); } this.addFeature(snapshottable); }
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; }
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; }