Search in sources :

Example 1 with State

use of org.apache.hadoop.hbase.master.RegionState.State in project hbase by apache.

the class AssignmentManager method processRegionsInTransition.

/**
   * Processes list of regions in transition at startup
   */
void processRegionsInTransition(Collection<RegionState> regionsInTransition) {
    // to the region if the master dies right after the RPC call is out.
    for (RegionState regionState : regionsInTransition) {
        LOG.info("Processing " + regionState);
        ServerName serverName = regionState.getServerName();
        // case, try assigning it here.
        if (serverName != null && !serverManager.getOnlineServers().containsKey(serverName)) {
            LOG.info("Server " + serverName + " isn't online. SSH will handle this");
            // SSH will handle it
            continue;
        }
        HRegionInfo regionInfo = regionState.getRegion();
        RegionState.State state = regionState.getState();
        switch(state) {
            case CLOSED:
                invokeAssign(regionState.getRegion());
                break;
            case PENDING_OPEN:
                retrySendRegionOpen(regionState);
                break;
            case PENDING_CLOSE:
                retrySendRegionClose(regionState);
                break;
            case FAILED_CLOSE:
            case FAILED_OPEN:
                invokeUnAssign(regionInfo);
                break;
            default:
                // No process for other states
                break;
        }
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ServerName(org.apache.hadoop.hbase.ServerName) State(org.apache.hadoop.hbase.master.RegionState.State)

Example 2 with State

use of org.apache.hadoop.hbase.master.RegionState.State 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 3 with State

use of org.apache.hadoop.hbase.master.RegionState.State in project hbase by apache.

the class RegionStateStore method updateRegionState.

void updateRegionState(long openSeqNum, RegionState newState, RegionState oldState) {
    try {
        HRegionInfo hri = newState.getRegion();
        // Update meta before checking for initialization. Meta state stored in zk.
        if (hri.isMetaRegion()) {
            // persist meta state in MetaTableLocator (which in turn is zk storage currently)
            try {
                MetaTableLocator.setMetaLocation(server.getZooKeeper(), newState.getServerName(), hri.getReplicaId(), newState.getState());
                // Done
                return;
            } catch (KeeperException e) {
                throw new IOException("Failed to update meta ZNode", e);
            }
        }
        if (!initialized || !shouldPersistStateChange(hri, newState, oldState)) {
            return;
        }
        ServerName oldServer = oldState != null ? oldState.getServerName() : null;
        ServerName serverName = newState.getServerName();
        State state = newState.getState();
        int replicaId = hri.getReplicaId();
        Put metaPut = new Put(MetaTableAccessor.getMetaKeyForRegion(hri));
        StringBuilder info = new StringBuilder("Updating hbase:meta row ");
        info.append(hri.getRegionNameAsString()).append(" with state=").append(state);
        if (serverName != null && !serverName.equals(oldServer)) {
            metaPut.addImmutable(HConstants.CATALOG_FAMILY, getServerNameColumn(replicaId), Bytes.toBytes(serverName.getServerName()));
            info.append(", sn=").append(serverName);
        }
        if (openSeqNum >= 0) {
            Preconditions.checkArgument(state == State.OPEN && serverName != null, "Open region should be on a server");
            MetaTableAccessor.addLocation(metaPut, serverName, openSeqNum, -1, replicaId);
            info.append(", openSeqNum=").append(openSeqNum);
            info.append(", server=").append(serverName);
        }
        metaPut.addImmutable(HConstants.CATALOG_FAMILY, getStateColumn(replicaId), Bytes.toBytes(state.name()));
        LOG.info(info);
        HTableDescriptor descriptor = server.getTableDescriptors().get(hri.getTable());
        boolean serial = false;
        if (descriptor != null) {
            serial = server.getTableDescriptors().get(hri.getTable()).hasSerialReplicationScope();
        }
        boolean shouldPutBarrier = serial && state == State.OPEN;
        // Persist the state change to meta
        if (metaRegion != null) {
            try {
                // Assume meta is pinned to master.
                // At least, that's what we want.
                metaRegion.put(metaPut);
                if (shouldPutBarrier) {
                    Put barrierPut = MetaTableAccessor.makeBarrierPut(hri.getEncodedNameAsBytes(), openSeqNum, hri.getTable().getName());
                    metaRegion.put(barrierPut);
                }
                // Done here
                return;
            } catch (Throwable t) {
                // to the master
                synchronized (this) {
                    if (metaRegion != null) {
                        LOG.info("Meta region shortcut failed", t);
                        if (multiHConnection == null) {
                            multiHConnection = new MultiHConnection(server.getConfiguration(), 1);
                        }
                        metaRegion = null;
                    }
                }
            }
        }
        // Called when meta is not on master
        List<Put> list = shouldPutBarrier ? Arrays.asList(metaPut, MetaTableAccessor.makeBarrierPut(hri.getEncodedNameAsBytes(), openSeqNum, hri.getTable().getName())) : Collections.singletonList(metaPut);
        multiHConnection.processBatchCallback(list, TableName.META_TABLE_NAME, null, null);
    } catch (IOException ioe) {
        LOG.error("Failed to persist region state " + newState, ioe);
        server.abort("Failed to update region location", ioe);
    }
}
Also used : IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) MultiHConnection(org.apache.hadoop.hbase.util.MultiHConnection) State(org.apache.hadoop.hbase.master.RegionState.State) ServerName(org.apache.hadoop.hbase.ServerName) KeeperException(org.apache.zookeeper.KeeperException)

Example 4 with State

use of org.apache.hadoop.hbase.master.RegionState.State in project hbase by apache.

the class RegionStates method regionOffline.

/**
   * A region is offline, won't be in transition any more. Its state
   * should be the specified expected state, which can only be
   * Split/Merged/Offline/null(=Offline)/SplittingNew/MergingNew.
   */
public void regionOffline(final HRegionInfo hri, final State expectedState) {
    Preconditions.checkArgument(expectedState == null || RegionState.isUnassignable(expectedState), "Offlined region should not be " + expectedState);
    if (isRegionInState(hri, State.SPLITTING_NEW, State.MERGING_NEW)) {
        // Remove it from all region maps
        deleteRegion(hri);
        return;
    }
    State newState = expectedState == null ? State.OFFLINE : expectedState;
    updateRegionState(hri, newState);
    String encodedName = hri.getEncodedName();
    synchronized (this) {
        regionsInTransition.remove(encodedName);
        ServerName oldServerName = regionAssignments.remove(hri);
        if (oldServerName != null && serverHoldings.containsKey(oldServerName)) {
            if (newState == State.MERGED || newState == State.SPLIT || hri.isMetaRegion() || tableStateManager.isTableState(hri.getTable(), TableState.State.DISABLED, TableState.State.DISABLING)) {
                // Offline the region only if it's merged/split, or the table is disabled/disabling.
                // Otherwise, offline it from this server only when it is online on a different server.
                LOG.info("Offlined " + hri.getShortNameToLog() + " from " + oldServerName);
                removeFromServerHoldings(oldServerName, hri);
                removeFromReplicaMapping(hri);
            } else {
                // Need to remember it so that we can offline it from this
                // server when it is online on a different server.
                oldAssignments.put(encodedName, oldServerName);
            }
        }
    }
}
Also used : TableState(org.apache.hadoop.hbase.client.TableState) State(org.apache.hadoop.hbase.master.RegionState.State) ServerName(org.apache.hadoop.hbase.ServerName)

Example 5 with State

use of org.apache.hadoop.hbase.master.RegionState.State in project hbase by apache.

the class RegionStates method getRegionByStateOfTable.

/**
   * Gets current state of all regions of the table.
   * This method looks at the in-memory state.  It does not go to <code>hbase:meta</code>.
   * Method guaranteed to return keys for all states
   * in {@link org.apache.hadoop.hbase.master.RegionState.State}
   *
   * @param tableName
   * @return Online regions from <code>tableName</code>
   */
public synchronized Map<RegionState.State, List<HRegionInfo>> getRegionByStateOfTable(TableName tableName) {
    Map<RegionState.State, List<HRegionInfo>> tableRegions = new HashMap<>();
    for (State state : State.values()) {
        tableRegions.put(state, new ArrayList<>());
    }
    Map<String, RegionState> indexMap = regionStatesTableIndex.get(tableName);
    if (indexMap == null)
        return tableRegions;
    for (RegionState regionState : indexMap.values()) {
        tableRegions.get(regionState.getState()).add(regionState.getRegion());
    }
    return tableRegions;
}
Also used : HashMap(java.util.HashMap) TableState(org.apache.hadoop.hbase.client.TableState) State(org.apache.hadoop.hbase.master.RegionState.State) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

State (org.apache.hadoop.hbase.master.RegionState.State)5 ServerName (org.apache.hadoop.hbase.ServerName)4 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)3 TableState (org.apache.hadoop.hbase.client.TableState)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1 RegionLocations (org.apache.hadoop.hbase.RegionLocations)1 TableName (org.apache.hadoop.hbase.TableName)1 Put (org.apache.hadoop.hbase.client.Put)1 Result (org.apache.hadoop.hbase.client.Result)1 RegionOpeningState (org.apache.hadoop.hbase.regionserver.RegionOpeningState)1 MultiHConnection (org.apache.hadoop.hbase.util.MultiHConnection)1 KeeperException (org.apache.zookeeper.KeeperException)1