Search in sources :

Example 1 with PostOpenDeployContext

use of org.apache.hadoop.hbase.regionserver.RegionServerServices.PostOpenDeployContext in project hbase by apache.

the class AssignRegionHandler method process.

@Override
public void process() throws IOException {
    HRegionServer rs = getServer();
    String encodedName = regionInfo.getEncodedName();
    byte[] encodedNameBytes = regionInfo.getEncodedNameAsBytes();
    String regionName = regionInfo.getRegionNameAsString();
    Region onlineRegion = rs.getRegion(encodedName);
    if (onlineRegion != null) {
        LOG.warn("Received OPEN for {} which is already online", regionName);
        // reportRegionStateTransition any more.
        return;
    }
    Boolean previous = rs.getRegionsInTransitionInRS().putIfAbsent(encodedNameBytes, Boolean.TRUE);
    if (previous != null) {
        if (previous) {
            // The region is opening and this maybe a retry on the rpc call, it is safe to ignore it.
            LOG.info("Receiving OPEN for {} which we are already trying to OPEN" + " - ignoring this new request for this region.", regionName);
        } else {
            // The region is closing. This is possible as we will update the region state to CLOSED when
            // calling reportRegionStateTransition, so the HMaster will think the region is offline,
            // before we actually close the region, as reportRegionStateTransition is part of the
            // closing process.
            long backoff = retryCounter.getBackoffTimeAndIncrementAttempts();
            LOG.info("Receiving OPEN for {} which we are trying to close, try again after {}ms", regionName, backoff);
            rs.getExecutorService().delayedSubmit(this, backoff, TimeUnit.MILLISECONDS);
        }
        return;
    }
    LOG.info("Open {}", regionName);
    HRegion region;
    try {
        TableDescriptor htd = tableDesc != null ? tableDesc : rs.getTableDescriptors().get(regionInfo.getTable());
        if (htd == null) {
            throw new IOException("Missing table descriptor for " + regionName);
        }
        // pass null for the last parameter, which used to be a CancelableProgressable, as now the
        // opening can not be interrupted by a close request any more.
        Configuration conf = rs.getConfiguration();
        region = HRegion.openHRegion(regionInfo, htd, rs.getWAL(regionInfo), conf, rs, null);
    } catch (IOException e) {
        cleanUpAndReportFailure(e);
        return;
    }
    // From here on out, this is PONR. We can not revert back. The only way to address an
    // exception from here on out is to abort the region server.
    rs.postOpenDeployTasks(new PostOpenDeployContext(region, openProcId, masterSystemTime));
    rs.addRegion(region);
    LOG.info("Opened {}", regionName);
    // Cache the open region procedure id after report region transition succeed.
    rs.finishRegionProcedure(openProcId);
    Boolean current = rs.getRegionsInTransitionInRS().remove(regionInfo.getEncodedNameAsBytes());
    if (current == null) {
        // Should NEVER happen, but let's be paranoid.
        LOG.error("Bad state: we've just opened {} which was NOT in transition", regionName);
    } else if (!current) {
        // Should NEVER happen, but let's be paranoid.
        LOG.error("Bad state: we've just opened {} which was closing", regionName);
    }
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) PostOpenDeployContext(org.apache.hadoop.hbase.regionserver.RegionServerServices.PostOpenDeployContext) Configuration(org.apache.hadoop.conf.Configuration) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Region(org.apache.hadoop.hbase.regionserver.Region) IOException(java.io.IOException) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer)

Aggregations

IOException (java.io.IOException)1 Configuration (org.apache.hadoop.conf.Configuration)1 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)1 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)1 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)1 Region (org.apache.hadoop.hbase.regionserver.Region)1 PostOpenDeployContext (org.apache.hadoop.hbase.regionserver.RegionServerServices.PostOpenDeployContext)1