diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/RegionLocations.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/RegionLocations.java index f98bf03b792..e119ebbb2fc 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/RegionLocations.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/RegionLocations.java @@ -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 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 bbb84d04f3a..069a324fa94 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 @@ -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. diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegionLocatorHelper.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegionLocatorHelper.java index 2836e4b11e8..5f4bc9f999f 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegionLocatorHelper.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegionLocatorHelper.java @@ -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);