DirectorySnapshottableFeature (Apache Hadoop HDFS 3.5.0 API)
Description: declaration: package: org.apache.hadoop.hdfs.server.namenode.snapshot, class: DirectorySnapshottableFeature

Package org.apache.hadoop.hdfs.server.namenode.snapshot

# 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.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class org.apache.hadoop.hdfs.server.namenode.snapshot.DirectoryWithSnapshotFeature

  `DirectoryWithSnapshotFeature.DirectoryDiff, DirectoryWithSnapshotFeature.DirectoryDiffList`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DirectorySnapshottableFeature(DirectoryWithSnapshotFeature feature)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Snapshot`
  `addSnapshot(INodeDirectory snapshotRoot, SnapshotManager snapshotManager, String name, LeaseManager leaseManager, long now)`
  Add a snapshot.
  `void`
  `computeContentSummary4Snapshot(BlockStoragePolicySuite bsps, ContentCounts counts)`
  `void`
  `dumpTreeRecursively(INodeDirectory snapshotRoot, PrintWriter out, StringBuilder prefix, int snapshot)`
  `byte[][]`
  `findRenameTargetPath(INodeDirectory snapshotRoot, INodeReference.WithName wn, int snapshotId)`
  We just found a deleted WithName node as the source of a rename operation.
  `int`
  `getNumSnapshots()`
  `Snapshot`
  `getSnapshot(byte[] snapshotName)`
  `Snapshot`
  `getSnapshotById(int sid)`
  `Snapshot`
  `getSnapshotByName(INodeDirectory snapshotRoot, String snapshotName)`
  Find the snapshot matching the given name.
  `ReadOnlyList<Snapshot>`
  `getSnapshotList()`
  `int`
  `getSnapshotQuota()`
  `Snapshot`
  `removeSnapshot(INode.ReclaimContext reclaimContext, INodeDirectory snapshotRoot, String snapshotName, long now, SnapshotManager snapshotManager)`
  Remove the snapshot with the given name from `snapshotsByNames`, and delete all the corresponding DirectoryDiff.
  `void`
  `renameSnapshot(String path, String oldName, String newName, long mtime)`
  Rename a snapshot
  `void`
  `setSnapshotQuota(int snapshotQuota)`
  `String`
  `toString()`

  ### Methods inherited from class org.apache.hadoop.hdfs.server.namenode.snapshot.DirectoryWithSnapshotFeature

  `addChild, cleanDirectory, clear, computeQuotaUsage4CurrentDirectory, destroyDstSubtree, getChild, getChildrenList, getDiffs, getLastSnapshotId, getSnapshotDirectory, removeChild, saveChild2Snapshot`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### DirectorySnapshottableFeature

    public DirectorySnapshottableFeature(DirectoryWithSnapshotFeature feature)

- ## 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)