Class FSDirectory
java.lang.Object
org.apache.hadoop.hdfs.server.namenode.FSDirectory
- All Implemented Interfaces:
Closeable,AutoCloseable
Both FSDirectory and FSNamesystem manage the state of the namespace.
FSDirectory is a pure in-memory data structure, all of whose operations
happen entirely in memory. In contrast, FSNamesystem persists the operations
to the disk.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byte[]static final Stringstatic final byte[]static final Stringstatic final org.apache.hadoop.hdfs.protocol.HdfsFileStatusstatic final Stringstatic final org.apache.hadoop.hdfs.protocol.HdfsFileStatusfinal EncryptionZoneManager -
Method Summary
Modifier and TypeMethodDescriptionaddLastINode(INodesInPath existing, INode inode, org.apache.hadoop.fs.permission.FsPermission modes, boolean checkQuota, Optional<QuotaCounts> quotaCount) Add a child to the end of the path specified by INodesInPath.final voidThis is to handle encryption zone for rootDir when loading from fsimage, and should only be called during NN restart.final voidaddToInodeMap(INode inode) This method is always called with writeLock of FSDirectory held.voidclose()Shutdown the filestoregetInode(long id) Get the inode from inodeMap based on its inode id.GetINodeassociated with the file / directory.getINode(String src, FSDirectory.DirOp dirOp) GetINodeassociated with the file / directory.getINode4Write(String src) GetINodeassociated with the file / directory.getINodesInPath(byte[][] components, FSDirectory.DirOp dirOp) getINodesInPath(String src, FSDirectory.DirOp dirOp) Resolves the given path into inodes.longintintstatic byte[][]getPathComponents(INode inode) Given an INode get all the path complents leading to it from the root.getRoot()EnumCounters<org.apache.hadoop.fs.StorageType>getStorageTypeDeltas(byte storagePolicyID, long dsDelta, short oldRep, short newRep) longstatic booleanisExactReservedName(byte[][] components) static booleanbooleanIndicates whether the image loading is complete or not.booleanisNonEmptyDirectory(INodesInPath inodesInPath) booleanbooleanstatic booleanisReservedName(String src) Check if a given path is reservedstatic booleanisReservedName(INode inode) Check if a given inode name is reservedfinal voidremoveFromInodeMap(List<? extends INode> inodes) This method is always called with writeLock of FSDirectory held.longRemove the last inode in the path from the namespace.voidresetLastInodeIdWithoutChecking(long newValue) Should only be used for tests to reset to any value.resolvePath(FSPermissionChecker pc, String src, FSDirectory.DirOp dirOp) Resolves a given path into an INodesInPath.voidvoidsetMaxDirItems(int newVal) voidsetPosixAclInheritanceEnabled(boolean posixAclInheritanceEnabled) This method should only be used from internal paths and not those provided directly by a user.voidupdateCount(INodesInPath iip, INode.QuotaDelta quotaDelta, boolean check) voidupdateSpaceForCompleteBlock(BlockInfo completeBlk, INodesInPath inodes) Update the cached quota space for a block that is being completed.
-
Field Details
-
DOT_RESERVED_STRING
- See Also:
-
DOT_RESERVED_PATH_PREFIX
- See Also:
-
DOT_RESERVED
public static final byte[] DOT_RESERVED -
DOT_INODES_STRING
- See Also:
-
DOT_INODES
public static final byte[] DOT_INODES -
DOT_RESERVED_STATUS
public static final org.apache.hadoop.hdfs.protocol.HdfsFileStatus DOT_RESERVED_STATUS -
DOT_SNAPSHOT_DIR_STATUS
public static final org.apache.hadoop.hdfs.protocol.HdfsFileStatus DOT_SNAPSHOT_DIR_STATUS -
ezManager
-
-
Method Details
-
setINodeAttributeProvider
-
getListLimit
public int getListLimit() -
isImageLoaded
public boolean isImageLoaded()Indicates whether the image loading is complete or not.- Returns:
- true if image loading is complete, false otherwise
-
getProtectedDirectories
-
isProtectedSubDirectoriesEnable
public boolean isProtectedSubDirectoriesEnable() -
setMaxDirItems
public void setMaxDirItems(int newVal) -
getMaxDirItems
public int getMaxDirItems() -
getRoot
- Returns:
- the root directory inode.
-
getBlockStoragePolicySuite
-
isPosixAclInheritanceEnabled
@VisibleForTesting public boolean isPosixAclInheritanceEnabled() -
setPosixAclInheritanceEnabled
@VisibleForTesting public void setPosixAclInheritanceEnabled(boolean posixAclInheritanceEnabled) -
close
Shutdown the filestore- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
resolvePath
@VisibleForTesting public INodesInPath resolvePath(FSPermissionChecker pc, String src, FSDirectory.DirOp dirOp) throws org.apache.hadoop.fs.UnresolvedLinkException, FileNotFoundException, org.apache.hadoop.security.AccessControlException, org.apache.hadoop.fs.ParentNotDirectoryException Resolves a given path into an INodesInPath. All ancestor inodes that exist are validated as traversable directories. Symlinks in the ancestry will generate an UnresolvedLinkException. The returned IIP will be an accessible path that also passed additional sanity checks based on how the path will be used as specified by the DirOp. READ: Expands reserved paths and performs permission checks during traversal. WRITE: In addition to READ checks, ensures the path is not a snapshot path. CREATE: In addition to WRITE checks, ensures path does not contain illegal character sequences.- Parameters:
pc- A permission checker for traversal checks. Pass null for no permission checks.src- The path to resolve.dirOp- TheFSDirectory.DirOpthat controls additional checks.- Returns:
- if the path indicates an inode, return path after replacing up to
<inodeid>with the corresponding path of the inode, else the path insrcas is. If the path refers to a path in the "raw" directory, return the non-raw pathname. - Throws:
FileNotFoundExceptionorg.apache.hadoop.security.AccessControlExceptionorg.apache.hadoop.fs.ParentNotDirectoryExceptionorg.apache.hadoop.fs.UnresolvedLinkException
-
unprotectedResolvePath
This method should only be used from internal paths and not those provided directly by a user. It resolves a given path into an INodesInPath in a similar way to resolvePath(...), only traversal and permissions are not checked.- Parameters:
src- The path to resolve.- Returns:
- if the path indicates an inode, return path after replacing up to
<inodeid>with the corresponding path of the inode, else the path insrcas is. If the path refers to a path in the "raw" directory, return the non-raw pathname. - Throws:
FileNotFoundException
-
isNonEmptyDirectory
- Returns:
- true if the path is a non-empty directory; otherwise, return false.
-
updateCount
public void updateCount(INodesInPath iip, INode.QuotaDelta quotaDelta, boolean check) throws org.apache.hadoop.hdfs.protocol.QuotaExceededException - Throws:
org.apache.hadoop.hdfs.protocol.QuotaExceededException
-
updateSpaceForCompleteBlock
public void updateSpaceForCompleteBlock(BlockInfo completeBlk, INodesInPath inodes) throws IOException Update the cached quota space for a block that is being completed. Must only be called once, as the block is being completed.- Parameters:
completeBlk- - Completed block for which to update spaceinodes- - INodes in path to file containing completeBlk; if null this will be resolved internally- Throws:
IOException
-
getStorageTypeDeltas
public EnumCounters<org.apache.hadoop.fs.StorageType> getStorageTypeDeltas(byte storagePolicyID, long dsDelta, short oldRep, short newRep) -
addLastINode
@VisibleForTesting public INodesInPath addLastINode(INodesInPath existing, INode inode, org.apache.hadoop.fs.permission.FsPermission modes, boolean checkQuota, Optional<QuotaCounts> quotaCount) throws org.apache.hadoop.hdfs.protocol.QuotaExceededException Add a child to the end of the path specified by INodesInPath.- Parameters:
existing- the INodesInPath containing all the ancestral INodesinode- the new INode to addmodes- create modescheckQuota- whether to check quota- Returns:
- an INodesInPath instance containing the new INode
- Throws:
org.apache.hadoop.hdfs.protocol.QuotaExceededException
-
removeLastINode
Remove the last inode in the path from the namespace. Note: the caller needs to update the ancestors' quota count.- Returns:
- -1 for failing to remove; 0 for removing a reference whose referred inode has other reference nodes; 1 otherwise.
-
getYieldCount
@VisibleForTesting public long getYieldCount() -
getINodeMap
-
addToInodeMap
This method is always called with writeLock of FSDirectory held. -
addRootDirToEncryptionZone
This is to handle encryption zone for rootDir when loading from fsimage, and should only be called during NN restart. -
removeFromInodeMap
This method is always called with writeLock of FSDirectory held. -
getInode
Get the inode from inodeMap based on its inode id.- Parameters:
id- The given id- Returns:
- The inode associated with the given id
-
getPathComponents
Given an INode get all the path complents leading to it from the root. If an Inode corresponding to C is given in /A/B/C, the returned patch components will be {root, A, B, C}. Note that this method cannot handle scenarios where the inode is in a snapshot. -
isReservedName
Check if a given inode name is reserved -
isReservedName
Check if a given path is reserved -
isExactReservedName
-
isExactReservedName
public static boolean isExactReservedName(byte[][] components) -
getINodesInPath
public INodesInPath getINodesInPath(String src, FSDirectory.DirOp dirOp) throws org.apache.hadoop.fs.UnresolvedLinkException, org.apache.hadoop.security.AccessControlException, org.apache.hadoop.fs.ParentNotDirectoryException Resolves the given path into inodes. Reserved paths are not handled and permissions are not verified. Client supplied paths should be resolved viaresolvePath(FSPermissionChecker, String, DirOp). This method should only be used by internal methods.- Returns:
- the
INodesInPathcontaining all inodes in the path. - Throws:
org.apache.hadoop.fs.UnresolvedLinkExceptionorg.apache.hadoop.fs.ParentNotDirectoryExceptionorg.apache.hadoop.security.AccessControlException
-
getINodesInPath
public INodesInPath getINodesInPath(byte[][] components, FSDirectory.DirOp dirOp) throws org.apache.hadoop.fs.UnresolvedLinkException, org.apache.hadoop.security.AccessControlException, org.apache.hadoop.fs.ParentNotDirectoryException - Throws:
org.apache.hadoop.fs.UnresolvedLinkExceptionorg.apache.hadoop.security.AccessControlExceptionorg.apache.hadoop.fs.ParentNotDirectoryException
-
getINode
@VisibleForTesting public INode getINode(String src) throws org.apache.hadoop.fs.UnresolvedLinkException, org.apache.hadoop.security.AccessControlException, org.apache.hadoop.fs.ParentNotDirectoryException GetINodeassociated with the file / directory. SeegetINode(String, DirOp)- Throws:
org.apache.hadoop.fs.UnresolvedLinkExceptionorg.apache.hadoop.security.AccessControlExceptionorg.apache.hadoop.fs.ParentNotDirectoryException
-
getINode4Write
@VisibleForTesting public INode getINode4Write(String src) throws org.apache.hadoop.fs.UnresolvedLinkException, org.apache.hadoop.security.AccessControlException, FileNotFoundException, org.apache.hadoop.fs.ParentNotDirectoryException GetINodeassociated with the file / directory. SeegetINode(String, DirOp)- Throws:
org.apache.hadoop.fs.UnresolvedLinkExceptionorg.apache.hadoop.security.AccessControlExceptionFileNotFoundExceptionorg.apache.hadoop.fs.ParentNotDirectoryException
-
getINode
public INode getINode(String src, FSDirectory.DirOp dirOp) throws org.apache.hadoop.fs.UnresolvedLinkException, org.apache.hadoop.security.AccessControlException, org.apache.hadoop.fs.ParentNotDirectoryException GetINodeassociated with the file / directory.- Throws:
org.apache.hadoop.fs.UnresolvedLinkExceptionorg.apache.hadoop.security.AccessControlExceptionorg.apache.hadoop.fs.ParentNotDirectoryException
-
getLastInodeId
public long getLastInodeId()- Returns:
- the last inode ID.
-
resetLastInodeIdWithoutChecking
@VisibleForTesting public void resetLastInodeIdWithoutChecking(long newValue) Should only be used for tests to reset to any value.- Parameters:
newValue- new value to set to
-