use of org.apache.hadoop.hbase.master.MasterServices in project hbase by apache.
the class TestMetaFixer method testOverlapWithMergeOfNonContiguous.
/**
* Make it so a big overlap spans many Regions, some of which are non-contiguous. Make it so
* we can fix this condition. HBASE-24247
*/
@Test
public void testOverlapWithMergeOfNonContiguous() throws Exception {
TableName tn = TableName.valueOf(this.name.getMethodName());
TEST_UTIL.createMultiRegionTable(tn, HConstants.CATALOG_FAMILY);
List<RegionInfo> ris = MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), tn);
assertTrue(ris.size() > 5);
MasterServices services = TEST_UTIL.getHBaseCluster().getMaster();
services.getCatalogJanitor().scan();
Report report = services.getCatalogJanitor().getLastReport();
assertTrue(report.isEmpty());
// Make a simple overlap spanning second and third region.
makeOverlap(services, ris.get(1), ris.get(5));
// Now Delete a region under the overlap to manufacture non-contiguous sub regions.
RegionInfo deletedRegion = ris.get(3);
long pid = services.getAssignmentManager().unassign(deletedRegion);
while (!services.getMasterProcedureExecutor().isFinished(pid)) {
Threads.sleep(100);
}
GCRegionProcedure procedure = new GCRegionProcedure(services.getMasterProcedureExecutor().getEnvironment(), ris.get(3));
pid = services.getMasterProcedureExecutor().submitProcedure(procedure);
while (!services.getMasterProcedureExecutor().isFinished(pid)) {
Threads.sleep(100);
}
services.getCatalogJanitor().scan();
report = services.getCatalogJanitor().getLastReport();
assertEquals(1, MetaFixer.calculateMerges(10, report.getOverlaps()).size());
MetaFixer fixer = new MetaFixer(services);
fixer.fixOverlaps(report);
HBaseTestingUtil.await(10, () -> {
try {
services.getCatalogJanitor().scan();
final Report postReport = services.getCatalogJanitor().getLastReport();
return postReport.isEmpty();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
use of org.apache.hadoop.hbase.master.MasterServices in project hbase by apache.
the class TestMetaFixer method testPlugsHolesWithReadReplicaInternal.
private void testPlugsHolesWithReadReplicaInternal(final TableName tn, final int replicaCount) throws Exception {
TEST_UTIL.createMultiRegionTable(tn, replicaCount, new byte[][] { HConstants.CATALOG_FAMILY });
List<RegionInfo> ris = MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), tn);
MasterServices services = TEST_UTIL.getHBaseCluster().getMaster();
int initialSize = services.getAssignmentManager().getRegionStates().getRegionStates().size();
services.getCatalogJanitor().scan();
Report report = services.getCatalogJanitor().getLastReport();
assertTrue(report.isEmpty());
int originalCount = ris.size();
// Remove first, last and middle region. See if hole gets plugged. Table has 26 * replicaCount regions.
for (int i = 0; i < replicaCount; i++) {
deleteRegion(services, ris.get(3 * replicaCount + i));
deleteRegion(services, ris.get(i));
deleteRegion(services, ris.get(ris.size() - 1 - i));
}
assertEquals(initialSize - 3 * replicaCount, services.getAssignmentManager().getRegionStates().getRegionStates().size());
services.getCatalogJanitor().scan();
report = services.getCatalogJanitor().getLastReport();
assertEquals(report.toString(), 3, report.getHoles().size());
MetaFixer fixer = new MetaFixer(services);
fixer.fixHoles(report);
services.getCatalogJanitor().scan();
report = services.getCatalogJanitor().getLastReport();
assertTrue(report.toString(), report.isEmpty());
assertEquals(initialSize, services.getAssignmentManager().getRegionStates().getRegionStates().size());
// wait for RITs to settle -- those are the fixed regions being assigned -- or until the
// watchdog TestRule terminates the test.
HBaseTestingUtil.await(50, () -> services.getMasterProcedureExecutor().getActiveProcIds().size() == 0);
ris = MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), tn);
assertEquals(originalCount, ris.size());
}
use of org.apache.hadoop.hbase.master.MasterServices in project hbase by apache.
the class RSGroupableBalancerTestBase method getMockedMaster.
protected static MasterServices getMockedMaster() throws IOException {
TableDescriptors tds = Mockito.mock(TableDescriptors.class);
Mockito.when(tds.get(tables[0])).thenReturn(tableDescs.get(tables[0]));
Mockito.when(tds.get(tables[1])).thenReturn(tableDescs.get(tables[1]));
Mockito.when(tds.get(tables[2])).thenReturn(tableDescs.get(tables[2]));
Mockito.when(tds.get(tables[3])).thenReturn(tableDescs.get(tables[3]));
MasterServices services = Mockito.mock(HMaster.class);
Mockito.when(services.getTableDescriptors()).thenReturn(tds);
AssignmentManager am = Mockito.mock(AssignmentManager.class);
Mockito.when(services.getAssignmentManager()).thenReturn(am);
Mockito.when(services.getConfiguration()).thenReturn(conf);
RSGroupInfoManager manager = getMockedGroupInfoManager();
Mockito.when(services.getRSGroupInfoManager()).thenReturn(manager);
return services;
}
use of org.apache.hadoop.hbase.master.MasterServices in project hbase by apache.
the class TestBalancerRejection method testBalancerRejections.
@Test
public void testBalancerRejections() throws Exception {
try {
// enabled balancer rejection recording
conf.setBoolean(BaseLoadBalancer.BALANCER_REJECTION_BUFFER_ENABLED, true);
conf.set(StochasticLoadBalancer.COST_FUNCTIONS_COST_FUNCTIONS_KEY, MockCostFunction.class.getName());
MasterServices services = mock(MasterServices.class);
when(services.getConfiguration()).thenReturn(conf);
MasterClusterInfoProvider provider = new MasterClusterInfoProvider(services);
loadBalancer.setClusterInfoProvider(provider);
loadBalancer.onConfigurationChange(conf);
// Simulate 2 servers with 5 regions.
Map<ServerName, List<RegionInfo>> servers = mockClusterServers(new int[] { 5, 5 });
Map<TableName, Map<ServerName, List<RegionInfo>>> LoadOfAllTable = (Map) mockClusterServersWithTables(servers);
// Reject case 1: Total cost < 0
MockCostFunction.mockCost = -Double.MAX_VALUE;
// Since the Balancer was rejected, there should not be any plans
Assert.assertNull(loadBalancer.balanceCluster(LoadOfAllTable));
// Reject case 2: Cost < minCostNeedBalance
MockCostFunction.mockCost = 1;
conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", Float.MAX_VALUE);
loadBalancer.onConfigurationChange(conf);
Assert.assertNull(loadBalancer.balanceCluster(LoadOfAllTable));
// NamedQueue is an async Producer-consumer Pattern, waiting here until it completed
int maxWaitingCount = 10;
while (maxWaitingCount-- > 0 && getBalancerRejectionLogEntries(provider).size() != 2) {
Thread.sleep(1000);
}
// There are two cases, should be 2 logEntries
List<LogEntry> logEntries = getBalancerRejectionLogEntries(provider);
Assert.assertEquals(2, logEntries.size());
Assert.assertTrue(logEntries.get(0).toJsonPrettyPrint().contains("minCostNeedBalance"));
Assert.assertTrue(logEntries.get(1).toJsonPrettyPrint().contains("cost1*multiplier1"));
} finally {
conf.unset(StochasticLoadBalancer.COST_FUNCTIONS_COST_FUNCTIONS_KEY);
conf.unset(BaseLoadBalancer.BALANCER_REJECTION_BUFFER_ENABLED);
loadBalancer.onConfigurationChange(conf);
}
}
Aggregations