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:Modifier and Type | Class and Description |
---|---|
private static class |
CatalogReplicaLoadBalanceSimpleSelector.StaleLocationCacheEntry
StaleLocationCacheEntry is the entry when a stale location is reported by an client.
|
Modifier and Type | Field and Description |
---|---|
private ChoreService |
choreService |
private IntSupplier |
getNumOfReplicas |
private boolean |
isStopped |
private static org.slf4j.Logger |
LOG |
private int |
numOfReplicas |
private int |
REFRESH_REPLICA_COUNT_CHORE_INTERVAL_IN_MILLISECONDS |
private int |
STALE_CACHE_CLEAN_CHORE_INTERVAL_IN_MILLISECONDS |
private long |
STALE_CACHE_TIMEOUT_IN_MILLISECONDS |
private ConcurrentMap<TableName,ConcurrentNavigableMap<byte[],CatalogReplicaLoadBalanceSimpleSelector.StaleLocationCacheEntry>> |
staleCache |
private TableName |
tableName |
UNINITIALIZED_NUM_OF_REPLICAS
Constructor and Description |
---|
CatalogReplicaLoadBalanceSimpleSelector(TableName tableName,
ChoreService choreService,
IntSupplier getNumOfReplicas) |
Modifier and Type | Method and Description |
---|---|
private void |
cleanupReplicaReplicaStaleCache() |
private ScheduledChore |
getCacheCleanupChore(CatalogReplicaLoadBalanceSimpleSelector selector) |
private int |
getRandomReplicaId()
Select an random replica id (including the primary replica id).
|
private ScheduledChore |
getRefreshReplicaCountChore(CatalogReplicaLoadBalanceSimpleSelector selector) |
boolean |
isStopped()
Returns True if
Stoppable.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 |
refreshCatalogReplicaCount() |
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(String why)
Stop this service.
|
private static final org.slf4j.Logger LOG
private final long STALE_CACHE_TIMEOUT_IN_MILLISECONDS
private final int STALE_CACHE_CLEAN_CHORE_INTERVAL_IN_MILLISECONDS
private final int REFRESH_REPLICA_COUNT_CHORE_INTERVAL_IN_MILLISECONDS
private final ConcurrentMap<TableName,ConcurrentNavigableMap<byte[],CatalogReplicaLoadBalanceSimpleSelector.StaleLocationCacheEntry>> staleCache
private volatile int numOfReplicas
private final ChoreService choreService
private final IntSupplier getNumOfReplicas
private volatile boolean isStopped
CatalogReplicaLoadBalanceSimpleSelector(TableName tableName, ChoreService choreService, IntSupplier getNumOfReplicas)
public void onError(HRegionLocation loc)
onError
in interface CatalogReplicaLoadBalanceSelector
loc
- the location which causes exception.private int getRandomReplicaId()
public int select(TableName tableName, byte[] row, RegionLocateType locateType)
select
in interface CatalogReplicaLoadBalanceSelector
tableName
- table name it looks uprow
- key it looks up.locateType
- locateType, Only BEFORE and CURRENT will be passed in.public void stop(String why)
Stoppable
public boolean isStopped()
Stoppable
Stoppable.stop(String)
has been closed.private void cleanupReplicaReplicaStaleCache()
private int refreshCatalogReplicaCount()
private ScheduledChore getCacheCleanupChore(CatalogReplicaLoadBalanceSimpleSelector selector)
private ScheduledChore getRefreshReplicaCountChore(CatalogReplicaLoadBalanceSimpleSelector selector)
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.