diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java index 131ed349957..8af97a5be6c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java @@ -63,25 +63,6 @@ public abstract class BaseLoadBalancer implements LoadBalancer { private static final int MIN_SERVER_BALANCE = 2; private volatile boolean stopped = false; - protected static final Set TABLES_ON_MASTER = new HashSet(); - - /** - * Regions of these tables will be put on the master regionserver by default. - */ - static { - TABLES_ON_MASTER.add(AccessControlLists.ACL_TABLE_NAME.getNameAsString()); - TABLES_ON_MASTER.add(TableName.NAMESPACE_TABLE_NAME.getNameAsString()); - TABLES_ON_MASTER.add(TableName.META_TABLE_NAME.getNameAsString()); - } - - /** - * Check if a region belongs to some small system table. - * If so, it may be expected to be put on the master regionserver. - */ - protected static boolean shouldBeOnMaster(HRegionInfo region) { - return TABLES_ON_MASTER.contains(region.getTable().getNameAsString()); - } - /** * An efficient array based implementation similar to ClusterState for keeping * the status of the cluster in terms of region assignment and distribution. @@ -89,6 +70,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer { */ protected static class Cluster { ServerName masterServerName; + Set tablesOnMaster; ServerName[] servers; ArrayList tables; HRegionInfo[] regions; @@ -123,8 +105,10 @@ public abstract class BaseLoadBalancer implements LoadBalancer { Map> clusterState, Map> loads, RegionLocationFinder regionFinder, - Collection backupMasters) { + Collection backupMasters, + Set tablesOnMaster) { + this.tablesOnMaster = tablesOnMaster; this.masterServerName = masterServerName; serversToIndex = new HashMap(); tablesToIndex = new HashMap(); @@ -133,7 +117,6 @@ public abstract class BaseLoadBalancer implements LoadBalancer { //TODO: We should get the list of tables from master tables = new ArrayList(); - numRegions = 0; int serverIndex = 0; @@ -380,6 +363,11 @@ public abstract class BaseLoadBalancer implements LoadBalancer { return activeMasterIndex == server; } + boolean shouldBeOnMaster(HRegionInfo region) { + return tablesOnMaster != null && tablesOnMaster.contains( + region.getTable().getNameAsString()); + } + private Comparator numRegionsComparator = new Comparator() { @Override public int compare(Integer integer, Integer integer2) { @@ -448,6 +436,12 @@ public abstract class BaseLoadBalancer implements LoadBalancer { "hbase.balancer.activeMasterWeight"; private static final int DEFAULT_ACTIVE_MASTER_WEIGHT = 200; + // Regions of these tables are put on the master by default. + private static final String[] DEFAULT_TABLES_ON_MASTER = + new String[] {AccessControlLists.ACL_TABLE_NAME.getNameAsString(), + TableName.NAMESPACE_TABLE_NAME.getNameAsString(), + TableName.META_TABLE_NAME.getNameAsString()}; + protected int activeMasterWeight; protected int backupMasterWeight; @@ -456,6 +450,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer { protected final Set excludedServers = Collections.synchronizedSet(new HashSet()); + protected final Set tablesOnMaster = new HashSet(); protected final MetricsBalancer metricsBalancer = new MetricsBalancer(); protected ClusterStatus clusterStatus = null; protected ServerName masterServerName; @@ -478,6 +473,13 @@ public abstract class BaseLoadBalancer implements LoadBalancer { + BACKUP_MASTER_WEIGHT_KEY + " is " + backupMasterWeight + "(<1)"); } + String[] tables = conf.getStrings( + "hbase.balancer.tablesOnMaster", DEFAULT_TABLES_ON_MASTER); + if (tables != null) { + for (String table: tables) { + tablesOnMaster.add(table); + } + } } protected void setSlop(Configuration conf) { @@ -500,6 +502,15 @@ public abstract class BaseLoadBalancer implements LoadBalancer { } } } + + /** + * Check if a region belongs to some small system table. + * If so, it may be expected to be put on the master regionserver. + */ + protected boolean shouldBeOnMaster(HRegionInfo region) { + return tablesOnMaster.contains(region.getTable().getNameAsString()); + } + /** * Balance the regions that should be on master regionserver. */ diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java index b5b3d04561f..e58e4863cc8 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/StochasticLoadBalancer.java @@ -202,8 +202,8 @@ public class StochasticLoadBalancer extends BaseLoadBalancer { long startTime = EnvironmentEdgeManager.currentTimeMillis(); // Keep track of servers to iterate through them. - Cluster cluster = new Cluster(masterServerName, - clusterState, loads, regionFinder, getBackupMasters()); + Cluster cluster = new Cluster(masterServerName, clusterState, + loads, regionFinder, getBackupMasters(), tablesOnMaster); double currentCost = computeCost(cluster, Double.MAX_VALUE); double initCost = currentCost; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerTestBase.java index 3069f2dca34..a7d678dbe71 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerTestBase.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerTestBase.java @@ -165,7 +165,7 @@ public class BalancerTestBase { protected BaseLoadBalancer.Cluster mockCluster(int[] mockCluster) { return new BaseLoadBalancer.Cluster(null, - mockClusterServers(mockCluster, -1), null, null, null); + mockClusterServers(mockCluster, -1), null, null, null, null); } protected Map> mockClusterServers(int[] mockCluster, int numTables) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java index 0519f091aff..7bd0b71d697 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBaseLoadBalancer.java @@ -289,7 +289,7 @@ public class TestBaseLoadBalancer extends BalancerTestBase { assignRegions(regions, oldServers, clusterState); // should not throw exception: - BaseLoadBalancer.Cluster cluster = new Cluster(null, clusterState, null, null, null); + BaseLoadBalancer.Cluster cluster = new Cluster(null, clusterState, null, null, null, null); assertEquals(101 + 9, cluster.numRegions); assertEquals(10, cluster.numServers); // only 10 servers because they share the same host + port } @@ -331,7 +331,7 @@ public class TestBaseLoadBalancer extends BalancerTestBase { when(locationFinder.getTopBlockLocations(regions.get(43))).thenReturn( Lists.newArrayList(ServerName.valueOf("foo", 0, 0))); // this server does not exists in clusterStatus - BaseLoadBalancer.Cluster cluster = new Cluster(null, clusterState, null, locationFinder, null); + BaseLoadBalancer.Cluster cluster = new Cluster(null, clusterState, null, locationFinder, null, null); int r0 = ArrayUtils.indexOf(cluster.regions, regions.get(0)); // this is ok, it is just a test int r1 = ArrayUtils.indexOf(cluster.regions, regions.get(1));