StateStoreService (Apache Hadoop HDFS-RBF 3.5.0 API)
Description: declaration: package: org.apache.hadoop.hdfs.server.federation.store, class: StateStoreService

Package org.apache.hadoop.hdfs.server.federation.store

# Class StateStoreService

java.lang.Object
org.apache.hadoop.service.AbstractService
org.apache.hadoop.service.CompositeService
org.apache.hadoop.hdfs.server.federation.store.StateStoreService

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`, `org.apache.hadoop.service.Service`

@Private @Evolving public class StateStoreService extends org.apache.hadoop.service.CompositeService
A service to initialize a `StateStoreDriver` and maintain the connection to the data store. There are multiple state store driver connections supported:

- File `StateStoreFileImpl`
- FileSystem `StateStoreFileSystemImpl`
- MySQL `StateStoreMySQLImpl`
- ZooKeeper `StateStoreZooKeeperImpl`

The service also supports the dynamic registration of record stores like:

- `MembershipStore`: state of the Namenodes in the federation.
- `MountTableStore`: Mount table between to subclusters. See `ViewFs`.
- `RouterStore`: Router state in the federation.
- `DisabledNameserviceStore`: Disabled name services.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class org.apache.hadoop.service.CompositeService

  `org.apache.hadoop.service.CompositeService.CompositeServiceShutdownHook`

  ## Nested classes/interfaces inherited from interface org.apache.hadoop.service.Service

  `org.apache.hadoop.service.Service.STATE`

- ## Field Summary

  ### Fields inherited from class org.apache.hadoop.service.CompositeService

  `STOP_ONLY_STARTED_SERVICES`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `StateStoreService()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `closeDriver()`
  Manually shuts down the driver.
  `long`
  `getCacheUpdateTime()`
  The last time the state store cache was fully updated.
  `StateStoreDriver`
  `getDriver()`
  Get the state store driver.
  `String`
  `getIdentifier()`
  Fetch a unique identifier for this state store instance.
  `StateStoreMetrics`
  `getMetrics()`
  Get the metrics for the State Store.
  `<T extends RecordStore<? extends BaseRecord>>
  List<T>`
  `getRecordStores()`
  Get the list of all RecordStores.
  `<T extends RecordStore<?>>
  T`
  `getRegisteredRecordStore(Class<T> recordStoreClass)`
  Get the record store in this State Store for a given interface.
  `Collection<Class<? extends BaseRecord>>`
  `getSupportedRecords()`
  List of records supported by this State Store.
  `boolean`
  `isDriverReady()`
  Check if the driver is ready to be used.
  `boolean`
  `loadCache(Class<?> clazz)`
  Update the cache for a specific record store.
  `boolean`
  `loadCache(Class<?> clazz, boolean force)`
  Update the cache for a specific record store.
  `void`
  `loadDriver()`
  Load the State Store driver.
  `void`
  `refreshCaches()`
  Refresh the cache with information from the State Store.
  `void`
  `refreshCaches(boolean force)`
  Refresh the cache with information from the State Store.
  `void`
  `registerCacheExternal(StateStoreCache client)`
  Register a cached record store for automatic periodic cache updates.
  `protected void`
  `serviceInit(org.apache.hadoop.conf.Configuration config)`
  Initialize the State Store and the connection to the back-end.
  `protected void`
  `serviceStart()`
  `protected void`
  `serviceStop()`
  `void`
  `setIdentifier(String id)`
  Set a unique synchronization identifier for this store.
  `void`
  `stopCacheUpdateService()`
  Stops the cache update service.

  ### Methods inherited from class org.apache.hadoop.service.CompositeService

  `addIfService, addService, getServices, removeService`

  ### Methods inherited from class org.apache.hadoop.service.AbstractService

  `close, getBlockers, getConfig, getFailureCause, getFailureState, getLifecycleHistory, getName, getServiceState, getStartTime, init, isInState, noteFailure, putBlocker, registerGlobalListener, registerServiceListener, removeBlocker, setConfig, start, stop, toString, unregisterGlobalListener, unregisterServiceListener, waitForServiceToStop`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### StateStoreService

    public StateStoreService()

- ## Method Details

  - ### serviceInit

    protected void serviceInit(org.apache.hadoop.conf.Configuration config) throws Exception
    Initialize the State Store and the connection to the back-end.
    Overrides:
      `serviceInit` in class `org.apache.hadoop.service.CompositeService`
    Parameters:
      `config` - Configuration for the State Store.
    Throws:
      `Exception` - Cannot create driver for the State Store.

  - ### serviceStart

    protected void serviceStart() throws Exception
    Overrides:
      `serviceStart` in class `org.apache.hadoop.service.CompositeService`
    Throws:
      `Exception`

  - ### serviceStop

    protected void serviceStop() throws Exception
    Overrides:
      `serviceStop` in class `org.apache.hadoop.service.CompositeService`
    Throws:
      `Exception`

  - ### getRegisteredRecordStore

    public <T extends RecordStore<?>> T getRegisteredRecordStore(Class<T> recordStoreClass)
    Get the record store in this State Store for a given interface.
    Type Parameters:
      `T` - The type of the record store.
    Parameters:
      `recordStoreClass` - Class of the record store.
    Returns:
      Registered record store or null if not found.

  - ### getRecordStores

    public <T extends RecordStore<? extends BaseRecord>> List<T> getRecordStores()
    Get the list of all RecordStores.
    Type Parameters:
      `T` - The type of the record stores that are returned.
    Returns:
      a list of each RecordStore.

  - ### getSupportedRecords

    public Collection<Class<? extends BaseRecord>> getSupportedRecords()
    List of records supported by this State Store.
    Returns:
      List of supported record classes.

  - ### loadDriver

    public void loadDriver()
    Load the State Store driver. If successful, refresh cached data tables.

  - ### isDriverReady

    public boolean isDriverReady()
    Check if the driver is ready to be used.
    Returns:
      If the driver is ready.

  - ### closeDriver

    @VisibleForTesting public void closeDriver() throws Exception
    Manually shuts down the driver.
    Throws:
      `Exception` - If the driver cannot be closed.

  - ### getDriver

    public StateStoreDriver getDriver()
    Get the state store driver.
    Returns:
      State store driver.

  - ### getIdentifier

    public String getIdentifier()
    Fetch a unique identifier for this state store instance. Typically, it is the address of the router.
    Returns:
      Unique identifier for this store.

  - ### setIdentifier

    public void setIdentifier(String id)
    Set a unique synchronization identifier for this store.
    Parameters:
      `id` - Unique identifier, typically the router's RPC address.

  - ### getCacheUpdateTime

    public long getCacheUpdateTime()
    The last time the state store cache was fully updated.
    Returns:
      Timestamp.

  - ### stopCacheUpdateService

    @VisibleForTesting public void stopCacheUpdateService()
    Stops the cache update service.

  - ### registerCacheExternal

    public void registerCacheExternal(StateStoreCache client)
    Register a cached record store for automatic periodic cache updates.
    Parameters:
      `client` - Client to the state store.

  - ### refreshCaches

    public void refreshCaches()
    Refresh the cache with information from the State Store. Called periodically by the CacheUpdateService to maintain data caches and versions.

  - ### refreshCaches

    public void refreshCaches(boolean force)
    Refresh the cache with information from the State Store. Called periodically by the CacheUpdateService to maintain data caches and versions.
    Parameters:
      `force` - If we force the refresh.

  - ### loadCache

    public boolean loadCache(Class<?> clazz) throws IOException
    Update the cache for a specific record store.
    Parameters:
      `clazz` - Class of the record store.
    Returns:
      If the cached was loaded.
    Throws:
      `IOException` - if the cache update failed.

  - ### loadCache

    public boolean loadCache(Class<?> clazz, boolean force) throws IOException
    Update the cache for a specific record store.
    Parameters:
      `clazz` - Class of the record store.
      `force` - Force the update ignoring cached periods.
    Returns:
      If the cached was loaded.
    Throws:
      `IOException` - if the cache update failed.

  - ### getMetrics

    public StateStoreMetrics getMetrics()
    Get the metrics for the State Store.
    Returns:
      State Store metrics.