产生问题于数据集群的数节点存储磁盘大小不同,造成使用一段时间以后容量小的磁盘空间紧张。
其实,早期配置了磁盘使用存储策略,就能解决该问题,部分网来上说这个策略无效,再hadoop2.0.1 本版有效,该版本应用于CHD4.6中。
为了找到准确的程序定位点,参考了以下的Hadoop设计文档。
参考
Hadoop中HDFS文件系统的Append/Hflush/Read设计文档:
http://blog.csdn.net/chenpingbupt/article/details/7972589
文档中给出:
在一个DN的disk中,每个DN具有三个目录:current em bw,current包含finallized的replica,tmp包含temporary replica,rbw包含rbw,rwr,rur replicas。当一个replica第一次被dfs client发起请求而创建的时候,将会放到rbw中。当第一次创建是在block replication和clust balance过程中发起的话,replica就会放置到tmp中。一旦一个replica被finallized,他就会被move到current 中。当一个DN重启之后,tmp中的replica将会被删除,rbw中的将会被加载为rwr状态,current中的会load为finallized 状态
我们就从tmp 或 rbw 文件创建开始。
1.参见java class BlockPoolSlice
从类的描述中看出BlockPoolSlice 是创建集群数据block的基础。
这是创建基础文件的方法。
2.该方法的实现
在调用该方法创建数据block时,并没有我们关心的存储路径的选择策略。
3.我们再来查找createRbwFile调用出处
调用了createRbwFile 方法,该方法同样创建rbw文件。
这里发现了我们关系的volumes,它是配置的存储路径。
4.查看volumes 的初始
volumnes是在构造函数中初始化的,使用了volArray
正式配置文件中的存储路径。
到此,我们找到了需要的存储路径,下面再找到如何选择的路径的就容易多了。
5.路径选择从getNextVolume开始
6.继续chooseVolume 源自于 blockChooser 类型是 VolumeChoosingPolicy ,该方法实现在下面的类中:
7.策略实现就是这样的:
关于配置中各个存储路径如何选择及选择策略都在这里了,sigh 累死了~~
花费了接近3天的时间,纯代码看着实累,可以步进就好了。
相关的配置说明。
dfs.datanode.fsdataset.volume.choosing.policy
dfs.datanode.available-space-volume-choosing-policy.balanced-space-threshold
10737418240
Only used when the dfs.datanode.fsdataset.volume.choosing.policy is set to org.apache.hadoop.hdfs.server.datanode.fsdataset.AvailableSpaceVolumeChoosingPolicy. This setting controls how much DN volumes are allowed to differ in terms of bytes of free disk space before they are considered imbalanced. If the free space of all the volumes are within this range of each other, the volumes will be considered balanced and block assignments will be done on a pure round robin basis.
dfs.datanode.available-space-volume-choosing-policy.balanced-space-preference-fraction
0.75f
Only used when the dfs.datanode.fsdataset.volume.choosing.policy is set to org.apache.hadoop.hdfs.server.datanode.fsdataset.AvailableSpaceVolumeChoosingPolicy. This setting controls what percentage of new block allocations will be sent to volumes with more available disk space than others. This setting should be in the range 0.0 - 1.0, though in practice 0.5 - 1.0, since there should be no reason to prefer that volumes with less available disk space receive more block allocations.
另附上其他的一些类分析:
DataNode的相关重要类
FSDataset:所有和数据块相关的操作,都在FSDataset相关的类。详细分析参考 http://caibinbupt.iteye.com/blog/284365
DataXceiverServer:处理数据块的流读写的的服务器,处理逻辑由DataXceiver完成。详细分析参考 http://caibinbupt.iteye.com/blog/284979
DataXceiver:处理数据块的流读写的线程。详细分析参考 http://caibinbupt.iteye.com/blog/284979
还有处理非读写的非主流的流程。详细分析参考 http://caibinbupt.iteye.com/blog/286533
BlockReceiver:完成数据块的流写操作。详细分析参考 http://caibinbupt.iteye.com/blog/286259
BlockSender:完成数据块的流读操作。
DataBlockScanner:用于定时对数据块文件进行校验。详细分析参考http://caibinbupt.iteye.com/blog/286650
