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 Summary
Modifier and TypeClassDescriptionprivate static final class
StaleLocationCacheEntry is the entry when a stale location is reported by an client. -
Field Summary
Modifier and TypeFieldDescriptionprivate final AsyncConnectionImpl
private final IntSupplier
private boolean
private static final org.slf4j.Logger
private int
private final int
private final int
private final long
private final ConcurrentMap<TableName,
ConcurrentNavigableMap<byte[], CatalogReplicaLoadBalanceSimpleSelector.StaleLocationCacheEntry>> private final TableName
Fields inherited from interface org.apache.hadoop.hbase.client.CatalogReplicaLoadBalanceSelector
UNINITIALIZED_NUM_OF_REPLICAS
-
Constructor Summary
ConstructorDescriptionCatalogReplicaLoadBalanceSimpleSelector
(TableName tableName, AsyncConnectionImpl conn, IntSupplier getNumOfReplicas) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private ScheduledChore
private int
Select an random replica id (including the primary replica id).private ScheduledChore
boolean
Returns True ifStoppable.stop(String)
has been closed.void
onError
(HRegionLocation loc) When a client runs into RegionNotServingException, it will call this method to update Selector's internal state.private int
int
select
(TableName tableName, byte[] row, RegionLocateType locateType) When it looks up a location, it will call this method to find a replica region to go.void
Stop 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
-
conn
-
tableName
-
getNumOfReplicas
-
isStopped
-
-
Constructor Details
-
CatalogReplicaLoadBalanceSimpleSelector
CatalogReplicaLoadBalanceSimpleSelector(TableName tableName, AsyncConnectionImpl conn, IntSupplier getNumOfReplicas)
-
-
Method Details
-
onError
When a client runs into RegionNotServingException, it will call this method to update Selector's internal state.- Specified by:
onError
in interfaceCatalogReplicaLoadBalanceSelector
- Parameters:
loc
- the location which causes exception.
-
getRandomReplicaId
Select 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
-
select
When 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:
select
in interfaceCatalogReplicaLoadBalanceSelector
- Parameters:
tableName
- table name it looks uprow
- key it looks up.locateType
- locateType, Only BEFORE and CURRENT will be passed in.- Returns:
- catalog replica id
-
stop
Description copied from interface:Stoppable
Stop this service. Implementers should favor logging errors over throwing RuntimeExceptions. -
isStopped
Description copied from interface:Stoppable
Returns True ifStoppable.stop(String)
has been closed. -
cleanupReplicaReplicaStaleCache
-
refreshCatalogReplicaCount
-
getCacheCleanupChore
-
getRefreshReplicaCountChore
private ScheduledChore getRefreshReplicaCountChore(CatalogReplicaLoadBalanceSimpleSelector selector)
-