hadoop2.0的datanode多目錄數據副本存放策略

在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>

如果不配置,默認使用第一種方式,既輪詢選擇磁盤來存儲數據副本,但是輪詢的方式雖然能夠保證所有磁盤都能夠被使用,但是經常會出現各個磁盤直接數據存儲不均衡問題,有的磁盤存儲得很滿了,而有的磁盤可能還有很多存儲空間沒有得到利用,所有在hadoop2.0集羣中,最好將磁盤選擇策略配置成第二種,根據磁盤空間剩餘量來選擇磁盤存儲數據副本,這樣一樣能保證所有磁盤都能得到利用,還能保證所有磁盤都被利用均衡。

在採用第二種方式時還有另外兩個參數會用到:

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

參考:

http://www.it165.net/admin/html/201409/3635.html

http://blog.csdn.net/chenpingbupt/article/details/7972589


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章