Search in sources :

Example 21 with MasterServices

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);
        }
    });
}
Also used : TableName(org.apache.hadoop.hbase.TableName) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) GCRegionProcedure(org.apache.hadoop.hbase.master.assignment.GCRegionProcedure) MasterServices(org.apache.hadoop.hbase.master.MasterServices) IOException(java.io.IOException) Test(org.junit.Test)

Example 22 with MasterServices

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());
}
Also used : RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) MasterServices(org.apache.hadoop.hbase.master.MasterServices)

Example 23 with MasterServices

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;
}
Also used : TableDescriptors(org.apache.hadoop.hbase.TableDescriptors) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) RSGroupInfoManager(org.apache.hadoop.hbase.rsgroup.RSGroupInfoManager) MasterServices(org.apache.hadoop.hbase.master.MasterServices)

Example 24 with MasterServices

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);
    }
}
Also used : RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) MasterServices(org.apache.hadoop.hbase.master.MasterServices) TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) List(java.util.List) Map(java.util.Map) LogEntry(org.apache.hadoop.hbase.client.LogEntry) Test(org.junit.Test)

Aggregations

MasterServices (org.apache.hadoop.hbase.master.MasterServices)24 IOException (java.io.IOException)9 TableName (org.apache.hadoop.hbase.TableName)8 Test (org.junit.Test)8 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)7 Map (java.util.Map)5 ServerName (org.apache.hadoop.hbase.ServerName)5 List (java.util.List)4 Configuration (org.apache.hadoop.conf.Configuration)4 Path (org.apache.hadoop.fs.Path)4 HashMap (java.util.HashMap)3 TableDescriptors (org.apache.hadoop.hbase.TableDescriptors)3 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)3 ArrayList (java.util.ArrayList)2 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)2 LogEntry (org.apache.hadoop.hbase.client.LogEntry)2 AssignmentManager (org.apache.hadoop.hbase.master.AssignmentManager)2 MasterFileSystem (org.apache.hadoop.hbase.master.MasterFileSystem)2 ServerManager (org.apache.hadoop.hbase.master.ServerManager)2 AssignmentManager (org.apache.hadoop.hbase.master.assignment.AssignmentManager)2