Search in sources :

Example 6 with RegionLoad

use of org.apache.hadoop.hbase.RegionLoad in project hbase by apache.

the class TestStochasticLoadBalancer method testKeepRegionLoad.

@Test
public void testKeepRegionLoad() throws Exception {
    ServerName sn = ServerName.valueOf("test:8080", 100);
    int numClusterStatusToAdd = 20000;
    for (int i = 0; i < numClusterStatusToAdd; i++) {
        ServerLoad sl = mock(ServerLoad.class);
        RegionLoad rl = mock(RegionLoad.class);
        when(rl.getStorefileSizeMB()).thenReturn(i);
        Map<byte[], RegionLoad> regionLoadMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
        regionLoadMap.put(Bytes.toBytes(REGION_KEY), rl);
        when(sl.getRegionsLoad()).thenReturn(regionLoadMap);
        ClusterStatus clusterStatus = mock(ClusterStatus.class);
        when(clusterStatus.getServers()).thenReturn(Arrays.asList(sn));
        when(clusterStatus.getLoad(sn)).thenReturn(sl);
        loadBalancer.setClusterStatus(clusterStatus);
    }
    assertTrue(loadBalancer.loads.get(REGION_KEY) != null);
    assertTrue(loadBalancer.loads.get(REGION_KEY).size() == 15);
    Queue<BalancerRegionLoad> loads = loadBalancer.loads.get(REGION_KEY);
    int i = 0;
    while (loads.size() > 0) {
        BalancerRegionLoad rl = loads.remove();
        assertEquals(i + (numClusterStatusToAdd - 15), rl.getStorefileSizeMB());
        i++;
    }
}
Also used : ServerLoad(org.apache.hadoop.hbase.ServerLoad) RegionLoad(org.apache.hadoop.hbase.RegionLoad) ServerName(org.apache.hadoop.hbase.ServerName) TreeMap(java.util.TreeMap) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus) Test(org.junit.Test)

Example 7 with RegionLoad

use of org.apache.hadoop.hbase.RegionLoad in project hbase by apache.

the class TestRegionServerReadRequestMetrics method updateMetricsMap.

private static void updateMetricsMap() throws IOException, InterruptedException {
    for (Metric metric : Metric.values()) {
        requestsMapPrev.put(metric, requestsMap.get(metric));
    }
    ServerLoad serverLoad = null;
    RegionLoad regionLoadOuter = null;
    boolean metricsUpdated = false;
    for (int i = 0; i < MAX_TRY; i++) {
        for (ServerName serverName : serverNames) {
            serverLoad = admin.getClusterStatus().getLoad(serverName);
            Map<byte[], RegionLoad> regionsLoad = serverLoad.getRegionsLoad();
            for (HRegionInfo tableRegion : tableRegions) {
                RegionLoad regionLoad = regionsLoad.get(tableRegion.getRegionName());
                if (regionLoad != null) {
                    regionLoadOuter = regionLoad;
                    for (Metric metric : Metric.values()) {
                        if (getReadRequest(serverLoad, regionLoad, metric) > requestsMapPrev.get(metric)) {
                            for (Metric metricInner : Metric.values()) {
                                requestsMap.put(metricInner, getReadRequest(serverLoad, regionLoad, metricInner));
                            }
                            metricsUpdated = true;
                            break;
                        }
                    }
                }
            }
        }
        if (metricsUpdated) {
            break;
        }
        Thread.sleep(SLEEP_MS);
    }
    if (!metricsUpdated) {
        for (Metric metric : Metric.values()) {
            requestsMap.put(metric, getReadRequest(serverLoad, regionLoadOuter, metric));
        }
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ServerLoad(org.apache.hadoop.hbase.ServerLoad) RegionLoad(org.apache.hadoop.hbase.RegionLoad) ServerName(org.apache.hadoop.hbase.ServerName)

Example 8 with RegionLoad

use of org.apache.hadoop.hbase.RegionLoad in project hbase by apache.

the class TestRegionSizeCalculator method mockAdmin.

/**
   * Creates mock returning RegionLoad info about given servers.
  */
private Admin mockAdmin(RegionLoad... regionLoadArray) throws Exception {
    Admin mockAdmin = Mockito.mock(Admin.class);
    Map<byte[], RegionLoad> regionLoads = new TreeMap<>(Bytes.BYTES_COMPARATOR);
    for (RegionLoad regionLoad : regionLoadArray) {
        regionLoads.put(regionLoad.getName(), regionLoad);
    }
    when(mockAdmin.getConfiguration()).thenReturn(configuration);
    when(mockAdmin.getRegionLoad(sn, TableName.valueOf("sizeTestTable"))).thenReturn(regionLoads);
    return mockAdmin;
}
Also used : RegionLoad(org.apache.hadoop.hbase.RegionLoad) Admin(org.apache.hadoop.hbase.client.Admin) TreeMap(java.util.TreeMap)

Example 9 with RegionLoad

use of org.apache.hadoop.hbase.RegionLoad in project hbase by apache.

the class TestRegionSizeCalculator method mockRegion.

/**
   * Creates mock of region with given name and size.
   *
   * @param  fileSizeMb number of megabytes occupied by region in file store in megabytes
   * */
private RegionLoad mockRegion(String regionName, int fileSizeMb) {
    RegionLoad region = Mockito.mock(RegionLoad.class);
    when(region.getName()).thenReturn(regionName.getBytes());
    when(region.getNameAsString()).thenReturn(regionName);
    when(region.getStorefileSizeMB()).thenReturn(fileSizeMb);
    return region;
}
Also used : RegionLoad(org.apache.hadoop.hbase.RegionLoad)

Example 10 with RegionLoad

use of org.apache.hadoop.hbase.RegionLoad in project hbase by apache.

the class TestSimpleRegionNormalizer method setupMocksForNormalizer.

protected void setupMocksForNormalizer(Map<byte[], Integer> regionSizes, List<HRegionInfo> hris) {
    masterServices = Mockito.mock(MasterServices.class, RETURNS_DEEP_STUBS);
    masterRpcServices = Mockito.mock(MasterRpcServices.class, RETURNS_DEEP_STUBS);
    // for simplicity all regions are assumed to be on one server; doesn't matter to us
    ServerName sn = ServerName.valueOf("localhost", 0, 1L);
    when(masterServices.getAssignmentManager().getRegionStates().getRegionsOfTable(any(TableName.class))).thenReturn(hris);
    when(masterServices.getAssignmentManager().getRegionStates().getRegionServerOfRegion(any(HRegionInfo.class))).thenReturn(sn);
    for (Map.Entry<byte[], Integer> region : regionSizes.entrySet()) {
        RegionLoad regionLoad = Mockito.mock(RegionLoad.class);
        when(regionLoad.getName()).thenReturn(region.getKey());
        when(regionLoad.getStorefileSizeMB()).thenReturn(region.getValue());
        when(masterServices.getServerManager().getLoad(sn).getRegionsLoad().get(region.getKey())).thenReturn(regionLoad);
    }
    try {
        when(masterRpcServices.isSplitOrMergeEnabled(any(RpcController.class), any(IsSplitOrMergeEnabledRequest.class))).thenReturn(IsSplitOrMergeEnabledResponse.newBuilder().setEnabled(true).build());
    } catch (ServiceException se) {
        LOG.debug("error setting isSplitOrMergeEnabled switch", se);
    }
    normalizer.setMasterServices(masterServices);
    normalizer.setMasterRpcServices(masterRpcServices);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) RpcController(org.apache.hadoop.hbase.shaded.com.google.protobuf.RpcController) TableName(org.apache.hadoop.hbase.TableName) MasterRpcServices(org.apache.hadoop.hbase.master.MasterRpcServices) RegionLoad(org.apache.hadoop.hbase.RegionLoad) IsSplitOrMergeEnabledRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSplitOrMergeEnabledRequest) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) ServerName(org.apache.hadoop.hbase.ServerName) MasterServices(org.apache.hadoop.hbase.master.MasterServices) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RegionLoad (org.apache.hadoop.hbase.RegionLoad)15 ServerName (org.apache.hadoop.hbase.ServerName)10 ServerLoad (org.apache.hadoop.hbase.ServerLoad)5 TreeMap (java.util.TreeMap)4 ClusterStatus (org.apache.hadoop.hbase.ClusterStatus)4 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)3 TableName (org.apache.hadoop.hbase.TableName)3 Map (java.util.Map)2 TableId (co.cask.cdap.data2.util.TableId)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 ArrayDeque (java.util.ArrayDeque)1 Deque (java.util.Deque)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)1 Admin (org.apache.hadoop.hbase.client.Admin)1