代码之家  ›  专栏  ›  技术社区  ›  Tom Taylor

如何在hadoop中创建datanode路径?

  •  3
  • Tom Taylor  · 技术社区  · 7 年前

    这是我用来编写文件的示例片段 hdfs

    import java.io.BufferedInputStream;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.URI;
    import java.net.URISyntaxException;
    
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.fs.FileSystem;
    import org.apache.hadoop.fs.Path;
    import org.apache.hadoop.io.IOUtils;
    import org.apache.hadoop.util.Progressable;
    
    public class WriteFileToHDFS {
      public static void main(String[] args) throws IOException, URISyntaxException 
       {
          System.setProperty("hadoop.home.dir", "/");   
          System.setProperty("HADOOP_USER_NAME", "hdfs");  
    
          //1. Get the instance of COnfiguration
          Configuration configuration = new Configuration();
    
          //2. Create an InputStream to read the data from local file
          InputStream inputStream = new BufferedInputStream(new FileInputStream("/Users/rabbit/Research/hadoop/sample_files/TAO.mp4"));  
    
          //3. Get the HDFS instance
          FileSystem hdfs = FileSystem.get(new URI("hdfs://192.168.143.150:9000"), configuration);  
    
          //4. Open a OutputStream to write the data, this can be obtained from the FileSytem
          OutputStream outputStream = hdfs.create(new Path("hdfs://192.168.143.150:9000/filestore/TAO.mp4"),   
          new Progressable() {  
                  @Override
                  public void progress() {
                    System.out.println("....");
                  }
            });
          try
          {
            IOUtils.copyBytes(inputStream, outputStream, 4096, false); 
          }
          finally
          {
            IOUtils.closeStream(inputStream);
            IOUtils.closeStream(outputStream);
          } 
      }
    }
    

    我希望这可以写成 /data/hadoop-data/dn/current/blk_1073741869 而是写为 /data/hadoop-data/dn/current/BP-1308070615-172.22.131.23-1533215887051/current/finalized/subdir0/subdir0/blk_1073741869 BP-1308070615-172.22.131.23-1533215887051/current/finalized/subdir0/subdir0 -生成了此路径?

    2 回复  |  直到 7 年前
        1
  •  1
  •   Abdulhafeth Sartawi    7 年前

    BP代表“block pool”,是属于单个HDFS命名空间的块的集合。

    https://hortonworks.com/blog/hdfs-metadata-directories-explained/

        2
  •  0
  •   Tom Taylor    7 年前

    英国石油公司 代表“块池”,是属于单个HDFS命名空间的块的集合。

    下一部分是 ,是随机生成的整数。

    172.22.131.23条

    最后一部分 是命名空间的创建时间。

    推荐文章