有些时候我们不添加 DataNode 节点, 反而是通过修改 hdfs-site.xml
中的 dfs.datanode.data.dir
添加挂载磁盘来增加.
这就会带来一个问题, 不同的磁盘可能容量大小不同, HDFS 默认的策略是轮询方式.
随着数据量增多, 就会导致磁盘空间不均衡.
所需需要修改写入策略
<property>
<name>dfs.datanode.fsdataset.volume.choosing.policy</name>
<value>org.apache.hadoop.hdfs.server.datanode.fsdataset.AvailableSpaceVolumeChoosingPolicy</value>
<description>在datanode 选择写入多个data dir 磁盘的时候, 根据可用空间大小判断来写入
官方参考: <https://hadoop.apache.org/docs/r2.8.5/hadoop-project-dist/hadoop-hdfs/hdfs-default.xml>
</description>
</property>
此项配置是根据磁盘的可用空间来优先写入的策略。一般需要配合一下两个参数来使用:
dfs.datanode.available-space-volume-choosing-policy.balanced-space-threshold
默认值是 10737418240
,即10G,一般使用默认值就行,
以下是该选项的官方解释: 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
,一般使用默认值就行,以下是该选项的官方解释:
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
意思是有多少比例的数据副本应该存储到剩余空间足够多的磁盘上。该配置项取值范围是0.0-1.0,一般取0.5-1.0,如果配置太小,会导致剩余空间足够的磁盘实际上没分配足够的数据副本,而剩余空间不足的磁盘取需要存储更多的数据副本,导致磁盘数据存储不均衡。