Class SnapshotManager

java.lang.Object
org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotManager
All Implemented Interfaces:
SnapshotStatsMXBean

public class SnapshotManager extends Object implements SnapshotStatsMXBean
Manage snapshottable directories and their snapshots. This class includes operations that create, access, modify snapshots and/or snapshot-related data. In general, the locking structure of snapshot operations is:
1. Lock the FSNamesystem lock in FSNamesystem before calling into SnapshotManager methods.
2. Lock the FSDirectory lock for the SnapshotManager methods if necessary.
  • Field Details

    • LOG

      public static final org.slf4j.Logger LOG
  • Constructor Details

  • Method Details

    • initThreadLocals

      public void initThreadLocals()
    • isSnapshotDeletionOrdered

      public boolean isSnapshotDeletionOrdered()
    • getSkipCaptureAccessTimeOnlyChange

      public boolean getSkipCaptureAccessTimeOnlyChange()
      Returns:
      skipCaptureAccessTimeOnlyChange
    • isAllowNestedSnapshots

      public boolean isAllowNestedSnapshots()
    • setSnapshottable

      public void setSnapshottable(String path, boolean checkNestedSnapshottable) throws IOException
      Set the given directory as a snapshottable directory. If the path is already a snapshottable directory, update the quota.
      Throws:
      IOException
    • addSnapshottable

      public void addSnapshottable(INodeDirectory dir)
      Add the given snapshottable directory to snapshottables.
    • removeSnapshottable

      public void removeSnapshottable(List<INodeDirectory> toRemove)
      Remove snapshottable directories from snapshottables
    • resetSnapshottable

      public void resetSnapshottable(String path) throws IOException
      Set the given snapshottable directory to non-snapshottable.
      Throws:
      SnapshotException - if there are snapshots in the directory.
      IOException
    • getSnapshottableRoot

      public INodeDirectory getSnapshottableRoot(INodesInPath iip) throws IOException
      Find the source root directory where the snapshot will be taken for a given path.
      Returns:
      Snapshottable directory.
      Throws:
      IOException - Throw IOException when the given path does not lead to an existing snapshottable directory.
    • assertMarkedAsDeleted

      public void assertMarkedAsDeleted(INodesInPath iip, String snapshotName) throws IOException
      Throws:
      IOException
    • checkAndGetSnapshottableAncestorDir

      public INodeDirectory checkAndGetSnapshottableAncestorDir(INodesInPath iip) throws IOException
      Get the snapshot root directory for the given directory. The given directory must either be a snapshot root or a descendant of any snapshot root directories.
      Parameters:
      iip - INodesInPath for the directory to get snapshot root.
      Returns:
      the snapshot root INodeDirectory
      Throws:
      IOException
    • getSnapshottableAncestorDir

      public INodeDirectory getSnapshottableAncestorDir(INodesInPath iip) throws IOException
      Throws:
      IOException
    • isDescendantOfSnapshotRoot

      public boolean isDescendantOfSnapshotRoot(INodeDirectory dir)
    • createSnapshot

      public String createSnapshot(LeaseManager leaseManager, INodesInPath iip, String snapshotRoot, String snapshotName, long mtime) throws IOException
      Create a snapshot of the given path. It is assumed that the caller will perform synchronization.
      Parameters:
      iip - the INodes resolved from the snapshottable directory's path
      snapshotName - The name of the snapshot.
      mtime - is the snapshot creation time set by Time.now().
      Throws:
      IOException - Throw IOException when 1) the given path does not lead to an existing snapshottable directory, and/or 2) there exists a snapshot with the given name for the directory, and/or 3) snapshot number exceeds quota
    • deleteSnapshot

      public void deleteSnapshot(INodesInPath iip, String snapshotName, INode.ReclaimContext reclaimContext, long now) throws IOException
      Delete a snapshot for a snapshottable directory
      Parameters:
      snapshotName - Name of the snapshot to be deleted
      now - is the snapshot deletion time set by Time.now().
      reclaimContext - Used to collect information to reclaim blocks and inodes
      Throws:
      IOException
    • renameSnapshot

      public void renameSnapshot(INodesInPath iip, String snapshotRoot, String oldSnapshotName, String newSnapshotName, long now) throws IOException
      Rename the given snapshot
      Parameters:
      oldSnapshotName - Old name of the snapshot
      newSnapshotName - New name of the snapshot
      now - is the snapshot modification time set by Time.now().
      Throws:
      IOException - Throw IOException when 1) the given path does not lead to an existing snapshottable directory, and/or 2) the snapshot with the old name does not exist for the directory, and/or 3) there exists a snapshot with the new name for the directory
    • getNumSnapshottableDirs

      public int getNumSnapshottableDirs()
    • getNumSnapshots

      public int getNumSnapshots()
    • write

      public void write(DataOutput out) throws IOException
      Write snapshotCounter, numSnapshots, and all snapshots to the DataOutput.
      Throws:
      IOException
    • read

      public Map<Integer,Snapshot> read(DataInput in, FSImageFormat.Loader loader) throws IOException
      Read values of snapshotCounter, numSnapshots, and all snapshots from the DataInput
      Throws:
      IOException
    • getSnapshottableDirListing

      public org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus[] getSnapshottableDirListing(String userName)
      List all the snapshottable directories that are owned by the current user.
      Parameters:
      userName - Current user name.
      Returns:
      Snapshottable directories that are owned by the current user, represented as an array of SnapshottableDirectoryStatus. If userName is null, return all the snapshottable dirs.
    • getSnapshotListing

      public org.apache.hadoop.hdfs.protocol.SnapshotStatus[] getSnapshotListing(INodesInPath iip) throws IOException
      List all the snapshots under a snapshottable directory.
      Throws:
      IOException
    • diff

      public org.apache.hadoop.hdfs.protocol.SnapshotDiffReport diff(INodesInPath iip, String snapshotPath, String from, String to) throws IOException
      Compute the difference between two snapshots of a directory, or between a snapshot of the directory and its current tree.
      Throws:
      IOException
    • diff

      public org.apache.hadoop.hdfs.protocol.SnapshotDiffReportListing diff(INodesInPath iip, String snapshotPath, String from, String to, byte[] startPath, int index, int snapshotDiffReportLimit) throws IOException
      Compute the partial difference between two snapshots of a directory, or between a snapshot of the directory and its current tree.
      Throws:
      IOException
    • clearSnapshottableDirs

      public void clearSnapshottableDirs()
    • getMaxSnapshotID

      public int getMaxSnapshotID()
      Returns the maximum allowable snapshot ID based on the bit width of the snapshot ID.
      Returns:
      maximum allowable snapshot ID.
    • buildXAttr

      public static org.apache.hadoop.fs.XAttr buildXAttr()
    • registerMXBean

      public void registerMXBean()
    • shutdown

      public void shutdown()
    • getSnapshottableDirectories

      public org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus.Bean[] getSnapshottableDirectories()
      Description copied from interface: SnapshotStatsMXBean
      Return the list of snapshottable directories
      Specified by:
      getSnapshottableDirectories in interface SnapshotStatsMXBean
      Returns:
      the list of snapshottable directories
    • getSnapshots

      public SnapshotInfo.Bean[] getSnapshots()
      Description copied from interface: SnapshotStatsMXBean
      Return the list of snapshots
      Specified by:
      getSnapshots in interface SnapshotStatsMXBean
      Returns:
      the list of snapshots
    • toBean

      public static org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus.Bean toBean(INodeDirectory d)
    • toBean

      public static SnapshotInfo.Bean toBean(Snapshot s)