Package org.apache.hadoop.hbase.client
Class CatalogReplicaLoadBalanceSimpleSelector
java.lang.Object
org.apache.hadoop.hbase.client.CatalogReplicaLoadBalanceSimpleSelector
- All Implemented Interfaces:
- CatalogReplicaLoadBalanceSelector,- Stoppable
class CatalogReplicaLoadBalanceSimpleSelector
extends Object
implements CatalogReplicaLoadBalanceSelector, Stoppable
CatalogReplicaLoadBalanceReplicaSimpleSelector implements a simple catalog replica load balancing algorithm. It maintains a stale location cache for each table. Whenever client looks up location, it first check if the row is the stale location cache. If yes, the location from catalog replica is stale, it will go to the primary region to look up update-to-date location; otherwise, it will randomly pick up a replica region or primary region for lookup. When clients receive RegionNotServedException from region servers, it will add these region locations to the stale location cache. The stale cache will be cleaned up periodically by a chore.
It follows a simple algorithm to choose a meta replica region (including primary meta) to go:- If there is no stale location entry for rows it looks up, it will randomly pick a meta replica region (including primary meta) to do lookup.
- If the location from the replica region is stale, client gets RegionNotServedException from region server, in this case, it will create StaleLocationCacheEntry in CatalogReplicaLoadBalanceReplicaSimpleSelector.
- When client tries to do location lookup, it checks StaleLocationCache first for rows it tries to lookup, if entry exists, it will go with primary meta region to do lookup; otherwise, it will follow step 1.
- A chore will periodically run to clean up cache entries in the StaleLocationCache.
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprivate static final classStaleLocationCacheEntry is the entry when a stale location is reported by an client.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate final ChoreServiceprivate final IntSupplierprivate booleanprivate static final org.slf4j.Loggerprivate intprivate final intprivate final intprivate final longprivate final ConcurrentMap<TableName,ConcurrentNavigableMap<byte[], CatalogReplicaLoadBalanceSimpleSelector.StaleLocationCacheEntry>> private final TableNameFields inherited from interface org.apache.hadoop.hbase.client.CatalogReplicaLoadBalanceSelectorUNINITIALIZED_NUM_OF_REPLICAS
- 
Constructor SummaryConstructorsConstructorDescriptionCatalogReplicaLoadBalanceSimpleSelector(TableName tableName, ChoreService choreService, IntSupplier getNumOfReplicas) 
- 
Method SummaryModifier and TypeMethodDescriptionprivate voidprivate ScheduledChoreprivate intSelect an random replica id (including the primary replica id).private ScheduledChorebooleanReturns True ifStoppable.stop(String)has been closed.voidonError(HRegionLocation loc) When a client runs into RegionNotServingException, it will call this method to update Selector's internal state.private intintselect(TableName tableName, byte[] row, RegionLocateType locateType) When it looks up a location, it will call this method to find a replica region to go.voidStop this service.
- 
Field Details- 
LOG
- 
STALE_CACHE_TIMEOUT_IN_MILLISECONDS- See Also:
 
- 
STALE_CACHE_CLEAN_CHORE_INTERVAL_IN_MILLISECONDS- See Also:
 
- 
REFRESH_REPLICA_COUNT_CHORE_INTERVAL_IN_MILLISECONDS- See Also:
 
- 
staleCache
- 
numOfReplicas
- 
choreService
- 
tableName
- 
getNumOfReplicas
- 
isStopped
 
- 
- 
Constructor Details- 
CatalogReplicaLoadBalanceSimpleSelectorCatalogReplicaLoadBalanceSimpleSelector(TableName tableName, ChoreService choreService, IntSupplier getNumOfReplicas) 
 
- 
- 
Method Details- 
onErrorWhen a client runs into RegionNotServingException, it will call this method to update Selector's internal state.- Specified by:
- onErrorin interface- CatalogReplicaLoadBalanceSelector
- Parameters:
- loc- the location which causes exception.
 
- 
getRandomReplicaIdSelect an random replica id (including the primary replica id). In case there is no replica region configured, return the primary replica id.- Returns:
- Replica id
 
- 
selectWhen it looks up a location, it will call this method to find a replica region to go. For a normal case, > 99% of region locations from catalog/meta replica will be up to date. In extreme cases such as region server crashes, it will depends on how fast replication catches up.- Specified by:
- selectin interface- CatalogReplicaLoadBalanceSelector
- Parameters:
- tableName- table name it looks up
- row- key it looks up.
- locateType- locateType, Only BEFORE and CURRENT will be passed in.
- Returns:
- catalog replica id
 
- 
stopDescription copied from interface:StoppableStop this service. Implementers should favor logging errors over throwing RuntimeExceptions.
- 
isStoppedDescription copied from interface:StoppableReturns True ifStoppable.stop(String)has been closed.
- 
cleanupReplicaReplicaStaleCache
- 
refreshCatalogReplicaCount
- 
getCacheCleanupChore
- 
getRefreshReplicaCountChoreprivate ScheduledChore getRefreshReplicaCountChore(CatalogReplicaLoadBalanceSimpleSelector selector) 
 
-