Get Hbase region size via API

人盡茶涼 提交于 2019-12-10 11:23:27

问题


I am trying to write a balancer tool for Hbase which could balance regions across regionServers for a table by region count and/or region size (sum of storeFile sizes). I could not find any Hbase API class which returns the regions size or related info. I have already checked a few of the classes which could be used to get other table/region info, e.g. org.apache.hadoop.hbase.client.HTable and HBaseAdmin.

I am thinking, another way this could be implemented is by using one of the Hadoop classes which returns the size of the directories in the fileSystem, for e.g. org.apache.hadoop.fs.FileSystem lists the files under a particular HDFS path.

Any suggestions ?


回答1:


I use this to do managed splits of regions, but, you could leverage it to load-balance on your own. I also load-balance myself to spread the regions ( of a given table ) evenly across our nodes so that MR jobs are evenly distributed.

Perhaps the code-snippet below is useful?

final HBaseAdmin admin = new HBaseAdmin(conf);
final ClusterStatus clusterStatus = admin.getClusterStatus();

for (ServerName serverName : clusterStatus.getServers()) {
  final HServerLoad serverLoad = clusterStatus.getLoad(serverName);

  for (Map.Entry<byte[], HServerLoad.RegionLoad> entry : serverLoad.getRegionsLoad().entrySet()) {
    final String region = Bytes.toString(entry.getKey());
    final HServerLoad.RegionLoad regionLoad = entry.getValue();
    long storeFileSize = regionLoad.getStorefileSizeMB();
    // other useful thing in regionLoad if you like
  }
}



回答2:


What's wrong with the default Load Balancer?

From the Wiki:

The balancer is a periodic operation which is run on the master to redistribute regions on the cluster. It is configured via hbase.balancer.period and defaults to 300000 (5 minutes).

If you really want to do it yourself you could indeed use the Hadoop API and more specifally, the FileStatus class. This class acts as an interface to represent the client side information for a file.



来源:https://stackoverflow.com/questions/14573466/get-hbase-region-size-via-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!