final class AsyncRegionLocationCache extends Object
AsyncNonMetaRegionLocator
. Wrapper around
ConcurrentSkipListMap ensuring proper access to cached items. Updates are synchronized, but reads
are not.Modifier and Type | Field and Description |
---|---|
private ConcurrentNavigableMap<byte[],RegionLocations> |
cache |
private static org.slf4j.Logger |
LOG |
private TableName |
tableName |
Constructor and Description |
---|
AsyncRegionLocationCache(TableName tableName) |
Modifier and Type | Method and Description |
---|---|
RegionLocations |
add(RegionLocations locs)
Add the given locations to the cache, merging with existing if necessary.
|
private void |
cleanProblematicOverlappedRegions(RegionLocations locations)
When caching a location, the region may have been the result of a merge.
|
RegionLocations |
findForBeforeRow(byte[] row,
int replicaId)
Finds the RegionLocations for the region with the greatest startKey strictly less than the
given row
|
RegionLocations |
findForRow(byte[] row,
int replicaId)
Finds the RegionLocations for the region with the greatest startKey less than or equal to the
given row
|
RegionLocations |
get(byte[] startKey)
Gets the RegionLocations for a given region's startKey.
|
Collection<RegionLocations> |
getAll()
Returns all cached RegionLocations
|
private boolean |
isEqual(RegionLocations locs1,
RegionLocations locs2) |
boolean |
remove(HRegionLocation loc)
Removes the location from the cache if it exists and can be removed.
|
void |
removeForServer(ServerName serverName)
Removes serverName from all locations in the cache, fully removing any RegionLocations which
are empty after removing the server from it.
|
int |
size()
Returns the size of the region locations cache
|
private static final org.slf4j.Logger LOG
private final ConcurrentNavigableMap<byte[],RegionLocations> cache
public AsyncRegionLocationCache(TableName tableName)
public RegionLocations add(RegionLocations locs)
cleanProblematicOverlappedRegions(RegionLocations)
locs
- the locations to cacheprivate void cleanProblematicOverlappedRegions(RegionLocations locations)
For example, if we have Start_New < Start_Old < End_Old < End_New, then if we only access within range [End_Old, End_New], then it will always return the old region but it will then find out the row is not in the range, and try to get the new region, and then we get [Start_New, End_New), still fall into the same situation.
If Start_Old is less than Start_New, even if we have overlap, it is not a problem, as when the row is greater than Start_New, we will locate to the new region, and if the row is less than Start_New, it will fall into the old region's range and we will try to access the region and get a NotServing exception, and then we will clean the cache.
See HBASE-27650
locations
- the new location that was just cachedprivate boolean isEqual(RegionLocations locs1, RegionLocations locs2)
public Collection<RegionLocations> getAll()
public RegionLocations get(byte[] startKey)
startKey
- region start key to directly look uppublic RegionLocations findForRow(byte[] row, int replicaId)
row
- row to find locationspublic RegionLocations findForBeforeRow(byte[] row, int replicaId)
row
- row to find locationspublic boolean remove(HRegionLocation loc)
public int size()
public void removeForServer(ServerName serverName)
serverName
- server to remove from locationsCopyright © 2007–2020 The Apache Software Foundation. All rights reserved.