Class DatanodeUtil

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

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

  • 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