Search in sources :

Example 11 with FavoredNodesManager

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

the class TestFavoredStochasticLoadBalancer method testAllFavoredNodesDeadMasterRestarted.

@Ignore
@Test
public void testAllFavoredNodesDeadMasterRestarted() throws Exception {
    TableName tableName = TableName.valueOf("testAllFavoredNodesDeadMasterRestarted");
    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 regionStatesBeforeMaster = master.getAssignmentManager().getRegionStates();
    TEST_UTIL.waitFor(10000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return regionStatesBeforeMaster.getRegionState(region).isFailedOpen();
        }
    });
    assertTrue("Region: " + region + " should be RIT", regionStatesBeforeMaster.getRegionState(region).isFailedOpen());
    List<RegionInfo> rit = Lists.newArrayList();
    for (RegionStateNode regionState : regionStatesBeforeMaster.getRegionsInTransition()) {
        RegionInfo regionInfo = regionState.getRegionInfo();
        LOG.debug("Region in transition after stopping FN's: " + regionInfo);
        rit.add(regionInfo);
        assertTrue("Region: " + regionInfo + " should be RIT", regionStatesBeforeMaster.getRegionState(regionInfo).isFailedOpen());
        assertEquals("Region: " + regionInfo + " does not belong to table: " + tableName, tableName, regionInfo.getTable());
    }
    Configuration conf = cluster.getConf();
    conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, SLAVES - FavoredNodeAssignmentHelper.FAVORED_NODES_NUM);
    cluster.stopMaster(master.getServerName());
    cluster.waitForMasterToStop(master.getServerName(), 60000);
    cluster.startMaster();
    cluster.waitForActiveAndReadyMaster();
    master = cluster.getMaster();
    fnm = master.getFavoredNodesManager();
    RegionStates regionStates = master.getAssignmentManager().getRegionStates();
    assertTrue("Region: " + region + " should be RIT", regionStates.getRegionState(region).isFailedOpen());
    for (RegionInfo regionInfo : rit) {
        assertTrue("Region: " + regionInfo + " should be RIT", regionStates.getRegionState(regionInfo).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 (RegionInfo regionInfo : rit) {
        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 : Configuration(org.apache.hadoop.conf.Configuration) 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 12 with FavoredNodesManager

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

the class CatalogJanitor method cleanParent.

/**
   * If daughters no longer hold reference to the parents, delete the parent.
   * @param parent HRegionInfo of split offlined parent
   * @param rowContent Content of <code>parent</code> row in
   * <code>metaRegionName</code>
   * @return True if we removed <code>parent</code> from meta table and from
   * the filesystem.
   * @throws IOException
   */
boolean cleanParent(final HRegionInfo parent, Result rowContent) throws IOException {
    boolean result = false;
    // be inserted/deleted together
    if (rowContent.getValue(HConstants.CATALOG_FAMILY, HConstants.MERGEA_QUALIFIER) != null) {
        // wait cleaning merge region first
        return result;
    }
    // Run checks on each daughter split.
    PairOfSameType<HRegionInfo> daughters = MetaTableAccessor.getDaughterRegions(rowContent);
    Pair<Boolean, Boolean> a = checkDaughterInFs(parent, daughters.getFirst());
    Pair<Boolean, Boolean> b = checkDaughterInFs(parent, daughters.getSecond());
    if (hasNoReferences(a) && hasNoReferences(b)) {
        LOG.debug("Deleting region " + parent.getRegionNameAsString() + " because daughter splits no longer hold references");
        FileSystem fs = this.services.getMasterFileSystem().getFileSystem();
        if (LOG.isTraceEnabled())
            LOG.trace("Archiving parent region: " + parent);
        HFileArchiver.archiveRegion(this.services.getConfiguration(), fs, parent);
        MetaTableAccessor.deleteRegion(this.connection, parent);
        services.getServerManager().removeRegion(parent);
        FavoredNodesManager fnm = this.services.getFavoredNodesManager();
        if (fnm != null) {
            fnm.deleteFavoredNodesForRegions(Lists.newArrayList(parent));
        }
        result = true;
    }
    return result;
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) FileSystem(org.apache.hadoop.fs.FileSystem) HRegionFileSystem(org.apache.hadoop.hbase.regionserver.HRegionFileSystem) FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 13 with FavoredNodesManager

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

the class AssignmentManagerUtil method removeNonDefaultReplicas.

static void removeNonDefaultReplicas(MasterProcedureEnv env, Stream<RegionInfo> regions, int regionReplication) {
    // Remove from in-memory states
    regions.flatMap(hri -> IntStream.range(1, regionReplication).mapToObj(i -> RegionReplicaUtil.getRegionInfoForReplica(hri, i))).forEach(hri -> {
        env.getAssignmentManager().getRegionStates().deleteRegion(hri);
        env.getMasterServices().getServerManager().removeRegion(hri);
        FavoredNodesManager fnm = env.getMasterServices().getFavoredNodesManager();
        if (fnm != null) {
            fnm.deleteFavoredNodesForRegions(Collections.singletonList(hri));
        }
    });
}
Also used : IntStream(java.util.stream.IntStream) DEFAULT_HBASE_ENABLE_SEPARATE_CHILD_REGIONS(org.apache.hadoop.hbase.HConstants.DEFAULT_HBASE_ENABLE_SEPARATE_CHILD_REGIONS) ListIterator(java.util.ListIterator) GetRegionInfoResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoResponse) FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager) RegionReplicaUtil(org.apache.hadoop.hbase.client.RegionReplicaUtil) WALSplitUtil(org.apache.hadoop.hbase.wal.WALSplitUtil) IOException(java.io.IOException) ArrayUtils(org.apache.commons.lang3.ArrayUtils) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) Collectors(java.util.stream.Collectors) RequestConverter(org.apache.hadoop.hbase.shaded.protobuf.RequestConverter) ArrayList(java.util.ArrayList) GetRegionInfoRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest) List(java.util.List) HConstants(org.apache.hadoop.hbase.HConstants) Stream(java.util.stream.Stream) FutureUtils(org.apache.hadoop.hbase.util.FutureUtils) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) AsyncRegionServerAdmin(org.apache.hadoop.hbase.client.AsyncRegionServerAdmin) Collections(java.util.Collections) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) ServerName(org.apache.hadoop.hbase.ServerName) FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager)

Example 14 with FavoredNodesManager

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

the class RSGroupBasedLoadBalancer method initialize.

@Override
public void initialize() throws IOException {
    if (rsGroupInfoManager == null) {
        rsGroupInfoManager = masterServices.getRSGroupInfoManager();
        if (rsGroupInfoManager == null) {
            String msg = "RSGroupInfoManager hasn't been initialized";
            LOG.error(msg);
            throw new HBaseIOException(msg);
        }
        rsGroupInfoManager.start();
    }
    // Create the balancer
    Configuration conf = masterServices.getConfiguration();
    Class<? extends LoadBalancer> balancerClass;
    @SuppressWarnings("deprecation") String balancerClassName = conf.get(HBASE_RSGROUP_LOADBALANCER_CLASS);
    if (balancerClassName == null) {
        balancerClass = conf.getClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, LoadBalancerFactory.getDefaultLoadBalancerClass(), LoadBalancer.class);
    } else {
        try {
            balancerClass = Class.forName(balancerClassName).asSubclass(LoadBalancer.class);
        } catch (ClassNotFoundException e) {
            throw new IOException(e);
        }
    }
    this.provider = new MasterClusterInfoProvider(masterServices);
    // avoid infinite nesting
    if (getClass().isAssignableFrom(balancerClass)) {
        balancerClass = LoadBalancerFactory.getDefaultLoadBalancerClass();
    }
    internalBalancer = ReflectionUtils.newInstance(balancerClass);
    internalBalancer.setClusterInfoProvider(provider);
    // special handling for favor node balancers
    if (internalBalancer instanceof FavoredNodesPromoter) {
        favoredNodesManager = new FavoredNodesManager(provider);
        ((FavoredNodesPromoter) internalBalancer).setFavoredNodesManager(favoredNodesManager);
    }
    internalBalancer.initialize();
    // init fallback groups
    this.fallbackEnabled = conf.getBoolean(FALLBACK_GROUP_ENABLE_KEY, false);
}
Also used : MasterClusterInfoProvider(org.apache.hadoop.hbase.master.balancer.MasterClusterInfoProvider) Configuration(org.apache.hadoop.conf.Configuration) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) FavoredNodesPromoter(org.apache.hadoop.hbase.favored.FavoredNodesPromoter) LoadBalancer(org.apache.hadoop.hbase.master.LoadBalancer) FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager) IOException(java.io.IOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException)

Example 15 with FavoredNodesManager

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

the class TestFavoredStochasticBalancerPickers method testPickers.

@Test
public void testPickers() throws Exception {
    TableName tableName = TableName.valueOf(name.getMethodName());
    ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(HConstants.CATALOG_FAMILY).build();
    TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(columnFamilyDescriptor).build();
    admin.createTable(desc, Bytes.toBytes("aaa"), Bytes.toBytes("zzz"), REGIONS);
    TEST_UTIL.waitUntilAllRegionsAssigned(tableName);
    TEST_UTIL.loadTable(admin.getConnection().getTable(tableName), HConstants.CATALOG_FAMILY);
    admin.flush(tableName);
    HMaster master = cluster.getMaster();
    FavoredNodesManager fnm = master.getFavoredNodesManager();
    ServerName masterServerName = master.getServerName();
    List<ServerName> excludedServers = Lists.newArrayList(masterServerName);
    final ServerName mostLoadedServer = getRSWithMaxRegions(tableName, excludedServers);
    assertNotNull(mostLoadedServer);
    int numRegions = getTableRegionsFromServer(tableName, mostLoadedServer).size();
    excludedServers.add(mostLoadedServer);
    // Lets find another server with more regions to calculate number of regions to move
    ServerName source = getRSWithMaxRegions(tableName, excludedServers);
    assertNotNull(source);
    int regionsToMove = getTableRegionsFromServer(tableName, source).size() / 2;
    // Since move only works if the target is part of favored nodes of the region, lets get all
    // regions that are movable to mostLoadedServer
    List<RegionInfo> hris = getRegionsThatCanBeMoved(tableName, mostLoadedServer);
    RegionStates rst = master.getAssignmentManager().getRegionStates();
    for (int i = 0; i < regionsToMove; i++) {
        final RegionInfo regionInfo = hris.get(i);
        admin.move(regionInfo.getEncodedNameAsBytes(), mostLoadedServer);
        LOG.info("Moving region: " + hris.get(i).getRegionNameAsString() + " to " + mostLoadedServer);
        TEST_UTIL.waitFor(60000, new Waiter.Predicate<Exception>() {

            @Override
            public boolean evaluate() throws Exception {
                return ServerName.isSameAddress(rst.getRegionServerOfRegion(regionInfo), mostLoadedServer);
            }
        });
    }
    final int finalRegions = numRegions + regionsToMove;
    TEST_UTIL.waitUntilNoRegionsInTransition(60000);
    TEST_UTIL.waitFor(60000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            int numRegions = getTableRegionsFromServer(tableName, mostLoadedServer).size();
            return (numRegions == finalRegions);
        }
    });
    TEST_UTIL.getHBaseCluster().startRegionServerAndWait(60000);
    Map<ServerName, List<RegionInfo>> serverAssignments = Maps.newHashMap();
    ClusterMetrics status = admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
    for (ServerName sn : status.getLiveServerMetrics().keySet()) {
        if (!ServerName.isSameAddress(sn, masterServerName)) {
            serverAssignments.put(sn, getTableRegionsFromServer(tableName, sn));
        }
    }
    RegionHDFSBlockLocationFinder regionFinder = new RegionHDFSBlockLocationFinder();
    regionFinder.setClusterMetrics(admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)));
    regionFinder.setConf(conf);
    regionFinder.setClusterInfoProvider(new MasterClusterInfoProvider(TEST_UTIL.getMiniHBaseCluster().getMaster()));
    BalancerClusterState cluster = new BalancerClusterState(serverAssignments, null, regionFinder, new RackManager(conf));
    LoadOnlyFavoredStochasticBalancer balancer = (LoadOnlyFavoredStochasticBalancer) TEST_UTIL.getMiniHBaseCluster().getMaster().getLoadBalancer().getInternalBalancer();
    cluster.sortServersByRegionCount();
    Integer[] servers = cluster.serverIndicesSortedByRegionCount;
    LOG.info("Servers sorted by region count:" + Arrays.toString(servers));
    LOG.info("Cluster dump: " + cluster);
    if (!mostLoadedServer.equals(cluster.servers[servers[servers.length - 1]])) {
        LOG.error("Most loaded server: " + mostLoadedServer + " does not match: " + cluster.servers[servers[servers.length - 1]]);
    }
    assertEquals(mostLoadedServer, cluster.servers[servers[servers.length - 1]]);
    FavoredStochasticBalancer.FavoredNodeLoadPicker loadPicker = balancer.new FavoredNodeLoadPicker();
    boolean userRegionPicked = false;
    for (int i = 0; i < 100; i++) {
        if (userRegionPicked) {
            break;
        } else {
            BalanceAction action = loadPicker.generate(cluster);
            if (action.getType() == BalanceAction.Type.MOVE_REGION) {
                MoveRegionAction moveRegionAction = (MoveRegionAction) action;
                RegionInfo region = cluster.regions[moveRegionAction.getRegion()];
                assertNotEquals(-1, moveRegionAction.getToServer());
                ServerName destinationServer = cluster.servers[moveRegionAction.getToServer()];
                assertEquals(cluster.servers[moveRegionAction.getFromServer()], mostLoadedServer);
                if (!region.getTable().isSystemTable()) {
                    List<ServerName> favNodes = fnm.getFavoredNodes(region);
                    assertTrue(favNodes.contains(ServerName.valueOf(destinationServer.getAddress(), -1)));
                    userRegionPicked = true;
                }
            }
        }
    }
    assertTrue("load picker did not pick expected regions in 100 iterations.", userRegionPicked);
}
Also used : RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) List(java.util.List) RackManager(org.apache.hadoop.hbase.master.RackManager) FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager) 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) ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) Waiter(org.apache.hadoop.hbase.Waiter) 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