static void updateCachedLocationOnError(HRegionLocation loc, Throwable exception,
Function<HRegionLocation, HRegionLocation> cachedLocationSupplier,
Consumer<HRegionLocation> addToCache, Consumer<HRegionLocation> removeFromCache) {
HRegionLocation oldLoc = cachedLocationSupplier.apply(loc);
LOG.debug("Try updating {} , the old value is {}", loc, oldLoc, exception);
if (!canUpdateOnError(loc, oldLoc)) {
return;
}
Throwable cause = findException(exception);
LOG.debug("The actual exception when updating {}", loc, cause);
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);
addToCache.accept(newLoc);
} else {
LOG.debug("Try removing {} from cache", loc);
removeFromCache.accept(loc);
}
}