static void updateCachedLocationOnError(HRegionLocation loc, Throwable exception,
    Function<HRegionLocation, HRegionLocation> cachedLocationSupplier,
    Consumer<HRegionLocation> addToCache, Consumer<HRegionLocation> removeFromCache,
    MetricsConnection metrics) {
    HRegionLocation oldLoc = cachedLocationSupplier.apply(loc);
    if (LOG.isDebugEnabled()) {
      LOG.debug("Try updating {} , the old value is {}, error={}", loc, oldLoc,
        exception != null ? exception.toString() : "none");
    }
    if (!canUpdateOnError(loc, oldLoc)) {
      return;
    }
    Throwable cause = findException(exception);
    if (LOG.isDebugEnabled()) {
      LOG.debug("The actual exception when updating {} is {}", loc,
        cause != null ? cause.toString() : "none");
    }
    if (cause == null || !isMetaClearingException(cause)) {
      LOG.debug("Will not update {} because the exception is null or not the one we care about",
        loc);
      return;
    }
    if (cause instanceof RegionMovedException) {
      RegionMovedException rme = (RegionMovedException) cause;
      HRegionLocation newLoc =
        new HRegionLocation(loc.getRegion(), rme.getServerName(), rme.getLocationSeqNum());
      LOG.debug("Try updating {} with the new location {} constructed by {}", loc, newLoc,
        rme.toString());
      addToCache.accept(newLoc);
    } else {
      LOG.debug("Try removing {} from cache", loc);
      if (metrics != null) {
        metrics.incrCacheDroppingExceptions(exception);
      }
      removeFromCache.accept(loc);
    }
  }
Helper class for asynchronous region locator.
hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegionLocatorHelper.java