Search in sources :

Example 36 with HRegionInfo

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

the class ServerCrashProcedure method calcRegionsToAssign.

/**
   * Figure out what we need to assign. Should be idempotent.
   * @param env
   * @return List of calculated regions to assign; may be empty or null.
   * @throws IOException
   */
private List<HRegionInfo> calcRegionsToAssign(final MasterProcedureEnv env) throws IOException {
    AssignmentManager am = env.getMasterServices().getAssignmentManager();
    List<HRegionInfo> regionsToAssignAggregator = new ArrayList<>();
    int replicaCount = env.getMasterConfiguration().getInt(HConstants.META_REPLICAS_NUM, HConstants.DEFAULT_META_REPLICA_NUM);
    for (int i = 1; i < replicaCount; i++) {
        HRegionInfo metaHri = RegionReplicaUtil.getRegionInfoForReplica(HRegionInfo.FIRST_META_REGIONINFO, i);
        if (am.isCarryingMetaReplica(this.serverName, metaHri)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Reassigning meta replica" + metaHri + " that was on " + this.serverName);
            }
            regionsToAssignAggregator.add(metaHri);
        }
    }
    // Clean out anything in regions in transition.
    List<HRegionInfo> regionsInTransition = am.cleanOutCrashedServerReferences(serverName);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Reassigning " + size(this.regionsOnCrashedServer) + " region(s) that " + (serverName == null ? "null" : serverName) + " was carrying (and " + regionsInTransition.size() + " regions(s) that were opening on this server)");
    }
    regionsToAssignAggregator.addAll(regionsInTransition);
    // Iterate regions that were on this server and figure which of these we need to reassign
    if (this.regionsOnCrashedServer != null && !this.regionsOnCrashedServer.isEmpty()) {
        RegionStates regionStates = am.getRegionStates();
        for (HRegionInfo hri : this.regionsOnCrashedServer) {
            if (regionsInTransition.contains(hri))
                continue;
            String encodedName = hri.getEncodedName();
            Lock lock = am.acquireRegionLock(encodedName);
            try {
                RegionState rit = regionStates.getRegionTransitionState(hri);
                if (processDeadRegion(hri, am)) {
                    ServerName addressFromAM = regionStates.getRegionServerOfRegion(hri);
                    if (addressFromAM != null && !addressFromAM.equals(this.serverName)) {
                        // If this region is in transition on the dead server, it must be
                        // opening or pending_open, which should have been covered by
                        // AM#cleanOutCrashedServerReferences
                        LOG.info("Skip assigning " + hri.getRegionNameAsString() + " because opened on " + addressFromAM.getServerName());
                        continue;
                    }
                    if (rit != null) {
                        if (rit.getServerName() != null && !rit.isOnServer(this.serverName)) {
                            // Skip regions that are in transition on other server
                            LOG.info("Skip assigning region in transition on other server" + rit);
                            continue;
                        }
                        LOG.info("Reassigning region " + rit + " and clearing zknode if exists");
                        regionStates.updateRegionState(hri, RegionState.State.OFFLINE);
                    } else if (regionStates.isRegionInState(hri, RegionState.State.SPLITTING_NEW, RegionState.State.MERGING_NEW)) {
                        regionStates.updateRegionState(hri, RegionState.State.OFFLINE);
                    }
                    regionsToAssignAggregator.add(hri);
                // TODO: The below else if is different in branch-1 from master branch.
                } else if (rit != null) {
                    if ((rit.isClosing() || rit.isFailedClose() || rit.isOffline()) && am.getTableStateManager().isTableState(hri.getTable(), TableState.State.DISABLED, TableState.State.DISABLING) || am.getReplicasToClose().contains(hri)) {
                        // If the table was partially disabled and the RS went down, we should clear the
                        // RIT and remove the node for the region.
                        // The rit that we use may be stale in case the table was in DISABLING state
                        // but though we did assign we will not be clearing the znode in CLOSING state.
                        // Doing this will have no harm. See HBASE-5927
                        regionStates.updateRegionState(hri, RegionState.State.OFFLINE);
                        am.offlineDisabledRegion(hri);
                    } else {
                        LOG.warn("THIS SHOULD NOT HAPPEN: unexpected region in transition " + rit + " not to be assigned by SSH of server " + serverName);
                    }
                }
            } finally {
                lock.unlock();
            }
        }
    }
    return regionsToAssignAggregator;
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) RegionState(org.apache.hadoop.hbase.master.RegionState) RegionStates(org.apache.hadoop.hbase.master.RegionStates) ServerName(org.apache.hadoop.hbase.ServerName) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager) ArrayList(java.util.ArrayList) Lock(java.util.concurrent.locks.Lock)

Example 37 with HRegionInfo

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

the class RestoreSnapshotHelper method cloneRegionInfo.

public static HRegionInfo cloneRegionInfo(TableName tableName, HRegionInfo snapshotRegionInfo) {
    HRegionInfo regionInfo = new HRegionInfo(tableName, snapshotRegionInfo.getStartKey(), snapshotRegionInfo.getEndKey(), snapshotRegionInfo.isSplit(), snapshotRegionInfo.getRegionId());
    regionInfo.setOffline(snapshotRegionInfo.isOffline());
    return regionInfo;
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo)

Example 38 with HRegionInfo

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

the class RestoreSnapshotHelper method cloneHdfsRegions.

/**
   * Clone specified regions. For each region create a new region
   * and create a HFileLink for each hfile.
   */
private HRegionInfo[] cloneHdfsRegions(final ThreadPoolExecutor exec, final Map<String, SnapshotRegionManifest> regionManifests, final List<HRegionInfo> regions) throws IOException {
    if (regions == null || regions.isEmpty())
        return null;
    final Map<String, HRegionInfo> snapshotRegions = new HashMap<>(regions.size());
    // clone region info (change embedded tableName with the new one)
    HRegionInfo[] clonedRegionsInfo = new HRegionInfo[regions.size()];
    for (int i = 0; i < clonedRegionsInfo.length; ++i) {
        // clone the region info from the snapshot region info
        HRegionInfo snapshotRegionInfo = regions.get(i);
        clonedRegionsInfo[i] = cloneRegionInfo(snapshotRegionInfo);
        // add the region name mapping between snapshot and cloned
        String snapshotRegionName = snapshotRegionInfo.getEncodedName();
        String clonedRegionName = clonedRegionsInfo[i].getEncodedName();
        regionsMap.put(Bytes.toBytes(snapshotRegionName), Bytes.toBytes(clonedRegionName));
        LOG.info("clone region=" + snapshotRegionName + " as " + clonedRegionName);
        // Add mapping between cloned region name and snapshot region info
        snapshotRegions.put(clonedRegionName, snapshotRegionInfo);
    }
    // create the regions on disk
    ModifyRegionUtils.createRegions(exec, conf, rootDir, tableDesc, clonedRegionsInfo, new ModifyRegionUtils.RegionFillTask() {

        @Override
        public void fillRegion(final HRegion region) throws IOException {
            HRegionInfo snapshotHri = snapshotRegions.get(region.getRegionInfo().getEncodedName());
            cloneRegion(region, snapshotHri, regionManifests.get(snapshotHri.getEncodedName()));
        }
    });
    return clonedRegionsInfo;
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) HashMap(java.util.HashMap) ModifyRegionUtils(org.apache.hadoop.hbase.util.ModifyRegionUtils) IOException(java.io.IOException)

Example 39 with HRegionInfo

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

the class Canary method sniff.

/*
   * Loops over regions that owns this table, and output some information abouts the state.
   */
private static List<Future<Void>> sniff(final Admin admin, final Sink sink, HTableDescriptor tableDesc, ExecutorService executor, TaskType taskType, boolean rawScanEnabled) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("reading list of regions for table %s", tableDesc.getTableName()));
    }
    Table table = null;
    try {
        table = admin.getConnection().getTable(tableDesc.getTableName());
    } catch (TableNotFoundException e) {
        return new ArrayList<>();
    } finally {
        if (table != null) {
            table.close();
        }
    }
    List<RegionTask> tasks = new ArrayList<>();
    RegionLocator regionLocator = null;
    try {
        regionLocator = admin.getConnection().getRegionLocator(tableDesc.getTableName());
        for (HRegionLocation location : regionLocator.getAllRegionLocations()) {
            ServerName rs = location.getServerName();
            HRegionInfo region = location.getRegionInfo();
            tasks.add(new RegionTask(admin.getConnection(), region, rs, sink, taskType, rawScanEnabled));
        }
    } finally {
        if (regionLocator != null) {
            regionLocator.close();
        }
    }
    return executor.invokeAll(tasks);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) Table(org.apache.hadoop.hbase.client.Table) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList)

Example 40 with HRegionInfo

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

the class TestAdmin1 method verifyRoundRobinDistribution.

protected void verifyRoundRobinDistribution(ClusterConnection c, RegionLocator regionLocator, int expectedRegions) throws IOException {
    int numRS = c.getCurrentNrHRS();
    List<HRegionLocation> regions = regionLocator.getAllRegionLocations();
    Map<ServerName, List<HRegionInfo>> server2Regions = new HashMap<>();
    for (HRegionLocation loc : regions) {
        ServerName server = loc.getServerName();
        List<HRegionInfo> regs = server2Regions.get(server);
        if (regs == null) {
            regs = new ArrayList<>();
            server2Regions.put(server, regs);
        }
        regs.add(loc.getRegionInfo());
    }
    if (numRS >= 2) {
        // Ignore the master region server,
        // which contains less regions by intention.
        numRS--;
    }
    float average = (float) expectedRegions / numRS;
    int min = (int) Math.floor(average);
    int max = (int) Math.ceil(average);
    for (List<HRegionInfo> regionList : server2Regions.values()) {
        assertTrue(regionList.size() == min || regionList.size() == max);
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) HashMap(java.util.HashMap) ServerName(org.apache.hadoop.hbase.ServerName) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)408 ServerName (org.apache.hadoop.hbase.ServerName)153 Test (org.junit.Test)141 TableName (org.apache.hadoop.hbase.TableName)118 ArrayList (java.util.ArrayList)86 IOException (java.io.IOException)83 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)75 Path (org.apache.hadoop.fs.Path)63 List (java.util.List)59 HashMap (java.util.HashMap)57 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)49 Table (org.apache.hadoop.hbase.client.Table)47 Map (java.util.Map)43 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)41 FileSystem (org.apache.hadoop.fs.FileSystem)40 Configuration (org.apache.hadoop.conf.Configuration)38 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)35 TreeMap (java.util.TreeMap)26 HashSet (java.util.HashSet)23 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)22