Class StateStoreZooKeeperImpl

All Implemented Interfaces:
StateStoreRecordOperations

public class StateStoreZooKeeperImpl extends StateStoreSerializableImpl
StateStoreDriver driver implementation that uses ZooKeeper as a backend.

The structure of the znodes in the ensemble is: PARENT_PATH |--- MOUNT |--- MEMBERSHIP |--- REBALANCER |--- ROUTERS |--- DISABLE_NAMESERVICE

  • Constructor Details

    • StateStoreZooKeeperImpl

      public StateStoreZooKeeperImpl()
  • Method Details

    • initDriver

      public boolean initDriver()
      Description copied from class: StateStoreDriver
      Prepare the driver to access data storage.
      Specified by:
      initDriver in class StateStoreDriver
      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 <T extends BaseRecord> boolean initRecordStorage(String className, Class<T> clazz)
      Description copied from class: StateStoreDriver
      Initialize storage for a single record class.
      Specified by:
      initRecordStorage in class StateStoreDriver
      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.
    • setEnableConcurrent

      @VisibleForTesting public void setEnableConcurrent(boolean enableConcurrent)
    • close

      public void close() throws Exception
      Description copied from class: StateStoreDriver
      Close the State Store driver connection.
      Overrides:
      close in class StateStoreDriver
      Throws:
      Exception - if something goes wrong while closing the state store driver connection.
    • isDriverReady

      public boolean isDriverReady()
      Description copied from class: StateStoreDriver
      Check if the driver is currently running and the data store connection is valid.
      Specified by:
      isDriverReady in class StateStoreDriver
      Returns:
      True if the driver is initialized and the data store is ready.
    • get

      public <T extends BaseRecord> QueryResult<T> get(Class<T> clazz) throws IOException
      Description copied from interface: StateStoreRecordOperations
      Get all records of the requested record class from the data store. To use the default implementations in this class, getAll must return new instances of the records on each call. It is recommended to override the default implementations for better performance.
      Type Parameters:
      T - Record class of the records.
      Parameters:
      clazz - Class of record to fetch.
      Returns:
      List of all records that match the class.
      Throws:
      IOException - Throws exception if unable to query the data store.
    • putAll

      public <T extends BaseRecord> StateStoreOperationResult putAll(List<T> records, boolean update, boolean error) throws IOException
      Description copied from interface: StateStoreRecordOperations
      Creates multiple records. Optionally updates existing records that have the same primary key.
      Type Parameters:
      T - Record class of the records.
      Parameters:
      records - List of data records to update or create. All records must be of class clazz.
      update - True if update of exiting record is allowed.
      error - True if an error should be returned when inserting an existing record. Only used if allowUpdate = false.
      Returns:
      The result of the putAll operation.
      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.
      Specified by:
      remove in interface StateStoreRecordOperations
      Overrides:
      remove in class StateStoreBaseImpl
      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.
    • remove

      public <T extends BaseRecord> int remove(Class<T> clazz, Query<T> query) throws IOException
      Description copied from interface: StateStoreRecordOperations
      Remove multiple records of a specific class that match a query. 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.
      query - Query to filter what to remove.
      Returns:
      The number of records removed.
      Throws:
      IOException - Throws exception if unable to query the data store.
    • removeAll

      public <T extends BaseRecord> boolean removeAll(Class<T> clazz) throws IOException
      Description copied from interface: StateStoreRecordOperations
      Remove all records of this class from the store.
      Type Parameters:
      T - Record class of the records.
      Parameters:
      clazz - Class of records to remove.
      Returns:
      True if successful.
      Throws:
      IOException - Throws exception if unable to query the data store.