Search in sources :

Example 31 with ServerName

use of org.apache.hadoop.hbase.ServerName in project hbase by apache.

the class AssignmentManager method isCarryingRegion.

/**
   * Check if the shutdown server carries the specific region.
   * @return whether the serverName currently hosts the region
   */
private boolean isCarryingRegion(ServerName serverName, HRegionInfo hri) {
    RegionState regionState = regionStates.getRegionTransitionState(hri);
    ServerName transitionAddr = regionState != null ? regionState.getServerName() : null;
    if (transitionAddr != null) {
        boolean matchTransitionAddr = transitionAddr.equals(serverName);
        LOG.debug("Checking region=" + hri.getRegionNameAsString() + ", transitioning on server=" + matchTransitionAddr + " server being checked: " + serverName + ", matches=" + matchTransitionAddr);
        return matchTransitionAddr;
    }
    ServerName assignedAddr = regionStates.getRegionServerOfRegion(hri);
    boolean matchAssignedAddr = serverName.equals(assignedAddr);
    LOG.debug("based on AM, current region=" + hri.getRegionNameAsString() + " is on server=" + assignedAddr + ", server being checked: " + serverName);
    return matchAssignedAddr;
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName)

Example 32 with ServerName

use of org.apache.hadoop.hbase.ServerName in project hbase by apache.

the class AssignmentManager method prepareDaughterReplicaForAssignment.

private void prepareDaughterReplicaForAssignment(HRegionInfo daughterHri, HRegionInfo parentHri, int replicaId, Map<HRegionInfo, ServerName> map) {
    HRegionInfo parentReplica = RegionReplicaUtil.getRegionInfoForReplica(parentHri, replicaId);
    HRegionInfo daughterReplica = RegionReplicaUtil.getRegionInfoForReplica(daughterHri, replicaId);
    LOG.debug("Created replica region for daughter " + daughterReplica);
    ServerName sn;
    if ((sn = regionStates.getRegionServerOfRegion(parentReplica)) != null) {
        map.put(daughterReplica, sn);
    } else {
        List<ServerName> servers = serverManager.getOnlineServersList();
        sn = servers.get((new Random(System.currentTimeMillis())).nextInt(servers.size()));
        map.put(daughterReplica, sn);
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Random(java.util.Random) ServerName(org.apache.hadoop.hbase.ServerName)

Example 33 with ServerName

use of org.apache.hadoop.hbase.ServerName in project hbase by apache.

the class AssignmentManager method rebuildUserRegions.

/**
   * Rebuild the list of user regions and assignment information.
   * Updates regionstates with findings as we go through list of regions.
   * @return set of servers not online that hosted some regions according to a scan of hbase:meta
   * @throws IOException
   */
Set<ServerName> rebuildUserRegions() throws IOException, KeeperException {
    Set<TableName> disabledOrEnablingTables = tableStateManager.getTablesInStates(TableState.State.DISABLED, TableState.State.ENABLING);
    Set<TableName> disabledOrDisablingOrEnabling = tableStateManager.getTablesInStates(TableState.State.DISABLED, TableState.State.DISABLING, TableState.State.ENABLING);
    // Region assignment from META
    List<Result> results = MetaTableAccessor.fullScanRegions(server.getConnection());
    // Get any new but slow to checkin region server that joined the cluster
    Set<ServerName> onlineServers = serverManager.getOnlineServers().keySet();
    // Set of offline servers to be returned
    Set<ServerName> offlineServers = new HashSet<>();
    // Iterate regions in META
    for (Result result : results) {
        if (result == null && LOG.isDebugEnabled()) {
            LOG.debug("null result from meta - ignoring but this is strange.");
            continue;
        }
        // keep a track of replicas to close. These were the replicas of the originally
        // unmerged regions. The master might have closed them before but it mightn't
        // maybe because it crashed.
        PairOfSameType<HRegionInfo> p = MetaTableAccessor.getMergeRegions(result);
        if (p.getFirst() != null && p.getSecond() != null) {
            int numReplicas = getNumReplicas(server, p.getFirst().getTable());
            for (HRegionInfo merge : p) {
                for (int i = 1; i < numReplicas; i++) {
                    replicasToClose.add(RegionReplicaUtil.getRegionInfoForReplica(merge, i));
                }
            }
        }
        RegionLocations rl = MetaTableAccessor.getRegionLocations(result);
        if (rl == null) {
            continue;
        }
        HRegionLocation[] locations = rl.getRegionLocations();
        if (locations == null) {
            continue;
        }
        for (HRegionLocation hrl : locations) {
            if (hrl == null)
                continue;
            HRegionInfo regionInfo = hrl.getRegionInfo();
            if (regionInfo == null)
                continue;
            int replicaId = regionInfo.getReplicaId();
            State state = RegionStateStore.getRegionState(result, replicaId);
            // but it couldn't maybe because it crashed
            if (replicaId == 0 && state.equals(State.SPLIT)) {
                for (HRegionLocation h : locations) {
                    replicasToClose.add(h.getRegionInfo());
                }
            }
            ServerName lastHost = hrl.getServerName();
            ServerName regionLocation = RegionStateStore.getRegionServer(result, replicaId);
            regionStates.createRegionState(regionInfo, state, regionLocation, lastHost);
            if (!regionStates.isRegionInState(regionInfo, State.OPEN)) {
                // Region is not open (either offline or in transition), skip
                continue;
            }
            TableName tableName = regionInfo.getTable();
            if (!onlineServers.contains(regionLocation)) {
                // Region is located on a server that isn't online
                offlineServers.add(regionLocation);
            } else if (!disabledOrEnablingTables.contains(tableName)) {
                // Region is being served and on an active server
                // add only if region not in disabled or enabling table
                regionStates.regionOnline(regionInfo, regionLocation);
                balancer.regionOnline(regionInfo, regionLocation);
            }
            // this will be used in rolling restarts
            if (!disabledOrDisablingOrEnabling.contains(tableName) && !getTableStateManager().isTableState(tableName, TableState.State.ENABLED)) {
                setEnabledTable(tableName);
            }
        }
    }
    return offlineServers;
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) Result(org.apache.hadoop.hbase.client.Result) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) State(org.apache.hadoop.hbase.master.RegionState.State) TableState(org.apache.hadoop.hbase.client.TableState) RegionOpeningState(org.apache.hadoop.hbase.regionserver.RegionOpeningState) ServerName(org.apache.hadoop.hbase.ServerName) HashSet(java.util.HashSet)

Example 34 with ServerName

use of org.apache.hadoop.hbase.ServerName in project hbase by apache.

the class DrainingServerTracker method add.

private void add(final List<String> servers) throws IOException {
    synchronized (this.drainingServers) {
        this.drainingServers.clear();
        for (String n : servers) {
            final ServerName sn = ServerName.valueOf(ZKUtil.getNodeName(n));
            this.drainingServers.add(sn);
            this.serverManager.addServerToDrainList(sn);
            LOG.info("Draining RS node created, adding to list [" + sn + "]");
        }
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName)

Example 35 with ServerName

use of org.apache.hadoop.hbase.ServerName in project hbase by apache.

the class DrainingServerTracker method nodeDeleted.

@Override
public void nodeDeleted(final String path) {
    if (path.startsWith(watcher.znodePaths.drainingZNode)) {
        final ServerName sn = ServerName.valueOf(ZKUtil.getNodeName(path));
        LOG.info("Draining RS node deleted, removing from list [" + sn + "]");
        remove(sn);
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName)

Aggregations

ServerName (org.apache.hadoop.hbase.ServerName)426 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)202 Test (org.junit.Test)163 ArrayList (java.util.ArrayList)97 TableName (org.apache.hadoop.hbase.TableName)89 IOException (java.io.IOException)87 HashMap (java.util.HashMap)81 List (java.util.List)72 Map (java.util.Map)54 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)45 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)34 Table (org.apache.hadoop.hbase.client.Table)33 HashSet (java.util.HashSet)32 TreeMap (java.util.TreeMap)31 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)29 Configuration (org.apache.hadoop.conf.Configuration)26 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)26 Pair (org.apache.hadoop.hbase.util.Pair)24 KeeperException (org.apache.zookeeper.KeeperException)23 InterruptedIOException (java.io.InterruptedIOException)22