private void startBulkRegionOperation(boolean writeLockNeeded) throws IOException {
    if (this.closing.get()) {
      throw new NotServingRegionException(getRegionInfo().getRegionNameAsString() + " is closing");
    }
    if (writeLockNeeded) lock(lock.writeLock());
    else lock(lock.readLock());
    if (this.closed.get()) {
      if (writeLockNeeded) lock.writeLock().unlock();
      else lock.readLock().unlock();
      throw new NotServingRegionException(getRegionInfo().getRegionNameAsString() + " is closed");
    }
    regionLockHolders.put(Thread.currentThread(), true);
  }
This method needs to be called before any public call that reads or modifies stores in bulk. It
has to be called just before a try. #closeBulkRegionOperation needs to be called in the try's
finally block Acquires a writelock and checks if the region is closing or closed.
@throws NotServingRegionException when the region is closing or closed
@throws RegionTooBusyException    if failed to get the lock in time
@throws InterruptedIOException    if interrupted while waiting for a lock
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java