+ maxSnapshotLimit); final Snapshot s = new Snapshot(id, name, snapshotRoot); final byte[] nameBytes = s.getRoot().getLocalNameBytes(); final int i = searchSnapshot(nameBytes); if (i >= 0) { throw new SnapshotException("Failed to add snapshot: there is already a " + "snapshot with the same name \"" + Snapshot.getSnapshotName(s) + "\"."); d.setSnapshotRoot(s.getRoot()); snapshotsByNames.add(-i - 1, s); s.getRoot().setModificationTime(now, Snapshot.CURRENT_STATE_ID);
@Override public int compare(Snapshot left, Snapshot right) { return ID_INTEGER_COMPARATOR.compare(Snapshot.getSnapshotId(left), Snapshot.getSnapshotId(right)); } };
/** * Read values of {@link #snapshotCounter}, {@link #numSnapshots}, and * all snapshots from the DataInput */ public Map<Integer, Snapshot> read(DataInput in, FSImageFormat.Loader loader ) throws IOException { snapshotCounter = in.readInt(); numSnapshots.set(in.readInt()); // read snapshots final Map<Integer, Snapshot> snapshotMap = new HashMap<Integer, Snapshot>(); for(int i = 0; i < numSnapshots.get(); i++) { final Snapshot s = Snapshot.read(in, loader); snapshotMap.put(s.getId(), s); } return snapshotMap; }
/** * Remove the snapshot with the given name from {@link #snapshotsByNames}, * and delete all the corresponding DirectoryDiff. * * @param reclaimContext records blocks and inodes that need to be reclaimed * @param snapshotRoot The directory where we take snapshots * @param snapshotName The name of the snapshot to be removed * @return The removed snapshot. Null if no snapshot with the given name * exists. */ public Snapshot removeSnapshot( INode.ReclaimContext reclaimContext, INodeDirectory snapshotRoot, String snapshotName) throws SnapshotException { final int i = searchSnapshot(DFSUtil.string2Bytes(snapshotName)); if (i < 0) { throw new SnapshotException("Cannot delete snapshot " + snapshotName + " from path " + snapshotRoot.getFullPathName() + ": the snapshot does not exist."); } else { final Snapshot snapshot = snapshotsByNames.get(i); int prior = Snapshot.findLatestSnapshot(snapshotRoot, snapshot.getId()); snapshotRoot.cleanSubtree(reclaimContext, snapshot.getId(), prior); // remove from snapshotsByNames after successfully cleaning the subtree snapshotsByNames.remove(i); return snapshot; } }
private static void checkSubtreeReadPermission( FSDirectory fsd, final FSPermissionChecker pc, String snapshottablePath, String snapshot) throws IOException { final String fromPath = snapshot == null ? snapshottablePath : Snapshot.getSnapshotPath(snapshottablePath, snapshot); INodesInPath iip = fsd.resolvePath(pc, fromPath, DirOp.READ); fsd.checkPermission(pc, iip, false, null, null, FsAction.READ, FsAction.READ); }
public Snapshot getSnapshotById(int sid) { for (Snapshot s : snapshotsByNames) { if (s.getId() == sid) { return s; } } return null; }
/** * Get the name of the given snapshot. * @param s The given snapshot. * @return The name of the snapshot, or an empty string if {@code s} is null */ static String getSnapshotName(Snapshot s) { return s != null ? s.getRoot().getLocalName() : ""; }
ReadOnlyList<INode> children = dir.getChildrenList(earlier.getId()); boolean iterate = false; for (INode child : children) { if (!toProcess && child instanceof INodeReference.WithName) { byte[][] renameTargetPath = findRenameTargetPath(snapshotDir, (WithName) child, Snapshot.getSnapshotId(later)); if (renameTargetPath != null) { toProcess = true;
static Snapshot read(DataInput in, FSImageFormat.Loader loader) throws IOException { final int snapshotId = in.readInt(); final INode root = loader.loadINodeWithLocalName(false, in, false); return new Snapshot(snapshotId, root.asDirectory(), null); }
snapshottable.addSnapshottableFeature(); final Snapshot[] snapshots = { new Snapshot(1, "s1", snapshottable), new Snapshot(1, "s1", snapshottable), new Snapshot(2, "s2", snapshottable), new Snapshot(2, "s2", snapshottable), }; final int expected = s.getRoot().getLocalName().compareTo( t.getRoot().getLocalName()); final int computed = Snapshot.ID_COMPARATOR.compare(s, t); Assert.assertEquals(expected > 0, computed > 0);
/** * 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); } } }
/** * @param pendingFile open file that needs to be closed * @param storedBlock last block * @throws IOException on error */ @VisibleForTesting void closeFileCommitBlocks(String src, INodeFile pendingFile, BlockInfo storedBlock) throws IOException { final INodesInPath iip = INodesInPath.fromINode(pendingFile); // commit the last block and complete it if it has minimum replicas commitOrCompleteLastBlock(pendingFile, iip, storedBlock); //remove lease, close file int s = Snapshot.findLatestSnapshot(pendingFile, Snapshot.CURRENT_STATE_ID); finalizeINodeFileUnderConstruction(src, pendingFile, s, false); }
/** * Generate a {@link SnapshotDiffReport} based on detailed diff information. * @return A {@link SnapshotDiffReport} describing the difference */ public SnapshotDiffReport generateReport() { List<DiffReportEntry> diffReportList = new ChunkedArrayList<>(); for (Map.Entry<INode,byte[][]> drEntry : diffMap.entrySet()) { INode node = drEntry.getKey(); byte[][] path = drEntry.getValue(); diffReportList.add(new DiffReportEntry(DiffType.MODIFY, path, null)); if (node.isDirectory()) { List<DiffReportEntry> subList = generateReport(dirDiffMap.get(node), path, isFromEarlier(), renameMap); diffReportList.addAll(subList); } } return new SnapshotDiffReport(snapshotRoot.getFullPathName(), Snapshot.getSnapshotName(from), Snapshot.getSnapshotName(to), diffReportList); }
snapshotName = Snapshot.generateDefaultSnapshotName(); } else if (!DFSUtil.isValidNameForComponent(snapshotName)) { throw new InvalidPathException("Invalid snapshot name: " + snapshotName);
@Override public String getFullPathName() { return getSnapshotPath(getParent().getFullPathName(), getLocalName()); }
public static int getSnapshotId(Snapshot s) { return s == null ? CURRENT_STATE_ID : s.getId(); }
/** * Read values of {@link #snapshotCounter}, {@link #numSnapshots}, and * all snapshots from the DataInput */ public Map<Integer, Snapshot> read(DataInput in, FSImageFormat.Loader loader ) throws IOException { snapshotCounter = in.readInt(); numSnapshots.set(in.readInt()); // read snapshots final Map<Integer, Snapshot> snapshotMap = new HashMap<Integer, Snapshot>(); for(int i = 0; i < numSnapshots.get(); i++) { final Snapshot s = Snapshot.read(in, loader); snapshotMap.put(s.getId(), s); } return snapshotMap; }
} else { final Snapshot snapshot = snapshotsByNames.get(i); int prior = Snapshot.findLatestSnapshot(snapshotRoot, snapshot.getId()); try { QuotaCounts counts = snapshotRoot.cleanSubtree(bsps, snapshot.getId(), prior, collectedBlocks, removedINodes); INodeDirectory parent = snapshotRoot.getParent();