Package org.apache.hadoop.hbase.master
Class CachedClusterId
java.lang.Object
org.apache.hadoop.hbase.master.CachedClusterId
Caches the cluster ID of the cluster. For standby masters, this is used to serve the client RPCs
that fetch the cluster ID. ClusterID is only created by an active master if one does not already
exist. Standby masters just read the information from the file system. This class is thread-safe.
TODO: Make it a singleton without affecting concurrent junit tests.
-
Field Summary
Modifier and TypeFieldDescriptionprivate AtomicInteger
private ClusterId
(package private) AtomicBoolean
private final org.apache.hadoop.fs.FileSystem
private AtomicBoolean
static final org.slf4j.Logger
private static final int
private final org.apache.hadoop.fs.Path
private final Server
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
Attempts to fetch the cluster ID from the file system.int
private String
Returns a cached copy of the cluster ID.Fetches the ClusterId from FS if it is not cached locally.private void
Succeeds only once, when setting to a non-null value.private void
-
Field Details
-
LOG
-
MAX_FETCH_TIMEOUT_MS
- See Also:
-
rootDir
-
fs
-
fetchInProgress
-
isClusterIdSet
-
clusterId
-
server
-
cacheMisses
-
-
Constructor Details
-
CachedClusterId
- Throws:
IOException
-
-
Method Details
-
setClusterId
Succeeds only once, when setting to a non-null value. Overwrites are not allowed. -
getClusterId
Returns a cached copy of the cluster ID. null if the cache is not populated. -
attemptFetch
Attempts to fetch the cluster ID from the file system. If no attempt is already in progress, synchronously fetches the cluster ID and sets it. If an attempt is already in progress, returns right away and the caller is expected to wait for the fetch to finish.- Returns:
- true if the attempt is done, false if another thread is already fetching it.
-
waitForFetchToFinish
- Throws:
InterruptedException
-
getFromCacheOrFetch
Fetches the ClusterId from FS if it is not cached locally. Atomically updates the cached copy and is thread-safe. Optimized to do a single fetch when there are multiple threads are trying get from a clean cache.- Returns:
- ClusterId by reading from FileSystem or null in any error case or cluster ID does not exist on the file system or if the server initiated a tear down.
-
getCacheStats
-