Fix for HBASE-3767

Re-adding getCurrentNrHRS but in HConnection instead, where it belongs.
Modified the tests that rely on it.


git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1094775 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jean-Daniel Cryans 2011-04-18 21:41:31 +00:00
parent 9dbed1e938
commit b16d6238d4
4 changed files with 22 additions and 2 deletions

View File

@ -338,4 +338,11 @@ public interface HConnection extends Abortable {
*/
public void prewarmRegionCache(final byte[] tableName,
final Map<HRegionInfo, HServerAddress> regions);
/**
* Scan zookeeper to get the number of region servers
* @return the number of region servers that are currently running
* @throws IOException if a remote or network exception occurs
*/
public int getCurrentNrHRS() throws IOException;
}

View File

@ -58,6 +58,7 @@ import org.apache.hadoop.hbase.util.Writables;
import org.apache.hadoop.hbase.zookeeper.ClusterId;
import org.apache.hadoop.hbase.zookeeper.RootRegionTracker;
import org.apache.hadoop.hbase.zookeeper.ZKTable;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
import org.apache.hadoop.ipc.RemoteException;
import org.apache.zookeeper.KeeperException;
@ -1446,5 +1447,16 @@ public class HConnectionManager {
else LOG.fatal(msg);
this.closed = true;
}
public int getCurrentNrHRS() throws IOException {
try {
// We go to zk rather than to master to get count of regions to avoid
// HTable having a Master dependency. See HBase-2828
return ZKUtil.getNumberOfChildren(this.zooKeeper,
this.zooKeeper.rsZNode);
} catch (KeeperException ke) {
throw new IOException("Unexpected ZooKeeper exception", ke);
}
}
}
}

View File

@ -351,7 +351,8 @@ public class RegionSplitter {
HTable table = new HTable(conf, tableName);
// max outstanding splits. default == 50% of servers
final int MAX_OUTSTANDING = Math.max(table.getCurrentNrHRS() / 2, minOS);
final int MAX_OUTSTANDING =
Math.max(table.getConnection().getCurrentNrHRS() / 2, minOS);
Path hbDir = new Path(conf.get(HConstants.HBASE_DIR));
Path tableDir = HTableDescriptor.getTableDir(hbDir, table.getTableName());

View File

@ -311,7 +311,7 @@ public class TestAdmin {
}
protected void verifyRoundRobinDistribution(HTable ht, int expectedRegions) throws IOException {
int numRS = ht.getCurrentNrHRS();
int numRS = ht.getConnection().getCurrentNrHRS();
Map<HRegionInfo,HServerAddress> regions = ht.getRegionsInfo();
Map<HServerAddress, List<HRegionInfo>> server2Regions = new HashMap<HServerAddress, List<HRegionInfo>>();
for (Map.Entry<HRegionInfo,HServerAddress> entry : regions.entrySet()) {