1. 程式人生 > >hadoop2.0的datanode多儲存硬碟設定資料副本存放策略

hadoop2.0的datanode多儲存硬碟設定資料副本存放策略

叢集使用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,如果配置太小,會導致剩餘空間足夠的磁碟實際上沒分配足夠的資料副本,而剩餘空間不足的磁碟取需要儲存更多的資料副本,導致磁碟資料儲存不均衡。