DatanodeUtil (Apache Hadoop HDFS 3.5.0 API)
Description: declaration: package: org.apache.hadoop.hdfs.server.datanode, class: DatanodeUtil

Package org.apache.hadoop.hdfs.server.datanode

# Class DatanodeUtil

java.lang.Object
org.apache.hadoop.hdfs.server.datanode.DatanodeUtil

@Private public class DatanodeUtil extends Object
Provide utility methods for Datanode.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `DISK_ERROR`
  `static final String`
  `UNLINK_BLOCK_SUFFIX`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DatanodeUtil()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static File`
  `createFileWithExistsCheck(FsVolumeSpi volume, org.apache.hadoop.hdfs.protocol.Block b, File f, FileIoProvider fileIoProvider)`
  Create a new file.
  `static boolean`
  `dirNoFilesRecursive(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 exist
  `static List<String>`
  `getAllSubDirNameForDataSetLock()`
  `static FileInputStream`
  `getMetaDataInputStream(org.apache.hadoop.hdfs.protocol.ExtendedBlock b, FsDatasetSpi<?> data)`
  `static String`
  `getMetaName(String blockName, long generationStamp)`
  `static File`
  `getUnlinkTmpFile(File f)`
  `static File`
  `idToBlockDir(File root, long blockId)`
  Get the directory where a finalized block with this ID should be stored.
  `static String`
  `idToBlockDirSuffix(long blockId)`
  Take an example.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### UNLINK_BLOCK_SUFFIX

    public static final String UNLINK_BLOCK_SUFFIX
    See Also:
      - Constant Field Values

  - ### DISK_ERROR

    public static final String DISK_ERROR
    See Also:
      - Constant Field Values

- ## 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

    public static String getMetaName(String blockName, long generationStamp)
    Returns:
      the meta name given the block name and generation stamp.

  - ### getUnlinkTmpFile

    public static File getUnlinkTmpFile(File f)
    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

    public static String idToBlockDirSuffix(long blockId)
    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

    public static File idToBlockDir(File root, long blockId)
    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 stored
      `blockId` -
    Returns:

  - ### getAllSubDirNameForDataSetLock

    public static List<String> 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`