除了load balance的对象是region以外,HBase提供了几个足够好用的接口,有了它们去实现balance一个table的regions就不是问题了!
The master has a built-in feature, called the balancer. By default the balancer runs every five minutes, which is configured by the hbase.balancer.period
property. Once the balancer is started it will attempt to equal out the number of assigned regions per region server so that they are within one region of the average number per server. The call first determines a new assignment plan, which describes which regions should be moved where. Then it starts the process of moving the regions by calling the unassign()
method of the administrative API iteratively.
The balancer has an upper limit on how long it is allowed to run, which is configured using the hbase.balancer.max.balancing
property and defaults to half of the balancer period value, in other words two and a half minutes.
You can control the balancer by means of the balancer switch: either use the shell's balance_switch command to toggle the balancer status between enabled and disabled, or use the balanceSwitch()
API method to do the same. When you disable the balancer, it is not run anymore as expected.
The balancer can be explicitly started using the shell's balancer command, or using the API method balancer()
. The above time controlled invocation calls this method implicitly. It will determine if there is any work to be done and return true
if that is the case. The return value of false
means that it was not able to run the balancer, because either it was switched off, there was no work to be done (all is balanced), or something else was prohibiting the process. One example for this is the region in transition list (see the section called “Main Page”): if there is a region currently in transition, the balancer will be skipped.
Instead of relying on the balancer to do its work properly, you can also use the move command and API method to assign regions to other servers. This is useful when you want to control where the regions of a particular table is assigned to. See the section called “Region Hotspotting” for an example.