Snapshot implements Comparable<byte[]> { @Override public String toString() { return getClass().getSimpleName() + "." + root.getLocalName() + "(id=" + id + ")"; } Snapshot(long id, String name, INodeDirectorySnapshottable dir);   Snapshot(long id, INodeDirectory dir, INodeDirectorySnapshottable parent); static String generateDefaultSnapshotName(); static String getSnapshotPath(String snapshottableDir,
      String snapshotRelativePath); static long getSnapshotId(Snapshot s); static long findLatestSnapshot(INode inode, final long anchor); long getId(); Root getRoot(); @Override int compareTo(byte[] bytes); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); static final long CURRENT_STATE_ID; static final long NO_SNAPSHOT_ID; static final Comparator<Snapshot> ID_COMPARATOR; static final Comparator<Integer> ID_INTEGER_COMPARATOR; static final Comparator<Long> ID_LONG_COMPARATOR; }
@Test public void testAllowAndDisallowSnapshot() throws Exception { final Path dir = new Path("/dir"); final Path file0 = new Path(dir, "file0"); final Path file1 = new Path(dir, "file1"); DFSTestUtil.createFile(hdfs, file0, BLOCKSIZE, REPLICATION, seed); DFSTestUtil.createFile(hdfs, file1, BLOCKSIZE, REPLICATION, seed); INodeDirectory dirNode = fsdir.getINode4Write(dir.toString()).asDirectory(); assertFalse(dirNode.isSnapshottable()); hdfs.allowSnapshot(dir); dirNode = fsdir.getINode4Write(dir.toString()).asDirectory(); assertTrue(dirNode.isSnapshottable()); hdfs.allowSnapshot(dir); dirNode = fsdir.getINode4Write(dir.toString()).asDirectory(); assertTrue(dirNode.isSnapshottable()); hdfs.disallowSnapshot(dir); dirNode = fsdir.getINode4Write(dir.toString()).asDirectory(); assertFalse(dirNode.isSnapshottable()); hdfs.disallowSnapshot(dir); dirNode = fsdir.getINode4Write(dir.toString()).asDirectory(); assertFalse(dirNode.isSnapshottable()); final Path root = new Path("/"); INodeDirectory rootNode = fsdir.getINode4Write(root.toString()) .asDirectory(); assertTrue(rootNode.isSnapshottable()); assertEquals(0, ((INodeDirectorySnapshottable) rootNode).getSnapshotQuota()); hdfs.allowSnapshot(root); rootNode = fsdir.getINode4Write(root.toString()).asDirectory(); assertTrue(rootNode.isSnapshottable()); assertEquals(INodeDirectorySnapshottable.SNAPSHOT_LIMIT, ((INodeDirectorySnapshottable) rootNode).getSnapshotQuota()); hdfs.allowSnapshot(root); rootNode = fsdir.getINode4Write(root.toString()).asDirectory(); assertTrue(rootNode.isSnapshottable()); assertEquals(INodeDirectorySnapshottable.SNAPSHOT_LIMIT, ((INodeDirectorySnapshottable) rootNode).getSnapshotQuota()); hdfs.disallowSnapshot(root); rootNode = fsdir.getINode4Write(root.toString()).asDirectory(); assertTrue(rootNode.isSnapshottable()); assertEquals(0, ((INodeDirectorySnapshottable) rootNode).getSnapshotQuota()); hdfs.disallowSnapshot(root); rootNode = fsdir.getINode4Write(root.toString()).asDirectory(); assertTrue(rootNode.isSnapshottable()); assertEquals(0, ((INodeDirectorySnapshottable) rootNode).getSnapshotQuota()); }