Package org.apache.hadoop.hbase.client
Class AsyncRegionLocationCache
java.lang.Object
org.apache.hadoop.hbase.client.AsyncRegionLocationCache
Cache of RegionLocations for use by
AsyncNonMetaRegionLocator
. Wrapper around
ConcurrentSkipListMap ensuring proper access to cached items. Updates are synchronized, but reads
are not.-
Field Summary
Modifier and TypeFieldDescriptionprivate final ConcurrentNavigableMap<byte[],
RegionLocations> private static final org.slf4j.Logger
private final TableName
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionadd
(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.findForBeforeRow
(byte[] row, int replicaId) Finds the RegionLocations for the region with the greatest startKey strictly less than the given rowfindForRow
(byte[] row, int replicaId) Finds the RegionLocations for the region with the greatest startKey less than or equal to the given rowget
(byte[] startKey) Gets the RegionLocations for a given region's startKey.getAll()
Returns all cached RegionLocationsprivate 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
-
Field Details
-
LOG
-
cache
-
tableName
-
-
Constructor Details
-
AsyncRegionLocationCache
-
-
Method Details
-
add
Add the given locations to the cache, merging with existing if necessary. Also cleans out any previously cached locations which may have been superseded by this one (i.e. in case of merged regions). SeecleanProblematicOverlappedRegions(RegionLocations)
- Parameters:
locs
- the locations to cache- Returns:
- the final location (possibly merged) that was added to the cache
-
cleanProblematicOverlappedRegions
When caching a location, the region may have been the result of a merge. Check to see if the region's boundaries overlap any other cached locations in a problematic way. Those would have been merge parents which no longer exist. We need to proactively clear them out to avoid a case where a merged region which receives no requests never gets cleared. This causes requests to other merged regions after it to see the wrong cached location.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
- Parameters:
locations
- the new location that was just cached
-
isEqual
-
getAll
Returns all cached RegionLocations -
get
Gets the RegionLocations for a given region's startKey. This is a direct lookup, if the key does not exist in the cache it will return null.- Parameters:
startKey
- region start key to directly look up
-
findForRow
Finds the RegionLocations for the region with the greatest startKey less than or equal to the given row- Parameters:
row
- row to find locations
-
findForBeforeRow
Finds the RegionLocations for the region with the greatest startKey strictly less than the given row- Parameters:
row
- row to find locations
-
remove
Removes the location from the cache if it exists and can be removed.- Returns:
- true if entry was removed
-
size
Returns the size of the region locations cache -
removeForServer
Removes serverName from all locations in the cache, fully removing any RegionLocations which are empty after removing the server from it.- Parameters:
serverName
- server to remove from locations
-