diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java index c8adc7947aa..0e102974b1e 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java @@ -570,6 +570,9 @@ class AsyncNonMetaRegionLocator { byte[] startKey = loc.getRegion().getStartKey(); for (;;) { RegionLocations oldLocs = tableCache.cache.get(startKey); + if (oldLocs == null) { + return; + } HRegionLocation oldLoc = oldLocs.getRegionLocation(loc.getRegion().getReplicaId()); if (!canUpdateOnError(loc, oldLoc)) { return; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncNonMetaRegionLocator.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncNonMetaRegionLocator.java index 042e0673e5c..6bc024ac121 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncNonMetaRegionLocator.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncNonMetaRegionLocator.java @@ -399,4 +399,14 @@ public class TestAsyncNonMetaRegionLocator { assertArrayEquals(loc.getRegion().getStartKey(), EMPTY_START_ROW); assertArrayEquals(loc.getRegion().getEndKey(), EMPTY_END_ROW); } + + @Test + public void testConcurrentUpdateCachedLocationOnError() throws Exception { + createSingleRegionTable(); + HRegionLocation loc = + getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, false) + .get(); + IntStream.range(0, 100).parallel() + .forEach(i -> LOCATOR.updateCachedLocationOnError(loc, new NotServingRegionException())); + } }