public boolean isSnapshottable() { return getDirectorySnapshottableFeature() != null; }
public Snapshot addSnapshot(int id, String name, final LeaseManager leaseManager, final boolean captureOpenFiles, int maxSnapshotLimit) throws SnapshotException { return getDirectorySnapshottableFeature().addSnapshot(this, id, name, leaseManager, captureOpenFiles, maxSnapshotLimit); }
public Snapshot removeSnapshot( ReclaimContext reclaimContext, String snapshotName) throws SnapshotException { return getDirectorySnapshottableFeature().removeSnapshot( reclaimContext, this, snapshotName); }
public void renameSnapshot(String path, String oldName, String newName) throws SnapshotException { getDirectorySnapshottableFeature().renameSnapshot(path, oldName, newName); }
public Snapshot getSnapshot(byte[] snapshotName) { return getDirectorySnapshottableFeature().getSnapshot(snapshotName); }
public void setSnapshotQuota(int snapshotQuota) { getDirectorySnapshottableFeature().setSnapshotQuota(snapshotQuota); }
/** * Write {@link #snapshotCounter}, {@link #numSnapshots}, * and all snapshots to the DataOutput. */ public void write(DataOutput out) throws IOException { out.writeInt(snapshotCounter); out.writeInt(numSnapshots.get()); // write all snapshots. for(INodeDirectory snapshottableDir : snapshottables.values()) { for (Snapshot s : snapshottableDir.getDirectorySnapshottableFeature() .getSnapshotList()) { s.write(out); } } }
@Override // SnapshotStatsMXBean public SnapshotInfo.Bean[] getSnapshots() { List<SnapshotInfo.Bean> beans = new ArrayList<SnapshotInfo.Bean>(); for (INodeDirectory d : getSnapshottableDirs()) { for (Snapshot s : d.getDirectorySnapshottableFeature().getSnapshotList()) { beans.add(toBean(s)); } } return beans.toArray(new SnapshotInfo.Bean[beans.size()]); }
private byte[][] findRenameTargetPath(INode deleted, Snapshot laterSnapshot) { if (deleted instanceof INodeReference.WithName) { return snapshotRoot.getDirectorySnapshottableFeature() .findRenameTargetPath(snapshotDiffScopeDir, (INodeReference.WithName) deleted, Snapshot.getSnapshotId(laterSnapshot)); } return null; }
/** * Save snapshots and snapshot quota for a snapshottable directory. * @param current The directory that the snapshots belongs to. * @param out The {@link DataOutput} to write. * @throws IOException */ public static void saveSnapshots(INodeDirectory current, DataOutput out) throws IOException { DirectorySnapshottableFeature sf = current.getDirectorySnapshottableFeature(); Preconditions.checkArgument(sf != null); // list of snapshots in snapshotsByNames ReadOnlyList<Snapshot> snapshots = sf.getSnapshotList(); out.writeInt(snapshots.size()); for (Snapshot s : snapshots) { // write the snapshot id out.writeInt(s.getId()); } // snapshot quota out.writeInt(sf.getSnapshotQuota()); }
public static SnapshottableDirectoryStatus.Bean toBean(INodeDirectory d) { return new SnapshottableDirectoryStatus.Bean( d.getFullPathName(), d.getDirectorySnapshottableFeature().getNumSnapshots(), d.getDirectorySnapshottableFeature().getSnapshotQuota(), d.getModificationTime(), Short.valueOf(Integer.toOctalString( d.getFsPermissionShort())), d.getUserName(), d.getGroupName()); }
/** * Load snapshots and snapshotQuota for a Snapshottable directory. * * @param snapshottableParent * The snapshottable directory for loading. * @param numSnapshots * The number of snapshots that the directory has. * @param loader * The loader */ public static void loadSnapshotList(INodeDirectory snapshottableParent, int numSnapshots, DataInput in, FSImageFormat.Loader loader) throws IOException { DirectorySnapshottableFeature sf = snapshottableParent .getDirectorySnapshottableFeature(); Preconditions.checkArgument(sf != null); for (int i = 0; i < numSnapshots; i++) { // read snapshots final Snapshot s = loader.getSnapshot(in); s.getRoot().setParent(snapshottableParent); sf.addSnapshot(s); } int snapshotQuota = in.readInt(); snapshottableParent.setSnapshotQuota(snapshotQuota); }
/** * 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()); }
/** remove DirectorySnapshottableFeature */ public void removeSnapshottableFeature() { DirectorySnapshottableFeature s = getDirectorySnapshottableFeature(); Preconditions.checkState(s != null, "The dir does not have snapshottable feature: this=%s", this); this.removeFeature(s); if (s.getDiffs().asList().size() > 0) { // add a DirectoryWithSnapshotFeature back DirectoryWithSnapshotFeature sf = new DirectoryWithSnapshotFeature( s.getDiffs()); addFeature(sf); } }
dir.getLocalNameBytes(), dir.getId(), dir.getChildrenNum(Snapshot.CURRENT_STATE_ID), dir.getDirectorySnapshottableFeature().getNumSnapshots(), dir.getDirectorySnapshottableFeature().getSnapshotQuota(), dir.getParent() == null ? DFSUtilClient.EMPTY_BYTES : DFSUtil.string2Bytes(dir.getParent().getFullPathName()));
/** * 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(); }
INodeDirectory targetDir = target.asDirectory(); DirectorySnapshottableFeature sf = targetDir .getDirectorySnapshottableFeature(); if (sf != null) { if (sf.getNumSnapshots() > 0) {
private void loadSnapshots(InputStream in, int size) throws IOException { for (int i = 0; i < size; i++) { SnapshotSection.Snapshot pbs = SnapshotSection.Snapshot .parseDelimitedFrom(in); INodeDirectory root = loadINodeDirectory(pbs.getRoot(), parent.getLoaderContext()); int sid = pbs.getSnapshotId(); INodeDirectory parent = fsDir.getInode(root.getId()).asDirectory(); Snapshot snapshot = new Snapshot(sid, root, parent); // add the snapshot to parent, since we follow the sequence of // snapshotsByNames when saving, we do not need to sort when loading parent.getDirectorySnapshottableFeature().addSnapshot(snapshot); snapshotMap.put(sid, snapshot); } }
final INode node = iip.getLastINode(); final INodeDirectory dirNode = INodeDirectory.valueOf(node, dirPath); final DirectorySnapshottableFeature sf = dirNode.getDirectorySnapshottableFeature(); if (sf == null) { throw new SnapshotException(
/** * 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); }