Class MemoryStateBackend

  • All Implemented Interfaces:
    Serializable, CheckpointStorage, ConfigurableStateBackend, StateBackend

    @Deprecated
    @PublicEvolving
    public class MemoryStateBackend
    extends AbstractFileStateBackend
    implements ConfigurableStateBackend
    Deprecated.
    IMPORTANT MemoryStateBackend is deprecated in favor of HashMapStateBackend and JobManagerCheckpointStorage. This change does not affect the runtime characteristics of your Jobs and is simply an API change to help better communicate the ways Flink separates local state storage from fault tolerance. Jobs can be upgraded without loss of state. If configuring your state backend via the StreamExecutionEnvironment please make the following changes.
    
     		StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
     		env.setStateBackend(new HashMapStateBackend());
     		env.getCheckpointConfig().setCheckpointStorage(new JobManagerCheckpointStorage());
     

    If you are configuring your state backend via the config.yaml please make the following changes:

    
     state.backend.type: hashmap
     state.checkpoint-storage: jobmanager
     

    This state backend holds the working state in the memory (JVM heap) of the TaskManagers. The state backend checkpoints state directly to the JobManager's memory (hence the backend's name), but the checkpoints will be persisted to a file system for high-availability setups and savepoints. The MemoryStateBackend is consequently a FileSystem-based backend that can work without a file system dependency in simple setups.

    This state backend should be used only for experimentation, quick local setups, or for streaming applications that have very small state: Because it requires checkpoints to go through the JobManager's memory, larger state will occupy larger portions of the JobManager's main memory, reducing operational stability. For any other setup, the FsStateBackend should be used. The FsStateBackend holds the working state on the TaskManagers in the same way, but checkpoints state directly to files rather than to the JobManager's memory, thus supporting large state sizes.

    State Size Considerations

    State checkpointing with this state backend is subject to the following conditions:

    • Each individual state must not exceed the configured maximum state size (see getMaxStateSize().
    • All state from one task (i.e., the sum of all operator states and keyed states from all chained operators of the task) must not exceed what the RPC system supports, which is be default < 10 MB. That limit can be configured up, but that is typically not advised.
    • The sum of all states in the application times all retained checkpoints must comfortably fit into the JobManager's JVM heap space.

    Persistence Guarantees

    For the use cases where the state sizes can be handled by this backend, the backend does guarantee persistence for savepoints, externalized checkpoints (of configured), and checkpoints (when high-availability is configured).

    Configuration

    As for all state backends, this backend can either be configured within the application (by creating the backend with the respective constructor parameters and setting it on the execution environment) or by specifying it in the Flink configuration.

    If the state backend was specified in the application, it may pick up additional configuration parameters from the Flink configuration. For example, if the backend if configured in the application without a default savepoint directory, it will pick up a default savepoint directory specified in the Flink configuration of the running job/cluster. That behavior is implemented via the configure(ReadableConfig, ClassLoader) method.

    See Also:
    Serialized Form
    • Field Detail

      • DEFAULT_MAX_STATE_SIZE

        public static final int DEFAULT_MAX_STATE_SIZE
        Deprecated.
        The default maximal size that the snapshotted memory state may have (5 MiBytes).
        See Also:
        Constant Field Values
    • Constructor Detail

      • MemoryStateBackend

        public MemoryStateBackend()
        Deprecated.
        Creates a new memory state backend that accepts states whose serialized forms are up to the default state size (5 MB).

        Checkpoint and default savepoint locations are used as specified in the runtime configuration.

      • MemoryStateBackend

        public MemoryStateBackend​(boolean asynchronousSnapshots)
        Deprecated.
        Creates a new memory state backend that accepts states whose serialized forms are up to the default state size (5 MB). The state backend uses asynchronous snapshots or synchronous snapshots as configured.

        Checkpoint and default savepoint locations are used as specified in the runtime configuration.

        Parameters:
        asynchronousSnapshots - This parameter is only there for API compatibility. Checkpoints are always asynchronous now.
      • MemoryStateBackend

        public MemoryStateBackend​(int maxStateSize)
        Deprecated.
        Creates a new memory state backend that accepts states whose serialized forms are up to the given number of bytes.

        Checkpoint and default savepoint locations are used as specified in the runtime configuration.

        WARNING: Increasing the size of this value beyond the default value (5242880) should be done with care. The checkpointed state needs to be send to the JobManager via limited size RPC messages, and there and the JobManager needs to be able to hold all aggregated state in its memory.

        Parameters:
        maxStateSize - The maximal size of the serialized state
      • MemoryStateBackend

        public MemoryStateBackend​(int maxStateSize,
                                  boolean asynchronousSnapshots)
        Deprecated.
        Creates a new memory state backend that accepts states whose serialized forms are up to the given number of bytes and that uses asynchronous snashots as configured.

        Checkpoint and default savepoint locations are used as specified in the runtime configuration.

        WARNING: Increasing the size of this value beyond the default value (5242880) should be done with care. The checkpointed state needs to be send to the JobManager via limited size RPC messages, and there and the JobManager needs to be able to hold all aggregated state in its memory.

        Parameters:
        maxStateSize - The maximal size of the serialized state
        asynchronousSnapshots - This parameter is only there for API compatibility. Checkpoints are always asynchronous now.
      • MemoryStateBackend

        public MemoryStateBackend​(@Nullable
                                  String checkpointPath,
                                  @Nullable
                                  String savepointPath)
        Deprecated.
        Creates a new MemoryStateBackend, setting optionally the path to persist checkpoint metadata to, and to persist savepoints to.
        Parameters:
        checkpointPath - The path to write checkpoint metadata to. If null, the value from the runtime configuration will be used.
        savepointPath - The path to write savepoints to. If null, the value from the runtime configuration will be used.
      • MemoryStateBackend

        public MemoryStateBackend​(@Nullable
                                  String checkpointPath,
                                  @Nullable
                                  String savepointPath,
                                  int maxStateSize,
                                  org.apache.flink.util.TernaryBoolean asynchronousSnapshots)
        Deprecated.
        Creates a new MemoryStateBackend, setting optionally the paths to persist checkpoint metadata and savepoints to, as well as configuring state thresholds and asynchronous operations.

        WARNING: Increasing the size of this value beyond the default value (5242880) should be done with care. The checkpointed state needs to be send to the JobManager via limited size RPC messages, and there and the JobManager needs to be able to hold all aggregated state in its memory.

        Parameters:
        checkpointPath - The path to write checkpoint metadata to. If null, the value from the runtime configuration will be used.
        savepointPath - The path to write savepoints to. If null, the value from the runtime configuration will be used.
        maxStateSize - The maximal size of the serialized state.
        asynchronousSnapshots - This parameter is only there for API compatibility. Checkpoints are always asynchronous now.