Skip to content

Commit

Permalink
HBASE-22236 AsyncNonMetaRegionLocator should not cache HRegionLocatio…
Browse files Browse the repository at this point in the history
…n with null location
  • Loading branch information
Apache9 committed Apr 20, 2019
1 parent 5b01e61 commit 353f922
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -185,6 +184,22 @@ public RegionLocations remove(int replicaId) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ private boolean onScanNext(TableName tableName, LocateRequest req, Result result
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ static void updateCachedLocationOnError(HRegionLocation loc, Throwable exception
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);
Expand Down

0 comments on commit 353f922

Please sign in to comment.