Package org.apache.hadoop.hbase
Class RegionLocations
java.lang.Object
org.apache.hadoop.hbase.RegionLocations
- All Implemented Interfaces:
Iterable<HRegionLocation>
Container for holding a list of
HRegionLocation
's that correspond to the same range. The
list is indexed by the replicaId. This is an immutable list, however mutation operations are
provided which returns a new List via copy-on-write (assuming small number of locations)-
Field Summary
-
Constructor Summary
ConstructorDescriptionRegionLocations
(Collection<HRegionLocation> locations) RegionLocations
(HRegionLocation... locations) Constructs the region location list. -
Method Summary
Modifier and TypeMethodDescriptionReturns the first not-null region location in the listgetRegionLocation
(int replicaId) getRegionLocationByRegionName
(byte[] regionName) Returns the region location from the list for matching regionName, which can be regionName or encodedRegionNameboolean
isEmpty()
Returns whether there are non-null elements in the listprivate boolean
isGreaterThan
(long a, long b, boolean checkForEquals) iterator()
mergeLocations
(RegionLocations other) Merges this RegionLocations list with the given list assuming same range, and keeping the most up to date version of the HRegionLocation entries from either list according to seqNum.int
Returns the size of not-null locationsremove
(int replicaId) Removes location of the given replicaId from the listremove
(HRegionLocation location) Removes the given location from the listremoveByServer
(ServerName serverName) Returns a new RegionLocations with the locations removed (set to null) which have the destination server as given.Set the element to null if its getServerName method returns null.private HRegionLocation
selectRegionLocation
(HRegionLocation oldLocation, HRegionLocation location, boolean checkForEquals, boolean force) int
size()
Returns the size of the list even if some of the elements might be null.toString()
updateLocation
(HRegionLocation location, boolean checkForEquals, boolean force) Updates the location with new only if the new location has a higher seqNum than the old one or force is true.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
numNonNullElements
-
locations
-
-
Constructor Details
-
RegionLocations
Constructs the region location list. The locations array should contain all the locations for known replicas for the region, and should be sorted in replicaId ascending order, although it can contain nulls indicating replicaIds that the locations of which are not known.- Parameters:
locations
- an array of HRegionLocations for the same region range
-
RegionLocations
-
-
Method Details
-
size
Returns the size of the list even if some of the elements might be null.- Returns:
- the size of the list (corresponding to the max replicaId)
-
numNonNullElements
Returns the size of not-null locations- Returns:
- the size of not-null locations
-
isEmpty
Returns whether there are non-null elements in the list- Returns:
- whether there are non-null elements in the list
-
removeByServer
Returns a new RegionLocations with the locations removed (set to null) which have the destination server as given.- Parameters:
serverName
- the serverName to remove locations of- Returns:
- an RegionLocations object with removed locations or the same object if nothing is removed
-
remove
Removes the given location from the list- Parameters:
location
- the location to remove- Returns:
- an RegionLocations object with removed locations or the same object if nothing is removed
-
remove
Removes location of the given replicaId from the list- Parameters:
replicaId
- the replicaId of the location to remove- Returns:
- an RegionLocations object with removed locations or the same object if nothing is removed
-
removeElementsWithNullLocation
Set the element to null if its getServerName method returns null. Returns null if all the elements are removed. -
mergeLocations
Merges this RegionLocations list with the given list assuming same range, and keeping the most up to date version of the HRegionLocation entries from either list according to seqNum. If seqNums are equal, the location from the argument (other) is taken.- Parameters:
other
- the locations to merge with- Returns:
- an RegionLocations object with merged locations or the same object if nothing is merged
-
selectRegionLocation
private HRegionLocation selectRegionLocation(HRegionLocation oldLocation, HRegionLocation location, boolean checkForEquals, boolean force) -
updateLocation
public RegionLocations updateLocation(HRegionLocation location, boolean checkForEquals, boolean force) Updates the location with new only if the new location has a higher seqNum than the old one or force is true.- Parameters:
location
- the location to add or updatecheckForEquals
- whether to update the location if seqNums for the HRegionLocations for the old and new location are the sameforce
- whether to force update- Returns:
- an RegionLocations object with updated locations or the same object if nothing is updated
-
isGreaterThan
-
getRegionLocation
-
getRegionLocationByRegionName
Returns the region location from the list for matching regionName, which can be regionName or encodedRegionName- Parameters:
regionName
- regionName or encodedRegionName- Returns:
- HRegionLocation found or null
-
getRegionLocations
-
getDefaultRegionLocation
-
getRegionLocation
Returns the first not-null region location in the list -
iterator
- Specified by:
iterator
in interfaceIterable<HRegionLocation>
-
toString
-