【转】通过HBaseAdmin的move方法来迁移Region

出处:http://www.oratea.net

 

通过HBaseAdmin的move方法可以把Region从一台RegionServer迁移到另外的RegionSever上。这在处理数据热点和grace stop的时候比较有用。

举例如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.UnknownRegionException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.util.Bytes;
 
public class test01 {
 
     public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, UnknownRegionException {
 
         Configuration conf = null ;
         conf = HBaseConfiguration.create();
         conf.set( "hbase.zookeeper.quorum" , "192.168.0.159" );
         conf.set( "hbase.zookeeper.property.clientPort" , "2181" );
 
         HBaseAdmin admin = new HBaseAdmin(conf);
 
         admin.move(Bytes.toBytes( "b01e6ed888395768c58ef350ab0bc785" ), Bytes.toBytes( "hadoop02,60020,1342601367463" ));
 
     }
}

其中需要注意的move方法的两个输入参数:
/**
* Move the region r to dest .
* @param encodedRegionName The encoded region name; i.e. the hash that makes
* up the region name suffix: e.g. if regionname is
* TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396. ,
* then the encoded region name is: 527db22f95c8a9e0116f0cc13c680396 .
* @param destServerName The servername of the destination regionserver. If
* passed the empty byte array we’ll assign to a random server. A server name
* is made of host, port and startcode. Here is an example:
* host187.example.com,60020,1289493121758
* @throws UnknownRegionException Thrown if we can’t find a region named
* encodedRegionName
* @throws ZooKeeperConnectionException
* @throws MasterNotRunningException
*/

注意:如果move的目标服务器参数为空,那么HBase会随机选择一台机器作为目标的机器

你可能感兴趣的:(【转】通过HBaseAdmin的move方法来迁移Region)