hadoop2.0的datanode多存储硬盘设置数据副本存放策略

来源:互联网 发布:星网锐捷和锐捷网络 编辑:程序博客网 时间:2024/05/29 10:11
集群使用4块硬盘,目前集群中部分节点盘disk1使用率已经超90%,后期可能会出现问题。
在hadoop2.0中,datanode数据副本存放磁盘选择策略有两种方式:
第一种是沿用hadoop1.0的磁盘目录轮询方式,实现类:RoundRobinVolumeChoosingPolicy.java
第二种是选择可用空间足够多的磁盘方式存储,实现类:AvailableSpaceVolumeChoosingPolicy.java
选择策略对应的配置项是:
<property><name>dfs.datanode.fsdataset.volume.choosing.policy</name><value>org.apache.hadoop.hdfs.server.datanode.fsdataset.AvailableSpaceVolumeChoosingPolicy</value></property>
该参数默认值是RoundRobinVolumeChoosingPolicy,这种默认策略DataNode会以轮询的方式选择磁盘存储数据,每个磁盘的数据量存储很接近,如果某些盘比较小的情况,就会出现这些小盘磁盘使用率比其他盘高,配置后重启datanode。

该参数配置成AvailableSpaceVolumeChoosingPolicy,DataNode在选择磁盘存储数据时,会选择可用磁盘空间最大的磁盘来存储数据,这样保证了小盘不会存储过多的数据量。


在采用第二种方式时还有另外两个参数会用到:
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.
意思是首先计算出两个值,一个是所有磁盘中最大可用空间,另外一个值是所有磁盘中最小可用空间,如果这两个值相差小于该配置项指定的阀值时,则就用轮询方式的磁盘选择策略选择磁盘存储数据副本。源代码如下:

public boolean areAllVolumesWithinFreeSpaceThreshold() {      long leastAvailable = Long.MAX_VALUE;      long mostAvailable = 0;      for (AvailableSpaceVolumePair volume : volumes) {        leastAvailable = Math.min(leastAvailable, volume.getAvailable());        mostAvailable = Math.max(mostAvailable, volume.getAvailable());      }      return (mostAvailable - leastAvailable) < balancedSpaceThreshold;    }
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,如果配置太小,会导致剩余空间足够的磁盘实际上没分配足够的数据副本,而剩余空间不足的磁盘取需要存储更多的数据副本,导致磁盘数据存储不均衡。

0 0
原创粉丝点击