將hbase中的RegionServer移除(2)

(問題)
如何將hbase中的RegionServer移除?

(方法)
在上一篇文章中,我們介紹了如何使用graceful_stop.sh的腳本,
關閉RegionServer並將上面的Region一一搬移,
相同的程序,該如何用java的程式來執行呢?

首先,我們要先取得目標RegionServer的hostname,
在實作中,我們沒有偏好的取最後一個讀到的hostname作為關閉的RegionServer,
當然,也可以利用Region個數等參數選出較佳的候選RegionServer,
詳細關於如何取得RegionServer資訊的方法請參考:
http://note-on-clouds.blogspot.tw/2015/01/hbase-0-94-x-admin-2.html

HBaseAdmin admin = new HBaseAdmin(conf);
ClusterStatus status = admin.getClusterStatus();
String stopRegionServer = "";
for (ServerName serverInfo : status.getServerInfo()){
        stopRegionServer = serverInfo.getHostname(); //take the last one
}

接著,產生要被執行的指令:
        String command = "/opt/hbase/bin/graceful_stop.sh " + stopRegionServer;

利用java執行Linux指令的功能,直接呼叫執行graceful_stop.sh,
Process p;
try {
        p = Runtime.getRuntime().exec(command);
        p.waitFor();
} catch (Exception e) {
e.printStackTrace();
}

因為graceful_stop.sh的腳本把Load Balancer關閉了,
在程式中,我們再把Load Balancer打開回復原狀,
admin.setBalancerRunning(true,true);

在setBalancerRunning中,需要兩個boolean參數,
第一個true是指是否開啟Load Balancer,
第二個true則是說,在下一次balance執行時間時才打開,
在hbase中,此balance的間隔可以手動設置(hbase.balancer.period),
而預設數值為5分鐘(300000 ms)

2.5.3.1. Balancer
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).

參考資料:

留言

熱門文章

LTE筆記: RSRP, RSSI and RSRQ

[WiFi] WiFi 網路的識別: BSS, ESS, SSID, ESSID, BSSID

LTE筆記: 波束成型 (beamforming) 和天線陣列