Search in sources :

Example 6 with FavoredNodesManager

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

the class DeleteTableProcedure method deleteFromMeta.

protected static void deleteFromMeta(final MasterProcedureEnv env, final TableName tableName, List<RegionInfo> regions) throws IOException {
    // Clean any remaining rows for this table.
    cleanRegionsInMeta(env, tableName);
    // clean region references from the server manager
    env.getMasterServices().getServerManager().removeRegions(regions);
    // Clear Favored Nodes for this table
    FavoredNodesManager fnm = env.getMasterServices().getFavoredNodesManager();
    if (fnm != null) {
        fnm.deleteFavoredNodesForRegions(regions);
    }
    deleteTableDescriptorCache(env, tableName);
}
Also used : FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager)

Example 7 with FavoredNodesManager

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

the class RestoreSnapshotProcedure method deleteRegionsFromInMemoryStates.

/**
 * Delete regions from in-memory states
 * @param regionInfos regions to delete
 * @param env MasterProcedureEnv
 * @param regionReplication the number of region replications
 */
private void deleteRegionsFromInMemoryStates(List<RegionInfo> regionInfos, MasterProcedureEnv env, int regionReplication) {
    FavoredNodesManager fnm = env.getMasterServices().getFavoredNodesManager();
    env.getAssignmentManager().getRegionStates().deleteRegions(regionInfos);
    env.getMasterServices().getServerManager().removeRegions(regionInfos);
    if (fnm != null) {
        fnm.deleteFavoredNodesForRegions(regionInfos);
    }
    // For region replicas
    if (regionReplication > 1) {
        for (RegionInfo regionInfo : regionInfos) {
            for (int i = 1; i < regionReplication; i++) {
                RegionInfo regionInfoForReplica = RegionReplicaUtil.getRegionInfoForReplica(regionInfo, i);
                env.getAssignmentManager().getRegionStates().deleteRegion(regionInfoForReplica);
                env.getMasterServices().getServerManager().removeRegion(regionInfoForReplica);
                if (fnm != null) {
                    fnm.deleteFavoredNodesForRegion(regionInfoForReplica);
                }
            }
        }
    }
}
Also used : FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo)

Example 8 with FavoredNodesManager

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

the class TestFavoredStochasticLoadBalancer method testBalancerWithoutFavoredNodes.

@Test
public void testBalancerWithoutFavoredNodes() throws Exception {
    TableName tableName = TableName.valueOf("testBalancerWithoutFavoredNodes");
    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 thats supposed to be in transition: " + region);
    FavoredNodesManager fnm = master.getFavoredNodesManager();
    List<ServerName> currentFN = fnm.getFavoredNodes(region);
    assertNotNull(currentFN);
    fnm.deleteFavoredNodesForRegions(Lists.newArrayList(region));
    RegionStates regionStates = master.getAssignmentManager().getRegionStates();
    admin.balancerSwitch(true, true);
    // Balancer should unassign the region
    assertTrue("Balancer did not run", admin.balance());
    TEST_UTIL.waitUntilNoRegionsInTransition();
    admin.assign(region.getEncodedNameAsBytes());
    TEST_UTIL.waitUntilNoRegionsInTransition(60000);
    currentFN = fnm.getFavoredNodes(region);
    assertNotNull(currentFN);
    assertEquals("Expected number of FN not present", FavoredNodeAssignmentHelper.FAVORED_NODES_NUM, currentFN.size());
    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) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Test(org.junit.Test)

Example 9 with FavoredNodesManager

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

the class TestFavoredStochasticLoadBalancer method testMisplacedRegions.

@Ignore
@Test
public void testMisplacedRegions() throws Exception {
    TableName tableName = TableName.valueOf("testMisplacedRegions");
    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 misplacedRegion = admin.getRegions(tableName).get(0);
    FavoredNodesManager fnm = master.getFavoredNodesManager();
    List<ServerName> currentFN = fnm.getFavoredNodes(misplacedRegion);
    assertNotNull(currentFN);
    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));
    }
    for (ServerName sn : currentFN) {
        serversForNewFN.remove(sn);
    }
    FavoredNodeAssignmentHelper helper = new FavoredNodeAssignmentHelper(serversForNewFN, conf);
    helper.initialize();
    List<ServerName> newFavoredNodes = helper.generateFavoredNodes(misplacedRegion);
    assertNotNull(newFavoredNodes);
    assertEquals(FavoredNodeAssignmentHelper.FAVORED_NODES_NUM, newFavoredNodes.size());
    Map<RegionInfo, List<ServerName>> regionFNMap = Maps.newHashMap();
    regionFNMap.put(misplacedRegion, newFavoredNodes);
    fnm.updateFavoredNodes(regionFNMap);
    final RegionStates regionStates = master.getAssignmentManager().getRegionStates();
    final ServerName current = regionStates.getRegionServerOfRegion(misplacedRegion);
    assertNull("Misplaced region is still hosted on favored node, not expected.", FavoredNodesPlan.getFavoredServerPosition(fnm.getFavoredNodes(misplacedRegion), current));
    admin.balancerSwitch(true, true);
    assertTrue("Balancer did not run", admin.balance());
    TEST_UTIL.waitFor(120000, 30000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            ServerName host = regionStates.getRegionServerOfRegion(misplacedRegion);
            return !ServerName.isSameAddress(host, current);
        }
    });
    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) 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 10 with FavoredNodesManager

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

the class TestFavoredStochasticLoadBalancer method testBasicRegionPlacementAndReplicaLoad.

@Test
public void testBasicRegionPlacementAndReplicaLoad() throws Exception {
    String tableName = "testBasicRegionPlacement";
    TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(TableName.valueOf(tableName)).setColumnFamily(ColumnFamilyDescriptorBuilder.of(HConstants.CATALOG_FAMILY)).build();
    admin.createTable(tableDescriptor, Bytes.toBytes("aaa"), Bytes.toBytes("zzz"), REGION_NUM);
    TEST_UTIL.waitTableAvailable(tableDescriptor.getTableName());
    FavoredNodesManager fnm = master.getFavoredNodesManager();
    List<RegionInfo> regionsOfTable = admin.getRegions(TableName.valueOf(tableName));
    for (RegionInfo rInfo : regionsOfTable) {
        Set<ServerName> favNodes = Sets.newHashSet(fnm.getFavoredNodes(rInfo));
        assertNotNull(favNodes);
        assertEquals(FavoredNodeAssignmentHelper.FAVORED_NODES_NUM, favNodes.size());
    }
    Map<ServerName, List<Integer>> replicaLoadMap = fnm.getReplicaLoad(Lists.newArrayList(admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet()));
    assertTrue("Not all replica load collected.", admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().size() == replicaLoadMap.size());
    for (Entry<ServerName, List<Integer>> entry : replicaLoadMap.entrySet()) {
        assertTrue(entry.getValue().size() == FavoredNodeAssignmentHelper.FAVORED_NODES_NUM);
        assertTrue(entry.getValue().get(0) >= 0);
        assertTrue(entry.getValue().get(1) >= 0);
        assertTrue(entry.getValue().get(2) >= 0);
    }
    admin.disableTable(TableName.valueOf(tableName));
    admin.deleteTable(TableName.valueOf(tableName));
    replicaLoadMap = fnm.getReplicaLoad(Lists.newArrayList(admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet()));
    assertTrue("replica load found " + replicaLoadMap.size() + " instead of 0.", replicaLoadMap.size() == admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().size());
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) List(java.util.List) 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