HBASE-10923 Control where to put meta region
This commit is contained in:
parent
8064bd4fff
commit
500ba3de32
|
@ -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<String> TABLES_ON_MASTER = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* 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<String> tablesOnMaster;
|
||||
ServerName[] servers;
|
||||
ArrayList<String> tables;
|
||||
HRegionInfo[] regions;
|
||||
|
@ -123,8 +105,10 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
|
|||
Map<ServerName, List<HRegionInfo>> clusterState,
|
||||
Map<String, Deque<RegionLoad>> loads,
|
||||
RegionLocationFinder regionFinder,
|
||||
Collection<ServerName> backupMasters) {
|
||||
Collection<ServerName> backupMasters,
|
||||
Set<String> tablesOnMaster) {
|
||||
|
||||
this.tablesOnMaster = tablesOnMaster;
|
||||
this.masterServerName = masterServerName;
|
||||
serversToIndex = new HashMap<String, Integer>();
|
||||
tablesToIndex = new HashMap<String, Integer>();
|
||||
|
@ -133,7 +117,6 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
|
|||
//TODO: We should get the list of tables from master
|
||||
tables = new ArrayList<String>();
|
||||
|
||||
|
||||
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<Integer> numRegionsComparator = new Comparator<Integer>() {
|
||||
@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<ServerName> excludedServers =
|
||||
Collections.synchronizedSet(new HashSet<ServerName>());
|
||||
|
||||
protected final Set<String> tablesOnMaster = new HashSet<String>();
|
||||
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.
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<ServerName, List<HRegionInfo>> mockClusterServers(int[] mockCluster, int numTables) {
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue