Skip to content

Commit 7924ba3

Browse files
authored
HBASE-23155 May NPE when concurrent AsyncNonMetaRegionLocator#updateCachedLocationOnError (#718)
1 parent 6aec958 commit 7924ba3

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,9 @@ private void removeLocationFromCache(HRegionLocation loc) {
570570
byte[] startKey = loc.getRegion().getStartKey();
571571
for (;;) {
572572
RegionLocations oldLocs = tableCache.cache.get(startKey);
573+
if (oldLocs == null) {
574+
return;
575+
}
573576
HRegionLocation oldLoc = oldLocs.getRegionLocation(loc.getRegion().getReplicaId());
574577
if (!canUpdateOnError(loc, oldLoc)) {
575578
return;

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncNonMetaRegionLocator.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,4 +399,14 @@ public void testLocateBeforeInOnlyRegion() throws IOException, InterruptedExcept
399399
assertArrayEquals(loc.getRegion().getStartKey(), EMPTY_START_ROW);
400400
assertArrayEquals(loc.getRegion().getEndKey(), EMPTY_END_ROW);
401401
}
402+
403+
@Test
404+
public void testConcurrentUpdateCachedLocationOnError() throws Exception {
405+
createSingleRegionTable();
406+
HRegionLocation loc =
407+
getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, false)
408+
.get();
409+
IntStream.range(0, 100).parallel()
410+
.forEach(i -> LOCATOR.updateCachedLocationOnError(loc, new NotServingRegionException()));
411+
}
402412
}

0 commit comments

Comments
 (0)