Search in sources :

Example 16 with FavoredNodesManager

use of org.apache.hadoop.hbase.favored.FavoredNodesManager in project hbase by apache.

the class TestFavoredStochasticBalancerPickers method getRegionsThatCanBeMoved.

/*
   * A region can only be moved to one of its favored node. Hence this method helps us to
   * get that list which makes it easy to write non-flaky tests.
   */
private List<RegionInfo> getRegionsThatCanBeMoved(TableName tableName, ServerName serverName) {
    List<RegionInfo> regions = Lists.newArrayList();
    RegionStates rst = cluster.getMaster().getAssignmentManager().getRegionStates();
    FavoredNodesManager fnm = cluster.getMaster().getFavoredNodesManager();
    for (RegionInfo regionInfo : fnm.getRegionsOfFavoredNode(serverName)) {
        if (regionInfo.getTable().equals(tableName) && !ServerName.isSameAddress(rst.getRegionServerOfRegion(regionInfo), serverName)) {
            regions.add(regionInfo);
        }
    }
    return regions;
}
Also used : RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo)

Example 17 with FavoredNodesManager

use of org.apache.hadoop.hbase.favored.FavoredNodesManager in project hbase by apache.

the class TestFavoredNodeTableImport method testTableCreation.

@Test
public void testTableCreation() throws Exception {
    conf.set(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, StochasticLoadBalancer.class.getName());
    LOG.info("Starting up cluster");
    UTIL.startMiniCluster(SLAVES);
    while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) {
        Threads.sleep(1);
    }
    Admin admin = UTIL.getAdmin();
    admin.balancerSwitch(false, true);
    String tableName = "testFNImport";
    TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(TableName.valueOf(tableName)).setColumnFamily(ColumnFamilyDescriptorBuilder.of(HConstants.CATALOG_FAMILY)).build();
    admin.createTable(tableDescriptor, Bytes.toBytes("a"), Bytes.toBytes("z"), REGION_NUM);
    UTIL.waitTableAvailable(tableDescriptor.getTableName());
    admin.balancerSwitch(true, true);
    LOG.info("Shutting down cluster");
    UTIL.shutdownMiniHBaseCluster();
    Thread.sleep(2000);
    LOG.info("Starting cluster again with FN Balancer");
    UTIL.getConfiguration().set(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, FavoredStochasticBalancer.class.getName());
    UTIL.restartHBaseCluster(SLAVES);
    HMaster master = UTIL.getMiniHBaseCluster().getMaster();
    while (!master.isInitialized()) {
        Threads.sleep(1);
    }
    UTIL.waitTableAvailable(tableDescriptor.getTableName());
    UTIL.waitUntilNoRegionsInTransition(10000);
    assertTrue(master.isBalancerOn());
    FavoredNodesManager fnm = master.getFavoredNodesManager();
    assertNotNull(fnm);
    admin = UTIL.getAdmin();
    List<RegionInfo> regionsOfTable = admin.getRegions(TableName.valueOf(tableName));
    for (RegionInfo rInfo : regionsOfTable) {
        assertNotNull(rInfo);
        assertNotNull(fnm);
        List<ServerName> fns = fnm.getFavoredNodes(rInfo);
        LOG.info("FNS {} {}", rInfo, fns);
        assertNotNull(rInfo.toString(), fns);
        Set<ServerName> favNodes = Sets.newHashSet(fns);
        assertNotNull(favNodes);
        assertEquals("Required no of favored nodes not found.", FAVORED_NODES_NUM, favNodes.size());
        for (ServerName fn : favNodes) {
            assertEquals("StartCode invalid for:" + fn, ServerName.NON_STARTCODE, fn.getStartcode());
        }
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Admin(org.apache.hadoop.hbase.client.Admin) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Test(org.junit.Test)

Example 18 with FavoredNodesManager

use of org.apache.hadoop.hbase.favored.FavoredNodesManager in project hbase by apache.

the class TestFavoredStochasticLoadBalancer method test2FavoredNodesDead.

@Test
public void test2FavoredNodesDead() throws Exception {
    TableName tableName = TableName.valueOf("testAllFavoredNodesDead");
    TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder.of(HConstants.CATALOG_FAMILY)).build();
    admin.createTable(tableDescriptor, Bytes.toBytes("aaa"), Bytes.toBytes("zzz"), REGION_NUM);
    TEST_UTIL.waitTableAvailable(tableName);
    final RegionInfo region = admin.getRegions(tableName).get(0);
    LOG.info("Region that's supposed to be in transition: " + region);
    FavoredNodesManager fnm = master.getFavoredNodesManager();
    List<ServerName> currentFN = fnm.getFavoredNodes(region);
    assertNotNull(currentFN);
    List<ServerName> serversToStop = Lists.newArrayList(currentFN);
    serversToStop.remove(currentFN.get(0));
    // Lets kill 2 FN for the region. All regions should still be assigned
    stopServersAndWaitUntilProcessed(serversToStop);
    TEST_UTIL.waitUntilNoRegionsInTransition();
    final RegionStates regionStates = master.getAssignmentManager().getRegionStates();
    TEST_UTIL.waitFor(10000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return regionStates.getRegionState(region).isOpened();
        }
    });
    assertEquals("Not all regions are online", REGION_NUM, admin.getRegions(tableName).size());
    admin.balancerSwitch(true, true);
    assertTrue("Balancer did not run", admin.balance());
    TEST_UTIL.waitUntilNoRegionsInTransition(60000);
    checkFavoredNodeAssignments(tableName, fnm, regionStates);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) ServerName(org.apache.hadoop.hbase.ServerName) FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Waiter(org.apache.hadoop.hbase.Waiter) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) IOException(java.io.IOException) Test(org.junit.Test)

Example 19 with FavoredNodesManager

use of org.apache.hadoop.hbase.favored.FavoredNodesManager in project hbase by apache.

the class TestFavoredStochasticLoadBalancer method testAllFavoredNodesDead.

@Ignore
@Test
public void testAllFavoredNodesDead() throws Exception {
    TableName tableName = TableName.valueOf("testAllFavoredNodesDead");
    TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder.of(HConstants.CATALOG_FAMILY)).build();
    admin.createTable(tableDescriptor, Bytes.toBytes("aaa"), Bytes.toBytes("zzz"), REGION_NUM);
    TEST_UTIL.waitTableAvailable(tableName);
    final RegionInfo region = admin.getRegions(tableName).get(0);
    LOG.info("Region that's supposed to be in transition: " + region);
    FavoredNodesManager fnm = master.getFavoredNodesManager();
    List<ServerName> currentFN = fnm.getFavoredNodes(region);
    assertNotNull(currentFN);
    // Lets kill all the RS that are favored nodes for this region.
    stopServersAndWaitUntilProcessed(currentFN);
    final RegionStates regionStates = master.getAssignmentManager().getRegionStates();
    TEST_UTIL.waitFor(10000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return regionStates.getRegionState(region).isFailedOpen();
        }
    });
    assertTrue("Region: " + region + " should be RIT", regionStates.getRegionState(region).isFailedOpen());
    // Regenerate FN and assign, everything else should be fine
    List<ServerName> serversForNewFN = Lists.newArrayList();
    for (ServerName sn : admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet()) {
        serversForNewFN.add(ServerName.valueOf(sn.getHostname(), sn.getPort(), NON_STARTCODE));
    }
    FavoredNodeAssignmentHelper helper = new FavoredNodeAssignmentHelper(serversForNewFN, conf);
    helper.initialize();
    for (RegionStateNode regionState : regionStates.getRegionsInTransition()) {
        RegionInfo regionInfo = regionState.getRegionInfo();
        List<ServerName> newFavoredNodes = helper.generateFavoredNodes(regionInfo);
        assertNotNull(newFavoredNodes);
        assertEquals(FavoredNodeAssignmentHelper.FAVORED_NODES_NUM, newFavoredNodes.size());
        LOG.info("Region: " + regionInfo.getEncodedName() + " FN: " + newFavoredNodes);
        Map<RegionInfo, List<ServerName>> regionFNMap = Maps.newHashMap();
        regionFNMap.put(regionInfo, newFavoredNodes);
        fnm.updateFavoredNodes(regionFNMap);
        LOG.info("Assigning region: " + regionInfo.getEncodedName());
        admin.assign(regionInfo.getEncodedNameAsBytes());
    }
    TEST_UTIL.waitUntilNoRegionsInTransition(60000);
    assertEquals("Not all regions are online", REGION_NUM, admin.getRegions(tableName).size());
    admin.balancerSwitch(true, true);
    assertTrue("Balancer did not run", admin.balance());
    TEST_UTIL.waitUntilNoRegionsInTransition(60000);
    checkFavoredNodeAssignments(tableName, fnm, regionStates);
}
Also used : FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) IOException(java.io.IOException) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode) TableName(org.apache.hadoop.hbase.TableName) RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) FavoredNodeAssignmentHelper(org.apache.hadoop.hbase.favored.FavoredNodeAssignmentHelper) ServerName(org.apache.hadoop.hbase.ServerName) List(java.util.List) Waiter(org.apache.hadoop.hbase.Waiter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 20 with FavoredNodesManager

use of org.apache.hadoop.hbase.favored.FavoredNodesManager in project hbase by apache.

the class TestFavoredStochasticLoadBalancer method testRandomAssignmentWithNoFavNodes.

@Test
public void testRandomAssignmentWithNoFavNodes() throws Exception {
    final String tableName = "testRandomAssignmentWithNoFavNodes";
    TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(TableName.valueOf(tableName)).setColumnFamily(ColumnFamilyDescriptorBuilder.of(HConstants.CATALOG_FAMILY)).build();
    admin.createTable(tableDescriptor);
    TEST_UTIL.waitTableAvailable(tableDescriptor.getTableName());
    RegionInfo hri = admin.getRegions(TableName.valueOf(tableName)).get(0);
    FavoredNodesManager fnm = master.getFavoredNodesManager();
    fnm.deleteFavoredNodesForRegions(Lists.newArrayList(hri));
    assertNull("Favored nodes not found null after delete", fnm.getFavoredNodes(hri));
    LoadBalancer balancer = master.getLoadBalancer();
    ServerName destination = balancer.randomAssignment(hri, Lists.newArrayList(admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet().stream().collect(Collectors.toList())));
    assertNotNull(destination);
    List<ServerName> favoredNodes = fnm.getFavoredNodes(hri);
    assertNotNull(favoredNodes);
    boolean containsFN = false;
    for (ServerName sn : favoredNodes) {
        if (ServerName.isSameAddress(destination, sn)) {
            containsFN = true;
        }
    }
    assertTrue("Destination server does not belong to favored nodes.", containsFN);
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager) LoadBalancer(org.apache.hadoop.hbase.master.LoadBalancer) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Test(org.junit.Test)

Aggregations

FavoredNodesManager (org.apache.hadoop.hbase.favored.FavoredNodesManager)20 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)13 ServerName (org.apache.hadoop.hbase.ServerName)12 IOException (java.io.IOException)11 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)10 Test (org.junit.Test)9 List (java.util.List)8 RegionStates (org.apache.hadoop.hbase.master.assignment.RegionStates)8 TableName (org.apache.hadoop.hbase.TableName)7 Waiter (org.apache.hadoop.hbase.Waiter)5 Configuration (org.apache.hadoop.conf.Configuration)4 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)4 ArrayList (java.util.ArrayList)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 Path (org.apache.hadoop.fs.Path)3 FavoredNodeAssignmentHelper (org.apache.hadoop.hbase.favored.FavoredNodeAssignmentHelper)3 RegionStateNode (org.apache.hadoop.hbase.master.assignment.RegionStateNode)3 Collections (java.util.Collections)2 HMaster (org.apache.hadoop.hbase.master.HMaster)2 LoadBalancer (org.apache.hadoop.hbase.master.LoadBalancer)2