Class SnapshotManager
java.lang.Object
org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotManager
- All Implemented Interfaces:
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
2. Lock the
1. Lock the
FSNamesystem lock in FSNamesystem before calling
into SnapshotManager methods.2. Lock the
FSDirectory lock for the SnapshotManager methods
if necessary.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSnapshotManager(org.apache.hadoop.conf.Configuration conf, FSDirectory fsdir) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the given snapshottable directory tosnapshottables.voidassertMarkedAsDeleted(INodesInPath iip, String snapshotName) static org.apache.hadoop.fs.XAttrGet the snapshot root directory for the given directory.voidcreateSnapshot(LeaseManager leaseManager, INodesInPath iip, String snapshotRoot, String snapshotName, long mtime) Create a snapshot of the given path.voiddeleteSnapshot(INodesInPath iip, String snapshotName, INode.ReclaimContext reclaimContext, long now) Delete a snapshot for a snapshottable directoryorg.apache.hadoop.hdfs.protocol.SnapshotDiffReportdiff(INodesInPath iip, String snapshotPath, String from, String to) Compute the difference between two snapshots of a directory, or between a snapshot of the directory and its current tree.org.apache.hadoop.hdfs.protocol.SnapshotDiffReportListingdiff(INodesInPath iip, String snapshotPath, String from, String to, byte[] startPath, int index, int snapshotDiffReportLimit) Compute the partial difference between two snapshots of a directory, or between a snapshot of the directory and its current tree.intReturns the maximum allowable snapshot ID based on the bit width of the snapshot ID.intintbooleanorg.apache.hadoop.hdfs.protocol.SnapshotStatus[]List all the snapshots under a snapshottable directory.Return the list of snapshotsorg.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus.Bean[]Return the list of snapshottable directoriesorg.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus[]getSnapshottableDirListing(String userName) List all the snapshottable directories that are owned by the current user.Find the source root directory where the snapshot will be taken for a given path.voidbooleanbooleanbooleanread(DataInput in, FSImageFormat.Loader loader) Read values ofsnapshotCounter,numSnapshots, and all snapshots from the DataInputvoidvoidremoveSnapshottable(List<INodeDirectory> toRemove) Remove snapshottable directories fromsnapshottablesvoidrenameSnapshot(INodesInPath iip, String snapshotRoot, String oldSnapshotName, String newSnapshotName, long now) Rename the given snapshotvoidresetSnapshottable(String path) Set the given snapshottable directory to non-snapshottable.voidsetSnapshottable(String path, boolean checkNestedSnapshottable) Set the given directory as a snapshottable directory.voidshutdown()static org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus.Beanstatic SnapshotInfo.Beanvoidwrite(DataOutput out) WritesnapshotCounter,numSnapshots, and all snapshots to the DataOutput.
-
Field Details
-
LOG
public static final org.slf4j.Logger LOG
-
-
Constructor Details
-
SnapshotManager
public SnapshotManager(org.apache.hadoop.conf.Configuration conf, FSDirectory fsdir) throws SnapshotException - Throws:
SnapshotException
-
-
Method Details
-
initThreadLocals
public void initThreadLocals() -
isSnapshotDeletionOrdered
public boolean isSnapshotDeletionOrdered() -
getSkipCaptureAccessTimeOnlyChange
public boolean getSkipCaptureAccessTimeOnlyChange()- Returns:
- skipCaptureAccessTimeOnlyChange
-
isAllowNestedSnapshots
public boolean isAllowNestedSnapshots() -
setSnapshottable
Set the given directory as a snapshottable directory. If the path is already a snapshottable directory, update the quota.- Throws:
IOException
-
addSnapshottable
Add the given snapshottable directory tosnapshottables. -
removeSnapshottable
Remove snapshottable directories fromsnapshottables -
resetSnapshottable
Set the given snapshottable directory to non-snapshottable.- Throws:
SnapshotException- if there are snapshots in the directory.IOException
-
getSnapshottableRoot
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
- Throws:
IOException
-
checkAndGetSnapshottableAncestorDir
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
- Throws:
IOException
-
isDescendantOfSnapshotRoot
-
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 pathsnapshotName- 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 deletednow- 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 snapshotnewSnapshotName- New name of the snapshotnow- 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
WritesnapshotCounter,numSnapshots, and all snapshots to the DataOutput.- Throws:
IOException
-
read
Read values ofsnapshotCounter,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. IfuserNameis 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:SnapshotStatsMXBeanReturn the list of snapshottable directories- Specified by:
getSnapshottableDirectoriesin interfaceSnapshotStatsMXBean- Returns:
- the list of snapshottable directories
-
getSnapshots
Description copied from interface:SnapshotStatsMXBeanReturn the list of snapshots- Specified by:
getSnapshotsin interfaceSnapshotStatsMXBean- Returns:
- the list of snapshots
-
toBean
public static org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus.Bean toBean(INodeDirectory d) -
toBean
-