zoukankan      html  css  js  c++  java
  • 第十二章 HDFS的读写流程

    一、HDFS写数据流程

    #1.客户端通过Distributed File System模块向NameNode请求上传文件,NameNode检查目标文件是否已存在,父目录是否存在。
    
    #2.NameNode返回是否可以上传。
    
    #3.客户端请求第一个 Block上传到哪几个DataNode服务器上。
    
    #4.NameNode返回3个DataNode节点,分别为dn1、dn2、dn3。
    
    #5.客户端通过FSDataOutputStream模块请求dn1上传数据,dn1收到请求会继续调用dn2,然后dn2调用dn3,将这个通信管道建立完成。
    
    #6.dn1、dn2、dn3逐级应答客户端。
    
    #7.客户端开始往dn1上传第一个Block(先从磁盘读取数据放到一个本地内存缓存),以Packet为单位,dn1收到一个Packet就会传给dn2,dn2传给dn3;dn1每传一个packet会放入一个应答队列等待应答。
    
    #8.当一个Block传输完成之后,客户端再次请求NameNode上传第二个Block的服务器。(重复执行3-7步)。
    

    二、网络拓扑-节点距离计算

    在HDFS写数据的过程中,NameNode会选择距离待上传数据最近距离的DataNode接收数据。那么这个最近距离怎么计算呢?
    
    #节点距离:两个节点到达最近的共同祖先的距离总和。
    

    例如,假设有数据中心d1机架r1中的节点n1。该节点可以表示为/d1/r1/n1。利用这种标记,这里给出四种距离描述。
    大家算一算每两个节点之间的距离。
    

    三、机架感知(副本存储节点选择)

    1.机架感知说明

    (1)官方说明
     官方文档地址:http://hadoop.apache.org/docs/r3.1.3/hadoop-project-dist/hadoop-hdfs/HdfsDesign.html#Data_Replication
    
    For the common case, when the replication factor is three, HDFS’s placement policy is to put one replica on the local machine if the writer is on a datanode, otherwise on a random datanode, another replica on a node in a different (remote) rack, and the last on a different node in the same remote rack. This policy cuts the inter-rack write traffic which generally improves write performance. The chance of rack failure is far less than that of node failure; this policy does not impact data reliability and availability guarantees. However, it does reduce the aggregate network bandwidth used when reading data since a block is placed in only two unique racks rather than three. With this policy, the replicas of a file do not evenly distribute across the racks. One third of replicas are on one node, two thirds of replicas are on one rack, and the other third are evenly distributed across the remaining racks. This policy improves write performance without compromising data reliability or read performance.
    
    (2)源码说明
    Crtl + n 查找BlockPlacementPolicyDefault,在该类中查找chooseTargetInOrder方法。
    

    2.Hadoop3.x副本节点选择

    四、HDFS读数据流程

    #1.客户端通过Distributed File System向NameNode请求下载文件,NameNode通过查询元数据,找到文件块所在的DataNode地址。
    
    #2.挑选一台DataNode(就近原则,然后随机)服务器,请求读取数据。
    
    #3.DataNode开始传输数据给客户端(从磁盘里面读取数据输入流,以Packet为单位来做校验)。
    
    #4.客户端以Packet为单位接收,先在本地缓存,然后写入目标文件。
    
  • 相关阅读:
    2014.5.20知识点学习:void及void指针含义的深刻解析(转载)
    2014.5.20知识点学习:void与void*(转载)
    2014.5.19知识点学习:上下文切换
    编写“全选”按钮来操作大量复选框
    排序算法(冒泡排序,选择排序,插入排序,快速排序)
    算法基础
    Git &GitHub
    flask 上下文管理 &源码剖析
    rest-framework框架的基本组件
    Django的FBV和CB
  • 原文地址:https://www.cnblogs.com/jhno1/p/15233517.html
Copyright © 2011-2022 走看看