@Override
  public void process() throws IOException {
    MDC.put("pid", Long.toString(closeProcId));
    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);
    }
    // This should be true only in the case of splits/merges closing the parent regions, as
    // there's no point on keep blocks for those region files.
    final boolean evictCacheOnClose = isSplit
      ? server.getConfiguration().getBoolean(EVICT_BLOCKS_ON_SPLIT_KEY, DEFAULT_EVICT_ON_SPLIT)
      : server.getConfiguration().getBoolean(EVICT_BLOCKS_ON_CLOSE_KEY, DEFAULT_EVICT_ON_CLOSE);
    LOG.debug("Unassign region: split region: {}: evictCache: {}", isSplit, evictCacheOnClose);
    region.getStores().forEach(s -> s.getCacheConfig().setEvictOnClose(evictCacheOnClose));

    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(), initiatingMasterActiveTime))
    ) {
      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);
  }
Handles closing of a region on a region server.
<p/>
Just done the same thing with the old {@link CloseRegionHandler}, with some modifications on
fencing and retrying. But we need to keep the {@link CloseRegionHandler} as is to keep compatible
with the zk less assignment for 1.x, otherwise it is not possible to do rolling upgrade.
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/handler/UnassignRegionHandler.java