Skip to content

Commit 353f922

Browse files
committed
HBASE-22236 AsyncNonMetaRegionLocator should not cache HRegionLocation with null location
1 parent 5b01e61 commit 353f922

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎hbase-client/src/main/java/org/apache/hadoop/hbase/RegionLocations.java‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.hadoop.hbase;
2020

2121
import java.util.Collection;
22-
2322
import org.apache.hadoop.hbase.client.RegionInfo;
2423
import org.apache.hadoop.hbase.client.RegionReplicaUtil;
2524
import org.apache.hadoop.hbase.util.Bytes;
@@ -185,6 +184,22 @@ public RegionLocations remove(int replicaId) {
185184
return new RegionLocations(newLocations);
186185
}
187186

187+
/**
188+
* Set the element to null if its getServerName method returns null. Returns null if all the
189+
* elements are removed.
190+
*/
191+
public RegionLocations removeElementsWithNullLocation() {
192+
HRegionLocation[] newLocations = new HRegionLocation[locations.length];
193+
boolean hasNonNullElement = false;
194+
for (int i = 0; i < locations.length; i++) {
195+
if (locations[i] != null && locations[i].getServerName() != null) {
196+
hasNonNullElement = true;
197+
newLocations[i] = locations[i];
198+
}
199+
}
200+
return hasNonNullElement ? new RegionLocations(newLocations) : null;
201+
}
202+
188203
/**
189204
* Merges this RegionLocations list with the given list assuming
190205
* same range, and keeping the most up to date version of the

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ private boolean onScanNext(TableName tableName, LocateRequest req, Result result
314314
LOG.debug("The fetched location of '{}', row='{}', locateType={} is {}", tableName,
315315
Bytes.toStringBinary(req.row), req.locateType, locs);
316316
}
317+
// remove HRegionLocation with null location, i.e, getServerName returns null.
318+
if (locs != null) {
319+
locs = locs.removeElementsWithNullLocation();
320+
}
317321

318322
// the default region location should always be presented when fetching from meta, otherwise
319323
// let's fail the request.

‎hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegionLocatorHelper.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ static void updateCachedLocationOnError(HRegionLocation loc, Throwable exception
7676
RegionMovedException rme = (RegionMovedException) cause;
7777
HRegionLocation newLoc =
7878
new HRegionLocation(loc.getRegion(), rme.getServerName(), rme.getLocationSeqNum());
79-
LOG.debug("Try updating {} with the new location {} constructed by {}", loc, newLoc, rme);
79+
LOG.debug("Try updating {} with the new location {} constructed by {}", loc, newLoc,
80+
rme.toString());
8081
addToCache.accept(newLoc);
8182
} else {
8283
LOG.debug("Try removing {} from cache", loc);

0 commit comments

Comments
 (0)