Search in sources :

Example 1 with RegionStateTransitionContext

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

the class SplitRequest method requestRegionSplit.

private void requestRegionSplit() {
    final TableName table = parent.getTable();
    final RegionInfo hri_a = RegionInfoBuilder.newBuilder(table).setStartKey(parent.getStartKey()).setEndKey(midKey).build();
    final RegionInfo hri_b = RegionInfoBuilder.newBuilder(table).setStartKey(midKey).setEndKey(parent.getEndKey()).build();
    // are created just to pass the information to the reportRegionStateTransition().
    if (!server.reportRegionStateTransition(new RegionStateTransitionContext(TransitionCode.READY_TO_SPLIT, HConstants.NO_SEQNUM, -1, parent, hri_a, hri_b))) {
        LOG.error("Unable to ask master to split " + parent.getRegionNameAsString());
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) RegionStateTransitionContext(org.apache.hadoop.hbase.regionserver.RegionServerServices.RegionStateTransitionContext) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo)

Example 2 with RegionStateTransitionContext

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

the class UnassignRegionHandler method process.

@Override
public void process() throws IOException {
    HRegionServer rs = getServer();
    byte[] encodedNameBytes = Bytes.toBytes(encodedName);
    Boolean previous = rs.getRegionsInTransitionInRS().putIfAbsent(encodedNameBytes, Boolean.FALSE);
    if (previous != null) {
        if (previous) {
            // This could happen as we will update the region state to OPEN when calling
            // reportRegionStateTransition, so the HMaster will think the region is online, before we
            // actually open the region, as reportRegionStateTransition is part of the opening process.
            long backoff = retryCounter.getBackoffTimeAndIncrementAttempts();
            LOG.warn("Received CLOSE for {} which we are already " + "trying to OPEN; try again after {}ms", encodedName, backoff);
            rs.getExecutorService().delayedSubmit(this, backoff, TimeUnit.MILLISECONDS);
        } else {
            LOG.info("Received CLOSE for {} which we are already trying to CLOSE," + " but not completed yet", encodedName);
        }
        return;
    }
    HRegion region = rs.getRegion(encodedName);
    if (region == null) {
        LOG.debug("Received CLOSE for {} which is not ONLINE and we're not opening/closing.", encodedName);
        rs.getRegionsInTransitionInRS().remove(encodedNameBytes, Boolean.FALSE);
        return;
    }
    String regionName = region.getRegionInfo().getEncodedName();
    LOG.info("Close {}", regionName);
    if (region.getCoprocessorHost() != null) {
        // XXX: The behavior is a bit broken. At master side there is no FAILED_CLOSE state, so if
        // there are exception thrown from the CP, we can not report the error to master, and if
        // here we just return without calling reportRegionStateTransition, the TRSP at master side
        // will hang there for ever. So here if the CP throws an exception out, the only way is to
        // abort the RS...
        region.getCoprocessorHost().preClose(abort);
    }
    if (region.close(abort) == null) {
        // XXX: Is this still possible? The old comment says about split, but now split is done at
        // master side, so...
        LOG.warn("Can't close {}, already closed during close()", regionName);
        rs.getRegionsInTransitionInRS().remove(encodedNameBytes, Boolean.FALSE);
        return;
    }
    rs.removeRegion(region, destination);
    if (!rs.reportRegionStateTransition(new RegionStateTransitionContext(TransitionCode.CLOSED, HConstants.NO_SEQNUM, closeProcId, -1, region.getRegionInfo()))) {
        throw new IOException("Failed to report close to master: " + regionName);
    }
    // Cache the close region procedure id after report region transition succeed.
    rs.finishRegionProcedure(closeProcId);
    rs.getRegionsInTransitionInRS().remove(encodedNameBytes, Boolean.FALSE);
    LOG.info("Closed {}", regionName);
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) RegionStateTransitionContext(org.apache.hadoop.hbase.regionserver.RegionServerServices.RegionStateTransitionContext) IOException(java.io.IOException) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer)

Example 3 with RegionStateTransitionContext

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

the class AssignRegionHandler method cleanUpAndReportFailure.

private void cleanUpAndReportFailure(IOException error) throws IOException {
    LOG.warn("Failed to open region {}, will report to master", regionInfo.getRegionNameAsString(), error);
    HRegionServer rs = getServer();
    rs.getRegionsInTransitionInRS().remove(regionInfo.getEncodedNameAsBytes(), Boolean.TRUE);
    if (!rs.reportRegionStateTransition(new RegionStateTransitionContext(TransitionCode.FAILED_OPEN, HConstants.NO_SEQNUM, openProcId, masterSystemTime, regionInfo))) {
        throw new IOException("Failed to report failed open to master: " + regionInfo.getRegionNameAsString());
    }
}
Also used : RegionStateTransitionContext(org.apache.hadoop.hbase.regionserver.RegionServerServices.RegionStateTransitionContext) IOException(java.io.IOException) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer)

Example 4 with RegionStateTransitionContext

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

the class CloseRegionHandler method process.

@Override
public void process() throws IOException {
    String name = regionInfo.getEncodedName();
    LOG.trace("Processing close of {}", name);
    // Check that this region is being served here
    HRegion region = (HRegion) rsServices.getRegion(name);
    try {
        if (region == null) {
            LOG.warn("Received CLOSE for region {} but currently not serving - ignoring", name);
            // TODO: do better than a simple warning
            return;
        }
        // Close the region
        if (region.close(abort) == null) {
            // This region has already been closed. Should not happen (A unit test makes this
            // happen as a side effect, TestRegionObserverInterface.testPreWALAppendNotCalledOnMetaEdit)
            LOG.warn("Can't close {}; already closed", name);
            return;
        }
        this.rsServices.removeRegion(region, destination);
        rsServices.reportRegionStateTransition(new RegionStateTransitionContext(TransitionCode.CLOSED, HConstants.NO_SEQNUM, Procedure.NO_PROC_ID, -1, regionInfo));
        // Done!  Region is closed on this RS
        LOG.debug("Closed {}", region.getRegionInfo().getRegionNameAsString());
    } finally {
        // Clear any reference in getServer().getRegionsInTransitionInRS() on success or failure,
        // since a reference was added before this CRH was invoked. If we don't clear it, it can
        // hold up regionserver abort on cluster shutdown. HBASE-23984.
        this.rsServices.getRegionsInTransitionInRS().remove(regionInfo.getEncodedNameAsBytes());
    }
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) RegionStateTransitionContext(org.apache.hadoop.hbase.regionserver.RegionServerServices.RegionStateTransitionContext)

Aggregations

RegionStateTransitionContext (org.apache.hadoop.hbase.regionserver.RegionServerServices.RegionStateTransitionContext)4 IOException (java.io.IOException)2 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)2 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)2 TableName (org.apache.hadoop.hbase.TableName)1 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)1