org.apache.hadoop.hdfs.server.namenode.snapshot
Class SnapshotManager

java.lang.Object
  extended by 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.


Constructor Summary
SnapshotManager(org.apache.hadoop.hdfs.server.namenode.FSDirectory fsdir)
           
 
Method Summary
 void addSnapshottable(INodeDirectory dir)
          Add the given snapshottable directory to snapshottables.
 void clearSnapshottableDirs()
           
 String createSnapshot(String path, String snapshotName)
          Create a snapshot of the given path.
 void deleteSnapshot(String path, String snapshotName, INode.BlocksMapUpdateInfo collectedBlocks, List<org.apache.hadoop.hdfs.server.namenode.INode> removedINodes)
          Delete a snapshot for a snapshottable directory
 SnapshotDiffReport diff(String path, String from, String to)
          Compute the difference between two snapshots of a directory, or between a snapshot of the directory and its current tree.
 int getMaxSnapshotID()
          Returns the maximum allowable snapshot ID based on the bit width of the snapshot ID.
 int getNumSnapshots()
           
 int getNumSnapshottableDirs()
           
 SnapshotInfo.Bean[] getSnapshots()
          Return the list of snapshots
 SnapshottableDirectoryStatus.Bean[] getSnapshottableDirectories()
          Return the list of snapshottable directories
 SnapshottableDirectoryStatus[] getSnapshottableDirListing(String userName)
          List all the snapshottable directories that are owned by the current user.
 INodeDirectory getSnapshottableRoot(String path)
          Find the source root directory where the snapshot will be taken for a given path.
 Map<Integer,org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot> read(DataInput in, FSImageFormat.Loader loader)
          Read values of snapshotCounter, numSnapshots, and all snapshots from the DataInput
 void registerMXBean()
           
 void removeSnapshottable(List<INodeDirectory> toRemove)
          Remove snapshottable directories from snapshottables
 void renameSnapshot(String path, String oldSnapshotName, String newSnapshotName)
          Rename the given snapshot
 void resetSnapshottable(String path)
          Set the given snapshottable directory to non-snapshottable.
 void setSnapshottable(String path, boolean checkNestedSnapshottable)
          Set the given directory as a snapshottable directory.
 void shutdown()
           
static SnapshottableDirectoryStatus.Bean toBean(INodeDirectory d)
           
static SnapshotInfo.Bean toBean(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot s)
           
 void write(DataOutput out)
          Write snapshotCounter, numSnapshots, and all snapshots to the DataOutput.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SnapshotManager

public SnapshotManager(org.apache.hadoop.hdfs.server.namenode.FSDirectory fsdir)
Method Detail

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(String path)
                                    throws IOException
Find the source root directory where the snapshot will be taken for a given path.

Parameters:
path - The directory path where the snapshot will be taken.
Returns:
Snapshottable directory.
Throws:
IOException - Throw IOException when the given path does not lead to an existing snapshottable directory.

createSnapshot

public String createSnapshot(String path,
                             String snapshotName)
                      throws IOException
Create a snapshot of the given path. It is assumed that the caller will perform synchronization.

Parameters:
path - The directory path where the snapshot will be taken.
snapshotName - The name of the snapshot.
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(String path,
                           String snapshotName,
                           INode.BlocksMapUpdateInfo collectedBlocks,
                           List<org.apache.hadoop.hdfs.server.namenode.INode> removedINodes)
                    throws IOException
Delete a snapshot for a snapshottable directory

Parameters:
path - Path to the directory where the snapshot was taken
snapshotName - Name of the snapshot to be deleted
collectedBlocks - Used to collect information to update blocksMap
Throws:
IOException

renameSnapshot

public void renameSnapshot(String path,
                           String oldSnapshotName,
                           String newSnapshotName)
                    throws IOException
Rename the given snapshot

Parameters:
path - The directory path where the snapshot was taken
oldSnapshotName - Old name of the snapshot
newSnapshotName - New name of the snapshot
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,org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot> read(DataInput in,
                                                                                  FSImageFormat.Loader loader)
                                                                           throws IOException
Read values of snapshotCounter, numSnapshots, and all snapshots from the DataInput

Throws:
IOException

getSnapshottableDirListing

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

diff

public SnapshotDiffReport diff(String path,
                               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

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.

registerMXBean

public void registerMXBean()

shutdown

public void shutdown()

getSnapshottableDirectories

public 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 SnapshottableDirectoryStatus.Bean toBean(INodeDirectory d)

toBean

public static SnapshotInfo.Bean toBean(org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot s)


Copyright © 2014 Apache Software Foundation. All Rights Reserved.