Java Code Examples for org.apache.hadoop.hbase.master.balancer.StochasticLoadBalancer#setConf()

The following examples show how to use org.apache.hadoop.hbase.master.balancer.StochasticLoadBalancer#setConf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommandAdapter.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
public static List<RegionPlan> makePlan(HBaseAdmin admin, List<RegionPlan> newRegionPlan) throws IOException {
    // snapshot current region assignment
    Map<HRegionInfo, ServerName> regionAssignmentMap = createRegionAssignmentMap(admin);

    // update with new plan
    for (RegionPlan regionPlan : newRegionPlan) {
        regionAssignmentMap.put(regionPlan.getRegionInfo(), regionPlan.getDestination());
    }

    Map<ServerName, List<HRegionInfo>> clusterState = initializeRegionMap(admin);
    for (Map.Entry<HRegionInfo, ServerName> entry : regionAssignmentMap.entrySet())
        clusterState.get(entry.getValue()).add(entry.getKey());

    StochasticLoadBalancer balancer = new StochasticLoadBalancer();
    Configuration conf = admin.getConfiguration();
    conf.setFloat("hbase.regions.slop", 0.2f);
    balancer.setConf(conf);
    return balancer.balanceCluster(clusterState);
}
 
Example 2
Source File: CommandAdapter.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
public static List<RegionPlan> makePlan(HBaseAdmin admin, List<RegionPlan> newRegionPlan) throws IOException {
    // snapshot current region assignment
    Map<HRegionInfo, ServerName> regionAssignmentMap = createRegionAssignmentMap(admin);

    // update with new plan
    for (RegionPlan regionPlan : newRegionPlan) {
        regionAssignmentMap.put(regionPlan.getRegionInfo(), regionPlan.getDestination());
    }

    Map<ServerName, List<HRegionInfo>> clusterState = initializeRegionMap(admin);
    for (Map.Entry<HRegionInfo, ServerName> entry : regionAssignmentMap.entrySet())
        clusterState.get(entry.getValue()).add(entry.getKey());

    StochasticLoadBalancer balancer = new StochasticLoadBalancer();
    Configuration conf = admin.getConfiguration();
    conf.setFloat("hbase.regions.slop", 0.2f);
    balancer.setConf(conf);
    return balancer.balanceCluster(clusterState);
}
 
Example 3
Source File: CommandAdapter.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
public static List<RegionPlan> makePlan(HBaseAdmin admin, List<RegionPlan> newRegionPlan) throws IOException {
    // snapshot current region assignment
    Map<HRegionInfo, ServerName> regionAssignmentMap = createRegionAssignmentMap(admin);

    // update with new plan
    for (RegionPlan regionPlan : newRegionPlan) {
        regionAssignmentMap.put(regionPlan.getRegionInfo(), regionPlan.getDestination());
    }

    Map<ServerName, List<HRegionInfo>> clusterState = initializeRegionMap(admin);
    for (Map.Entry<HRegionInfo, ServerName> entry : regionAssignmentMap.entrySet())
        clusterState.get(entry.getValue()).add(entry.getKey());

    StochasticLoadBalancer balancer = new StochasticLoadBalancer();
    Configuration conf = admin.getConfiguration();
    conf.setFloat("hbase.regions.slop", 0.2f);
    balancer.setConf(conf);
    return balancer.balanceCluster(clusterState);
}
 
Example 4
Source File: CommandAdapter.java    From hbase-tools with Apache License 2.0 6 votes vote down vote up
public static List<RegionPlan> makePlan(HBaseAdmin admin, List<RegionPlan> newRegionPlan) throws IOException {
    // snapshot current region assignment
    Map<HRegionInfo, ServerName> regionAssignmentMap = createRegionAssignmentMap(admin);

    // update with new plan
    for (RegionPlan regionPlan : newRegionPlan) {
        regionAssignmentMap.put(regionPlan.getRegionInfo(), regionPlan.getDestination());
    }

    Map<ServerName, List<HRegionInfo>> clusterState = initializeRegionMap(admin);
    for (Map.Entry<HRegionInfo, ServerName> entry : regionAssignmentMap.entrySet())
        clusterState.get(entry.getValue()).add(entry.getKey());

    StochasticLoadBalancer balancer = new StochasticLoadBalancer();
    Configuration conf = admin.getConfiguration();
    conf.setFloat("hbase.regions.slop", 0.2f);
    balancer.setConf(conf);
    return balancer.balanceCluster(clusterState);
}
 
Example 5
Source File: TestStochasticBalancerJmxMetrics.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * In Ensemble mode, there should be only one ensemble table
 */
@Test
public void testJmxMetrics_EnsembleMode() throws Exception {
  loadBalancer = new StochasticLoadBalancer();

  conf.setBoolean(HConstants.HBASE_MASTER_LOADBALANCE_BYTABLE, false);
  loadBalancer.setConf(conf);

  TableName tableName = HConstants.ENSEMBLE_TABLE_NAME;
  Map<ServerName, List<RegionInfo>> clusterState = mockClusterServers(mockCluster_ensemble);
  loadBalancer.balanceTable(tableName, clusterState);

  String[] tableNames = new String[] { tableName.getNameAsString() };
  String[] functionNames = loadBalancer.getCostFunctionNames();
  Set<String> jmxMetrics = readJmxMetricsWithRetry();
  Set<String> expectedMetrics = getExpectedJmxMetrics(tableNames, functionNames);

  // printMetrics(jmxMetrics, "existing metrics in ensemble mode");
  // printMetrics(expectedMetrics, "expected metrics in ensemble mode");

  // assert that every expected is in the JMX
  for (String expected : expectedMetrics) {
    assertTrue("Metric " + expected + " can not be found in JMX in ensemble mode.",
      jmxMetrics.contains(expected));
  }
}
 
Example 6
Source File: CommandAdapter.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
public static List<RegionPlan> makePlan(HBaseAdmin admin,
    Map<ServerName, List<HRegionInfo>> clusterState, Configuration conf) throws IOException {
    StochasticLoadBalancer balancer = new StochasticLoadBalancer() {
        @Override
        protected boolean needsBalance(ClusterLoadState cs) {
            return true;
        }
    };
    balancer.setConf(conf);
    balancer.setClusterStatus(admin.getClusterStatus());
    List<RegionPlan> regionPlanList = balancer.balanceCluster(clusterState);
    return regionPlanList == null ? new ArrayList<RegionPlan>() : regionPlanList;
}
 
Example 7
Source File: CommandAdapter.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
public static List<RegionPlan> makePlan(HBaseAdmin admin, Map<ServerName, List<HRegionInfo>> clusterState, Configuration conf) throws IOException {
    StochasticLoadBalancer balancer = new StochasticLoadBalancer() {
        @Override
        protected boolean needsBalance(Cluster c) {
            return true;
        }
    };
    balancer.setConf(conf);
    balancer.setClusterStatus(admin.getClusterStatus());
    List<RegionPlan> regionPlanList = balancer.balanceCluster(clusterState);
    return regionPlanList == null ? new ArrayList<RegionPlan>() : regionPlanList;
}
 
Example 8
Source File: CommandAdapter.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
public static List<RegionPlan> makePlan(HBaseAdmin admin,
    Map<ServerName, List<HRegionInfo>> clusterState, Configuration conf) throws IOException {
    StochasticLoadBalancer balancer = new StochasticLoadBalancer() {
        @Override
        protected boolean needsBalance(ClusterLoadState cs) {
            return true;
        }
    };
    balancer.setConf(conf);
    balancer.setClusterStatus(admin.getClusterStatus());
    List<RegionPlan> regionPlanList = balancer.balanceCluster(clusterState);
    return regionPlanList == null ? new ArrayList<RegionPlan>() : regionPlanList;
}
 
Example 9
Source File: CommandAdapter.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
public static List<RegionPlan> makePlan(HBaseAdmin admin, Map<ServerName, List<HRegionInfo>> clusterState, Configuration conf) throws IOException {
    StochasticLoadBalancer balancer = new StochasticLoadBalancer() {
        @Override
        protected boolean needsBalance(Cluster c) {
            return true;
        }
    };
    balancer.setConf(conf);
    balancer.setClusterStatus(admin.getClusterStatus());
    List<RegionPlan> regionPlanList = balancer.balanceCluster(clusterState);
    return regionPlanList == null ? new ArrayList<RegionPlan>() : regionPlanList;
}
 
Example 10
Source File: TestStochasticBalancerJmxMetrics.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * In per-table mode, each table has a set of metrics
 */
@Test
public void testJmxMetrics_PerTableMode() throws Exception {
  loadBalancer = new StochasticLoadBalancer();

  conf.setBoolean(HConstants.HBASE_MASTER_LOADBALANCE_BYTABLE, true);
  loadBalancer.setConf(conf);

  // NOTE the size is normally set in setClusterMetrics, for test purpose, we set it manually
  // Tables: hbase:namespace, table1, table2
  // Functions: costFunctions, overall
  String[] functionNames = loadBalancer.getCostFunctionNames();
  loadBalancer.updateMetricsSize(3 * (functionNames.length + 1));

  // table 1
  TableName tableName = TableName.valueOf(TABLE_NAME_1);
  Map<ServerName, List<RegionInfo>> clusterState = mockClusterServers(mockCluster_pertable_1);
  loadBalancer.balanceTable(tableName, clusterState);

  // table 2
  tableName = TableName.valueOf(TABLE_NAME_2);
  clusterState = mockClusterServers(mockCluster_pertable_2);
  loadBalancer.balanceTable(tableName, clusterState);

  // table hbase:namespace
  tableName = TableName.valueOf(TABLE_NAME_NAMESPACE);
  clusterState = mockClusterServers(mockCluster_pertable_namespace);
  loadBalancer.balanceTable(tableName, clusterState);

  String[] tableNames = new String[] { TABLE_NAME_1, TABLE_NAME_2, TABLE_NAME_NAMESPACE };
  Set<String> jmxMetrics = readJmxMetricsWithRetry();
  Set<String> expectedMetrics = getExpectedJmxMetrics(tableNames, functionNames);

  // printMetrics(jmxMetrics, "existing metrics in per-table mode");
  // printMetrics(expectedMetrics, "expected metrics in per-table mode");

  // assert that every expected is in the JMX
  for (String expected : expectedMetrics) {
    assertTrue("Metric " + expected + " can not be found in JMX in per-table mode.",
      jmxMetrics.contains(expected));
  }
}