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

@Public @Evolving public abstract class StateStoreBaseImpl extends StateStoreDriver
Base implementation of a State Store driver. It contains default implementations for the optional functions. These implementations use an uncached read/write all algorithm for all changes. In most cases it is recommended to override the optional functions.

Drivers may optionally override additional routines for performance optimization, such as custom get/put/remove queries, depending on the capabilities of the data store.

  • Constructor Details

    • StateStoreBaseImpl

      public StateStoreBaseImpl()
  • Method Details

    • get

      public <T extends BaseRecord> T get(Class<T> clazz, Query<T> query) throws IOException
      Description copied from interface: StateStoreRecordOperations
      Get a single record from the store that matches the query.
      Type Parameters:
      T - Record class of the records.
      Parameters:
      clazz - Class of record to fetch.
      query - Query to filter results.
      Returns:
      A single record matching the query. Null if there are no matching records.
      Throws:
      IOException - If multiple records match or if the data store cannot be queried.
    • getMultiple

      public <T extends BaseRecord> List<T> getMultiple(Class<T> clazz, Query<T> query) throws IOException
      Description copied from interface: StateStoreRecordOperations
      Get multiple records from the store that match a query. This method assumes the underlying driver does not support filtering. If the driver supports filtering it should overwrite this method.
      Type Parameters:
      T - Record class of the records.
      Parameters:
      clazz - Class of record to fetch.
      query - Query to filter results.
      Returns:
      Records of type class that match the query or empty list if none are found.
      Throws:
      IOException - Throws exception if unable to query the data store.
    • put

      public <T extends BaseRecord> boolean put(T record, boolean allowUpdate, boolean errorIfExists) throws IOException
      Description copied from interface: StateStoreRecordOperations
      Creates a single record. Optionally updates an existing record with same primary key.
      Type Parameters:
      T - Record class of the records.
      Parameters:
      record - The record to insert or update.
      allowUpdate - True if update of exiting record is allowed.
      errorIfExists - True if an error should be returned when inserting an existing record. Only used if allowUpdate = false.
      Returns:
      True if the operation was successful.
      Throws:
      IOException - Throws exception if unable to query the data store.
    • remove

      public <T extends BaseRecord> boolean remove(T record) throws IOException
      Description copied from interface: StateStoreRecordOperations
      Remove a single record.
      Type Parameters:
      T - Record class of the records.
      Parameters:
      record - Record to be removed.
      Returns:
      true If the record was successfully removed. False if the record could not be removed or not stored.
      Throws:
      IOException - Throws exception if unable to query the data store.
    • removeMultiple

      public <T extends BaseRecord> Map<T,Boolean> removeMultiple(List<T> records) throws IOException
      Description copied from interface: StateStoreRecordOperations
      Remove multiple records.
      Type Parameters:
      T - Record class of the records.
      Parameters:
      records - Records to be removed.
      Returns:
      Map of record to a boolean indicating if the record has being removed successfully.
      Throws:
      IOException - Throws exception if unable to query the data store.
    • remove

      public <T extends BaseRecord> Map<Query<T>,Integer> remove(Class<T> clazz, List<Query<T>> queries) throws IOException
      Description copied from interface: StateStoreRecordOperations
      Remove all records of a specific class that match any query in a list of queries. Requires the getAll implementation to fetch fresh records on each call.
      Type Parameters:
      T - Record class of the records.
      Parameters:
      clazz - The class to match the records with.
      queries - Queries (logical OR) to filter what to remove.
      Returns:
      Map of query to number of records removed by that query.
      Throws:
      IOException - Throws exception if unable to query the data store.