Class DatanodeUtil
java.lang.Object
org.apache.hadoop.hdfs.server.datanode.DatanodeUtil
Provide utility methods for Datanode.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FilecreateFileWithExistsCheck(FsVolumeSpi volume, org.apache.hadoop.hdfs.protocol.Block b, File f, FileIoProvider fileIoProvider) Create a new file.static booleandirNoFilesRecursive(FsVolumeSpi volume, File dir, FileIoProvider fileIoProvider) Checks whether there are any files anywhere in the directory tree rooted at dir (directories don't count as files). dir must existstatic FileInputStreamgetMetaDataInputStream(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, FsDatasetSpi<?> data) static StringgetMetaName(String blockName, long generationStamp) static Filestatic FileidToBlockDir(File root, long blockId) Get the directory where a finalized block with this ID should be stored.static StringidToBlockDirSuffix(long blockId) Take an example.
-
Field Details
-
UNLINK_BLOCK_SUFFIX
- See Also:
-
DISK_ERROR
- See Also:
-
-
Constructor Details
-
DatanodeUtil
public DatanodeUtil()
-
-
Method Details
-
createFileWithExistsCheck
public static File createFileWithExistsCheck(FsVolumeSpi volume, org.apache.hadoop.hdfs.protocol.Block b, File f, FileIoProvider fileIoProvider) throws IOException Create a new file.- Throws:
IOException- if the file already exists or if the file cannot be created.
-
getMetaName
- Returns:
- the meta name given the block name and generation stamp.
-
getUnlinkTmpFile
- Returns:
- the unlink file.
-
dirNoFilesRecursive
public static boolean dirNoFilesRecursive(FsVolumeSpi volume, File dir, FileIoProvider fileIoProvider) throws IOException Checks whether there are any files anywhere in the directory tree rooted at dir (directories don't count as files). dir must exist- Returns:
- true if there are no files
- Throws:
IOException- if unable to list subdirectories
-
idToBlockDirSuffix
Take an example. We hava a block with blockid mapping to: "/data1/hadoop/hdfs/datanode/current/BP-xxxx/current/finalized/subdir0/subdir1" We return "subdir0/subdir0".- Parameters:
blockId- the block id.- Returns:
- two-level subdir string where block will be stored.
-
idToBlockDir
Get the directory where a finalized block with this ID should be stored. Do not attempt to create the directory.- Parameters:
root- the root directory where finalized blocks are storedblockId-- Returns:
-
getAllSubDirNameForDataSetLock
-
getMetaDataInputStream
public static FileInputStream getMetaDataInputStream(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, FsDatasetSpi<?> data) throws IOException - Returns:
- the FileInputStream for the meta data of the given block.
- Throws:
FileNotFoundException- if the file not found.ClassCastException- if the underlying input stream is not a FileInputStream.IOException
-