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++;
}
}
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));
}
}
}
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;
}
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;
}
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);
}
Aggregations