HBASE-23155 May NPE when concurrent AsyncNonMetaRegionLocator#updateCachedLocationOnError (#718)

This commit is contained in:
Guanghao Zhang 2019-10-15 11:16:43 +08:00 committed by GitHub
parent 6aec958d66
commit 7924ba39e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -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;

View File

@ -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()));
}
}