Package org.apache.hadoop.hbase
Class MetaRegionLocationCache
java.lang.Object
org.apache.hadoop.hbase.zookeeper.ZKListener
org.apache.hadoop.hbase.MetaRegionLocationCache
A cache of meta region location metadata. Registers a listener on ZK to track changes to the meta
table znodes. Clients are expected to retry if the meta information is stale. This class is
thread-safe (a single instance of this class can be shared by multiple threads without race
conditions).
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CopyOnWriteArrayMap<Integer,HRegionLocation> Cached meta region locations indexed by replica ID.private static final org.slf4j.Loggerprivate static final intMaximum number of times we retry when ZK operation times out.private final RetryCounterFactoryprivate static final intSleep interval ms between ZK operation retries.private static final intFields inherited from class org.apache.hadoop.hbase.zookeeper.ZKListener
watcher -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate HRegionLocationgetMetaRegionLocation(int replicaId) Gets the HRegionLocation for a given meta replica ID.Returns Optional list of HRegionLocations for meta replica(s), null if the cache is empty.private booleanisValidMetaPath(String path) Helper to check if the given 'path' corresponds to a meta znode.private voidloadMetaLocationsFromZk(RetryCounter retryCounter, MetaRegionLocationCache.ZNodeOpType opType) Populates the current snapshot of meta locations from ZK.voidnodeChildrenChanged(String path) Called when an existing node has a child node added or removed.voidnodeCreated(String path) Called when a new node has been created.voidnodeDataChanged(String path) Called when an existing node has changed data.voidnodeDeleted(String path) Called when a node has been deletedprivate voidupdateMetaLocation(String path, MetaRegionLocationCache.ZNodeOpType opType) Methods inherited from class org.apache.hadoop.hbase.zookeeper.ZKListener
getWatcher
-
Field Details
-
LOG
-
MAX_ZK_META_FETCH_RETRIES
Maximum number of times we retry when ZK operation times out.- See Also:
-
SLEEP_INTERVAL_MS_BETWEEN_RETRIES
Sleep interval ms between ZK operation retries.- See Also:
-
SLEEP_INTERVAL_MS_MAX
- See Also:
-
retryCounterFactory
-
cachedMetaLocations
Cached meta region locations indexed by replica ID. CopyOnWriteArrayMap ensures synchronization during updates and a consistent snapshot during client requests. Even though CopyOnWriteArrayMap copies the data structure for every write, that should be OK since the size of the list is often small and mutations are not too often and we do not need to block client requests while mutations are in progress.
-
-
Constructor Details
-
MetaRegionLocationCache
-
-
Method Details
-
loadMetaLocationsFromZk
private void loadMetaLocationsFromZk(RetryCounter retryCounter, MetaRegionLocationCache.ZNodeOpType opType) Populates the current snapshot of meta locations from ZK. If no meta znodes exist, it registers a watcher on base znode to check for any CREATE/DELETE events on the children.- Parameters:
retryCounter- controls the number of retries and sleep between retries.
-
getMetaRegionLocation
private HRegionLocation getMetaRegionLocation(int replicaId) throws org.apache.zookeeper.KeeperException Gets the HRegionLocation for a given meta replica ID. Renews the watch on the znode for future updates.- Parameters:
replicaId- ReplicaID of the region.- Returns:
- HRegionLocation for the meta replica.
- Throws:
org.apache.zookeeper.KeeperException- if there is any issue fetching/parsing the serialized data.
-
updateMetaLocation
-
getMetaRegionLocations
Returns Optional list of HRegionLocations for meta replica(s), null if the cache is empty. -
isValidMetaPath
Helper to check if the given 'path' corresponds to a meta znode. This listener is only interested in changes to meta znodes. -
nodeCreated
Description copied from class:ZKListenerCalled when a new node has been created.- Overrides:
nodeCreatedin classZKListener- Parameters:
path- full path of the new node
-
nodeDeleted
Description copied from class:ZKListenerCalled when a node has been deleted- Overrides:
nodeDeletedin classZKListener- Parameters:
path- full path of the deleted node
-
nodeDataChanged
Description copied from class:ZKListenerCalled when an existing node has changed data.- Overrides:
nodeDataChangedin classZKListener- Parameters:
path- full path of the updated node
-
nodeChildrenChanged
Description copied from class:ZKListenerCalled when an existing node has a child node added or removed.- Overrides:
nodeChildrenChangedin classZKListener- Parameters:
path- full path of the node whose children have changed
-