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
-
Field Summary
Modifier and TypeFieldDescriptionprivate final CopyOnWriteArrayMap<Integer,
HRegionLocation> Cached meta region locations indexed by replica ID.private static final org.slf4j.Logger
private static final int
Maximum number of times we retry when ZK operation times out.private final RetryCounterFactory
private static final int
Sleep interval ms between ZK operation retries.private static final int
Fields inherited from class org.apache.hadoop.hbase.zookeeper.ZKListener
watcher
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate HRegionLocation
getMetaRegionLocation
(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 boolean
isValidMetaPath
(String path) Helper to check if the given 'path' corresponds to a meta znode.private void
loadMetaLocationsFromZk
(RetryCounter retryCounter, MetaRegionLocationCache.ZNodeOpType opType) Populates the current snapshot of meta locations from ZK.void
nodeChildrenChanged
(String path) Called when an existing node has a child node added or removed.void
nodeCreated
(String path) Called when a new node has been created.void
nodeDataChanged
(String path) Called when an existing node has changed data.void
nodeDeleted
(String path) Called when a node has been deletedprivate void
updateMetaLocation
(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:ZKListener
Called when a new node has been created.- Overrides:
nodeCreated
in classZKListener
- Parameters:
path
- full path of the new node
-
nodeDeleted
Description copied from class:ZKListener
Called when a node has been deleted- Overrides:
nodeDeleted
in classZKListener
- Parameters:
path
- full path of the deleted node
-
nodeDataChanged
Description copied from class:ZKListener
Called when an existing node has changed data.- Overrides:
nodeDataChanged
in classZKListener
- Parameters:
path
- full path of the updated node
-
nodeChildrenChanged
Description copied from class:ZKListener
Called when an existing node has a child node added or removed.- Overrides:
nodeChildrenChanged
in classZKListener
- Parameters:
path
- full path of the node whose children have changed
-