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

Class StateStoreDriver

java.lang.Object
org.apache.hadoop.hdfs.server.federation.store.driver.StateStoreDriver
All Implemented Interfaces:
org.apache.hadoop.hdfs.server.federation.store.driver.StateStoreRecordOperations
Direct Known Subclasses:
StateStoreBaseImpl

@Public @Evolving public abstract class StateStoreDriver extends Object implements org.apache.hadoop.hdfs.server.federation.store.driver.StateStoreRecordOperations
Driver class for an implementation of a StateStoreService provider. Driver implementations will extend this class and implement some of the default methods.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Close the State Store driver connection.
    protected Configuration
    Get the State Store configuration.
    Gets a unique identifier for the running task/process.
    org.apache.hadoop.hdfs.server.federation.metrics.StateStoreMetrics
    Get the metrics for the State Store.
    long
    Returns the current time synchronization from the underlying store.
    <R extends org.apache.hadoop.hdfs.server.federation.store.records.BaseRecord>
    List<R>
    handleOverwriteAndDelete(List<R> commitRecords, List<R> deleteRecords)
    Try to overwrite records in commitRecords and remove records in deleteRecords.
    boolean
    init(Configuration config, String id, Collection<Class<? extends org.apache.hadoop.hdfs.server.federation.store.records.BaseRecord>> records, org.apache.hadoop.hdfs.server.federation.metrics.StateStoreMetrics stateStoreMetrics)
    Initialize the state store connection.
    abstract boolean
    Prepare the driver to access data storage.
    abstract <T extends org.apache.hadoop.hdfs.server.federation.store.records.BaseRecord>
    boolean
    initRecordStorage(String className, Class<T> clazz)
    Initialize storage for a single record class.
    abstract boolean
    Check if the driver is currently running and the data store connection is valid.
    void
    Check if the driver is ready to be used and throw an exception otherwise.

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface org.apache.hadoop.hdfs.server.federation.store.driver.StateStoreRecordOperations

    get, get, getMultiple, put, putAll, remove, remove, remove, removeAll, removeMultiple
  • Constructor Details

    • StateStoreDriver

      public StateStoreDriver()
  • Method Details

    • init

      public boolean init(Configuration config, String id, Collection<Class<? extends org.apache.hadoop.hdfs.server.federation.store.records.BaseRecord>> records, org.apache.hadoop.hdfs.server.federation.metrics.StateStoreMetrics stateStoreMetrics)
      Initialize the state store connection.
      Parameters:
      config - Configuration for the driver.
      id - Identifier for the driver.
      records - Records that are supported.
      stateStoreMetrics - State store metrics.
      Returns:
      If initialized and ready, false if failed to initialize driver.
    • getConf

      protected Configuration getConf()
      Get the State Store configuration.
      Returns:
      Configuration for the State Store.
    • getIdentifier

      public String getIdentifier()
      Gets a unique identifier for the running task/process. Typically, the router address.
      Returns:
      Unique identifier for the running task.
    • getMetrics

      public org.apache.hadoop.hdfs.server.federation.metrics.StateStoreMetrics getMetrics()
      Get the metrics for the State Store.
      Returns:
      State Store metrics.
    • initDriver

      public abstract boolean initDriver()
      Prepare the driver to access data storage.
      Returns:
      True if the driver was successfully initialized. If false is returned, the state store will periodically attempt to re-initialize the driver and the router will remain in safe mode until the driver is initialized.
    • initRecordStorage

      public abstract <T extends org.apache.hadoop.hdfs.server.federation.store.records.BaseRecord> boolean initRecordStorage(String className, Class<T> clazz)
      Initialize storage for a single record class.
      Type Parameters:
      T - Type of the state store record.
      Parameters:
      className - String reference of the record class to initialize, used to construct paths and file names for the record. Determined by configuration settings for the specific driver.
      clazz - Record type corresponding to the provided name.
      Returns:
      True if successful, false otherwise.
    • isDriverReady

      public abstract boolean isDriverReady()
      Check if the driver is currently running and the data store connection is valid.
      Returns:
      True if the driver is initialized and the data store is ready.
    • verifyDriverReady

      public void verifyDriverReady() throws org.apache.hadoop.hdfs.server.federation.store.StateStoreUnavailableException
      Check if the driver is ready to be used and throw an exception otherwise.
      Throws:
      org.apache.hadoop.hdfs.server.federation.store.StateStoreUnavailableException - If the driver is not ready.
    • close

      public void close() throws Exception
      Close the State Store driver connection.
      Throws:
      Exception - if something goes wrong while closing the state store driver connection.
    • getTime

      public long getTime()
      Returns the current time synchronization from the underlying store. Override for stores that supply a current date. The data store driver is responsible for maintaining the official synchronization time/date for all distributed components.
      Returns:
      Current time stamp, used for all synchronization dates.
    • handleOverwriteAndDelete

      public <R extends org.apache.hadoop.hdfs.server.federation.store.records.BaseRecord> List<R> handleOverwriteAndDelete(List<R> commitRecords, List<R> deleteRecords) throws IOException
      Try to overwrite records in commitRecords and remove records in deleteRecords. Should return null if async mode is used. Else return removed records.
      Type Parameters:
      R - record class
      Parameters:
      commitRecords - records to overwrite in state store
      deleteRecords - records to remove from state store
      Returns:
      null if async mode is used, else removed records
      Throws:
      IOException - when there is a failure during overwriting or deletion