繁体   English   中英

在hadoop中如何创建datanode路径?

[英]How datanode path is created in hadoop?

这是我用来将文件写入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 ——这条路径是在哪里生成的?

在hadoop中写入数据节点时如何定义路径结构?

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

这就是 hdfs 管理数据块的方式,你可以参考这个链接来了解它的一切:

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

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

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

IP 地址172.22.131.23是最初创建块池的 NameNode 的地址。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM