Class DirectorySnapshottableFeature

java.lang.Object
org.apache.hadoop.hdfs.server.namenode.snapshot.DirectoryWithSnapshotFeature
org.apache.hadoop.hdfs.server.namenode.snapshot.DirectorySnapshottableFeature
All Implemented Interfaces:
INode.Feature

@Private public class DirectorySnapshottableFeature extends DirectoryWithSnapshotFeature
A directory with this feature is a snapshottable directory, where snapshots can be taken. This feature extends DirectoryWithSnapshotFeature, and maintains extra information about all the snapshots taken on this directory.
  • Constructor Details

  • Method Details

    • getNumSnapshots

      public int getNumSnapshots()
      Returns:
      the number of existing snapshots.
    • getSnapshot

      public Snapshot getSnapshot(byte[] snapshotName)
      Returns:
      the snapshot with the given name.
    • getSnapshotById

      public Snapshot getSnapshotById(int sid)
    • getSnapshotList

      public ReadOnlyList<Snapshot> getSnapshotList()
      Returns:
      snapshotsByNames as a ReadOnlyList
    • renameSnapshot

      public void renameSnapshot(String path, String oldName, String newName, long mtime) throws SnapshotException
      Rename a snapshot
      Parameters:
      path - The directory path where the snapshot was taken. Used for generating exception message.
      oldName - Old name of the snapshot
      newName - New name the snapshot will be renamed to
      mtime - The snapshot modification time set by Time.now().
      Throws:
      SnapshotException - Throw SnapshotException when either the snapshot with the old name does not exist or a snapshot with the new name already exists
    • getSnapshotQuota

      public int getSnapshotQuota()
    • setSnapshotQuota

      public void setSnapshotQuota(int snapshotQuota)
    • addSnapshot

      public Snapshot addSnapshot(INodeDirectory snapshotRoot, SnapshotManager snapshotManager, String name, LeaseManager leaseManager, long now) throws SnapshotException
      Add a snapshot.
      Parameters:
      snapshotRoot - Root of the snapshot.
      snapshotManager - SnapshotManager Instance.
      name - Name of the snapshot.
      leaseManager -
      Throws:
      SnapshotException - Throw SnapshotException when there is a snapshot with the same name already exists or snapshot quota exceeds
    • removeSnapshot

      public Snapshot removeSnapshot(INode.ReclaimContext reclaimContext, INodeDirectory snapshotRoot, String snapshotName, long now, SnapshotManager snapshotManager) throws SnapshotException
      Remove the snapshot with the given name from snapshotsByNames, and delete all the corresponding DirectoryDiff.
      Parameters:
      reclaimContext - records blocks and inodes that need to be reclaimed
      snapshotRoot - The directory where we take snapshots
      snapshotName - The name of the snapshot to be removed
      now - The snapshot deletion time set by Time.now().
      Returns:
      The removed snapshot. Null if no snapshot with the given name exists.
      Throws:
      SnapshotException
    • computeContentSummary4Snapshot

      public void computeContentSummary4Snapshot(BlockStoragePolicySuite bsps, ContentCounts counts) throws org.apache.hadoop.security.AccessControlException
      Overrides:
      computeContentSummary4Snapshot in class DirectoryWithSnapshotFeature
      Throws:
      org.apache.hadoop.security.AccessControlException
    • getSnapshotByName

      public Snapshot getSnapshotByName(INodeDirectory snapshotRoot, String snapshotName) throws SnapshotException
      Find the snapshot matching the given name.
      Parameters:
      snapshotRoot - The directory where snapshots were taken.
      snapshotName - The name of the snapshot.
      Returns:
      The corresponding snapshot. Null if snapshotName is null or empty.
      Throws:
      SnapshotException - If snapshotName is not null or empty, but there is no snapshot matching the name.
    • findRenameTargetPath

      public byte[][] findRenameTargetPath(INodeDirectory snapshotRoot, INodeReference.WithName wn, int snapshotId)
      We just found a deleted WithName node as the source of a rename operation. However, we should include it in our snapshot diff report as rename only if the rename target is also under the same snapshottable directory.
    • toString

      public String toString()
      Overrides:
      toString in class DirectoryWithSnapshotFeature
    • dumpTreeRecursively

      @VisibleForTesting public void dumpTreeRecursively(INodeDirectory snapshotRoot, PrintWriter out, StringBuilder prefix, int snapshot)