HBASE-22236 AsyncNonMetaRegionLocator should not cache HRegionLocation with null location
This commit is contained in:
parent
5b01e613fb
commit
353f9226c3
|
@ -19,7 +19,6 @@
|
|||
package org.apache.hadoop.hbase;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.hadoop.hbase.client.RegionInfo;
|
||||
import org.apache.hadoop.hbase.client.RegionReplicaUtil;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
@ -185,6 +184,22 @@ public class RegionLocations {
|
|||
return new RegionLocations(newLocations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the element to null if its getServerName method returns null. Returns null if all the
|
||||
* elements are removed.
|
||||
*/
|
||||
public RegionLocations removeElementsWithNullLocation() {
|
||||
HRegionLocation[] newLocations = new HRegionLocation[locations.length];
|
||||
boolean hasNonNullElement = false;
|
||||
for (int i = 0; i < locations.length; i++) {
|
||||
if (locations[i] != null && locations[i].getServerName() != null) {
|
||||
hasNonNullElement = true;
|
||||
newLocations[i] = locations[i];
|
||||
}
|
||||
}
|
||||
return hasNonNullElement ? new RegionLocations(newLocations) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges this RegionLocations list with the given list assuming
|
||||
* same range, and keeping the most up to date version of the
|
||||
|
|
|
@ -314,6 +314,10 @@ class AsyncNonMetaRegionLocator {
|
|||
LOG.debug("The fetched location of '{}', row='{}', locateType={} is {}", tableName,
|
||||
Bytes.toStringBinary(req.row), req.locateType, locs);
|
||||
}
|
||||
// remove HRegionLocation with null location, i.e, getServerName returns null.
|
||||
if (locs != null) {
|
||||
locs = locs.removeElementsWithNullLocation();
|
||||
}
|
||||
|
||||
// the default region location should always be presented when fetching from meta, otherwise
|
||||
// let's fail the request.
|
||||
|
|
|
@ -76,7 +76,8 @@ final class AsyncRegionLocatorHelper {
|
|||
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);
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue