Class StateBackendLoader

java.lang.Object
org.apache.flink.runtime.state.StateBackendLoader

public class StateBackendLoader extends Object
This class contains utility methods to load state backends from configurations.
  • Field Details

    • HASHMAP_STATE_BACKEND_NAME

      public static final String HASHMAP_STATE_BACKEND_NAME
      The shortcut configuration name of the HashMap state backend.
      See Also:
    • ROCKSDB_STATE_BACKEND_NAME

      public static final String ROCKSDB_STATE_BACKEND_NAME
      The shortcut configuration name for the RocksDB State Backend.
      See Also:
    • FORST_STATE_BACKEND_NAME

      public static final String FORST_STATE_BACKEND_NAME
      See Also:
  • Method Details

    • loadStateBackendFromConfig

      @Nonnull public static StateBackend loadStateBackendFromConfig(org.apache.flink.configuration.ReadableConfig config, ClassLoader classLoader, @Nullable org.slf4j.Logger logger) throws org.apache.flink.configuration.IllegalConfigurationException, org.apache.flink.util.DynamicCodeLoadingException, IOException
      Loads the unwrapped state backend from the configuration, from the parameter 'state.backend', as defined in StateBackendOptions.STATE_BACKEND.

      The state backends can be specified either via their shortcut name, or via the class name of a StateBackendFactory. If a StateBackendFactory class name is specified, the factory is instantiated (via its zero-argument constructor) and its StateBackendFactory.createFromConfig(ReadableConfig, ClassLoader) method is called.

      Recognized shortcut names are '"hashmap"', '"rocksdb"'

      Parameters:
      config - The configuration to load the state backend from
      classLoader - The class loader that should be used to load the state backend
      logger - Optionally, a logger to log actions to (may be null)
      Returns:
      The instantiated state backend.
      Throws:
      org.apache.flink.util.DynamicCodeLoadingException - Thrown if a state backend factory is configured and the factory class was not found or the factory could not be instantiated
      org.apache.flink.configuration.IllegalConfigurationException - May be thrown by the StateBackendFactory when creating / configuring the state backend in the factory
      IOException - May be thrown by the StateBackendFactory when instantiating the state backend
    • fromApplicationOrConfigOrDefault

      public static StateBackend fromApplicationOrConfigOrDefault(@Nullable StateBackend fromApplication, org.apache.flink.configuration.Configuration jobConfig, org.apache.flink.configuration.Configuration clusterConfig, ClassLoader classLoader, @Nullable org.slf4j.Logger logger) throws org.apache.flink.configuration.IllegalConfigurationException, org.apache.flink.util.DynamicCodeLoadingException, IOException
      This is the state backend loader that loads a DelegatingStateBackend wrapping the state backend loaded from loadFromApplicationOrConfigOrDefaultInternal(org.apache.flink.runtime.state.StateBackend, org.apache.flink.configuration.Configuration, org.apache.flink.configuration.Configuration, java.lang.ClassLoader, org.slf4j.Logger) when delegation is enabled. If delegation is not enabled, the underlying wrapped state backend is returned instead.
      Parameters:
      fromApplication - StateBackend defined from application
      jobConfig - The job level configuration to load the state backend from
      clusterConfig - The cluster level configuration to load the state backend from
      classLoader - The class loader that should be used to load the state backend
      logger - Optionally, a logger to log actions to (may be null)
      Returns:
      The instantiated state backend.
      Throws:
      org.apache.flink.util.DynamicCodeLoadingException - Thrown if a state backend (factory) is configured and the (factory) class was not found or could not be instantiated
      org.apache.flink.configuration.IllegalConfigurationException - May be thrown by the StateBackendFactory when creating / configuring the state backend in the factory
      IOException - May be thrown by the StateBackendFactory when instantiating the state backend
    • stateBackendFromApplicationOrConfigOrDefaultUseManagedMemory

      public static boolean stateBackendFromApplicationOrConfigOrDefaultUseManagedMemory(org.apache.flink.configuration.Configuration config, Optional<Boolean> stateBackendFromApplicationUsesManagedMemory, ClassLoader classLoader)
      Checks whether state backend uses managed memory, without having to deserialize or load the state backend.
      Parameters:
      config - configuration to load the state backend from.
      stateBackendFromApplicationUsesManagedMemory - Whether the application-defined backend uses Flink's managed memory. Empty if application has not defined a backend.
      classLoader - User code classloader.
      Returns:
      Whether the state backend uses managed memory.
    • loadStateBackendFromKeyedStateHandles

      public static StateBackend loadStateBackendFromKeyedStateHandles(StateBackend originalStateBackend, ClassLoader classLoader, Collection<KeyedStateHandle> keyedStateHandles) throws org.apache.flink.util.DynamicCodeLoadingException
      Load state backend which may wrap the original state backend for recovery.
      Parameters:
      originalStateBackend - StateBackend loaded from application or config.
      classLoader - User code classloader.
      keyedStateHandles - The state handles for restore.
      Returns:
      Wrapped state backend for recovery.
      Throws:
      org.apache.flink.util.DynamicCodeLoadingException - Thrown if keyed state handles of wrapped state backend are found and the class was not found or could not be instantiated.
    • isChangelogStateBackend

      public static boolean isChangelogStateBackend(StateBackend backend)