Search in sources :

Example 1 with CloseRegionHandler

use of org.apache.hadoop.hbase.regionserver.handler.CloseRegionHandler in project hbase by apache.

the class HRegionServer method closeRegion.

/**
   * Close asynchronously a region, can be called from the master or internally by the regionserver
   * when stopping. If called from the master, the region will update the znode status.
   *
   * <p>
   * If an opening was in progress, this method will cancel it, but will not start a new close. The
   * coprocessors are not called in this case. A NotServingRegionException exception is thrown.
   * </p>

   * <p>
   *   If a close was in progress, this new request will be ignored, and an exception thrown.
   * </p>
   *
   * @param encodedName Region to close
   * @param abort True if we are aborting
   * @return True if closed a region.
   * @throws NotServingRegionException if the region is not online
   */
protected boolean closeRegion(String encodedName, final boolean abort, final ServerName sn) throws NotServingRegionException {
    //Check for permissions to close.
    Region actualRegion = this.getFromOnlineRegions(encodedName);
    // Can be null if we're calling close on a region that's not online
    if ((actualRegion != null) && (actualRegion.getCoprocessorHost() != null)) {
        try {
            actualRegion.getCoprocessorHost().preClose(false);
        } catch (IOException exp) {
            LOG.warn("Unable to close region: the coprocessor launched an error ", exp);
            return false;
        }
    }
    final Boolean previous = this.regionsInTransitionInRS.putIfAbsent(encodedName.getBytes(), Boolean.FALSE);
    if (Boolean.TRUE.equals(previous)) {
        LOG.info("Received CLOSE for the region:" + encodedName + " , which we are already " + "trying to OPEN. Cancelling OPENING.");
        if (!regionsInTransitionInRS.replace(encodedName.getBytes(), previous, Boolean.FALSE)) {
            // The replace failed. That should be an exceptional case, but theoretically it can happen.
            // We're going to try to do a standard close then.
            LOG.warn("The opening for region " + encodedName + " was done before we could cancel it." + " Doing a standard close now");
            return closeRegion(encodedName, abort, sn);
        }
        // Let's get the region from the online region list again
        actualRegion = this.getFromOnlineRegions(encodedName);
        if (actualRegion == null) {
            // If already online, we still need to close it.
            LOG.info("The opening previously in progress has been cancelled by a CLOSE request.");
            // The master deletes the znode when it receives this exception.
            throw new NotServingRegionException("The region " + encodedName + " was opening but not yet served. Opening is cancelled.");
        }
    } else if (Boolean.FALSE.equals(previous)) {
        LOG.info("Received CLOSE for the region: " + encodedName + ", which we are already trying to CLOSE, but not completed yet");
        return true;
    }
    if (actualRegion == null) {
        LOG.debug("Received CLOSE for a region which is not online, and we're not opening.");
        this.regionsInTransitionInRS.remove(encodedName.getBytes());
        // The master deletes the znode when it receives this exception.
        throw new NotServingRegionException("The region " + encodedName + " is not online, and is not opening.");
    }
    CloseRegionHandler crh;
    final HRegionInfo hri = actualRegion.getRegionInfo();
    if (hri.isMetaRegion()) {
        crh = new CloseMetaHandler(this, this, hri, abort);
    } else {
        crh = new CloseRegionHandler(this, this, hri, abort, sn);
    }
    this.service.submit(crh);
    return true;
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) CloseRegionHandler(org.apache.hadoop.hbase.regionserver.handler.CloseRegionHandler) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) CloseMetaHandler(org.apache.hadoop.hbase.regionserver.handler.CloseMetaHandler) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Aggregations

IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)1 NotServingRegionException (org.apache.hadoop.hbase.NotServingRegionException)1 CloseMetaHandler (org.apache.hadoop.hbase.regionserver.handler.CloseMetaHandler)1 CloseRegionHandler (org.apache.hadoop.hbase.regionserver.handler.CloseRegionHandler)1