Class ExecutionConfig

  • All Implemented Interfaces:
    Serializable, Archiveable<ArchivedExecutionConfig>

    @Public
    public class ExecutionConfig
    extends Object
    implements Serializable, Archiveable<ArchivedExecutionConfig>
    A config to define the behavior of the program execution. It allows to define (among other options) the following settings:
    • The default parallelism of the program, i.e., how many parallel tasks to use for all functions that do not define a specific value directly.
    • The number of retries in the case of failed executions.
    • The delay between execution retries.
    • The ExecutionMode of the program: Batch or Pipelined. The default execution mode is ExecutionMode.PIPELINED
    • Enabling or disabling the "closure cleaner". The closure cleaner pre-processes the implementations of functions. In case they are (anonymous) inner classes, it removes unused references to the enclosing class to fix certain serialization-related problems and to reduce the size of the closure.
    • The config allows to register types and serializers to increase the efficiency of handling generic types and POJOs. This is usually only needed when the functions return not only the types declared in their signature, but also subclasses of those types.
    See Also:
    Serialized Form
    • Field Detail

      • PARALLELISM_AUTO_MAX

        @Deprecated
        public static final int PARALLELISM_AUTO_MAX
        Deprecated.
        The constant to use for the parallelism, if the system should use the number of currently available slots.
        See Also:
        Constant Field Values
      • PARALLELISM_DEFAULT

        public static final int PARALLELISM_DEFAULT
        The flag value indicating use of the default parallelism. This value can be used to reset the parallelism back to the default state.
        See Also:
        Constant Field Values
      • PARALLELISM_UNKNOWN

        public static final int PARALLELISM_UNKNOWN
        The flag value indicating an unknown or unset parallelism. This value is not a valid parallelism and indicates that the parallelism should remain unchanged.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ExecutionConfig

        public ExecutionConfig()
    • Method Detail

      • enableClosureCleaner

        public ExecutionConfig enableClosureCleaner()
        Enables the ClosureCleaner. This analyzes user code functions and sets fields to null that are not used. This will in most cases make closures or anonymous inner classes serializable that where not serializable due to some Scala or Java implementation artifact. User code must be serializable because it needs to be sent to worker nodes.
      • isClosureCleanerEnabled

        public boolean isClosureCleanerEnabled()
        Returns whether the ClosureCleaner is enabled.
        See Also:
        enableClosureCleaner()
      • setAutoWatermarkInterval

        @PublicEvolving
        public ExecutionConfig setAutoWatermarkInterval​(long interval)
        Sets the interval of the automatic watermark emission. Watermarks are used throughout the streaming system to keep track of the progress of time. They are used, for example, for time based windowing.

        Setting an interval of 0 will disable periodic watermark emission.

        Parameters:
        interval - The interval between watermarks in milliseconds.
      • getAutoWatermarkInterval

        @PublicEvolving
        public long getAutoWatermarkInterval()
        Returns the interval of the automatic watermark emission.
        See Also:
        setAutoWatermarkInterval(long)
      • setLatencyTrackingInterval

        @PublicEvolving
        public ExecutionConfig setLatencyTrackingInterval​(long interval)
        Interval for sending latency tracking marks from the sources to the sinks. Flink will send latency tracking marks from the sources at the specified interval.

        Setting a tracking interval <= 0 disables the latency tracking.

        Parameters:
        interval - Interval in milliseconds.
      • getLatencyTrackingInterval

        @PublicEvolving
        public long getLatencyTrackingInterval()
        Returns the latency tracking interval.
        Returns:
        The latency tracking interval in milliseconds
      • isLatencyTrackingConfigured

        @Internal
        public boolean isLatencyTrackingConfigured()
      • getPeriodicMaterializeIntervalMillis

        @Internal
        public long getPeriodicMaterializeIntervalMillis()
      • setPeriodicMaterializeIntervalMillis

        @Internal
        public void setPeriodicMaterializeIntervalMillis​(java.time.Duration periodicMaterializeInterval)
      • getMaterializationMaxAllowedFailures

        @Internal
        public int getMaterializationMaxAllowedFailures()
      • setMaterializationMaxAllowedFailures

        @Internal
        public void setMaterializationMaxAllowedFailures​(int materializationMaxAllowedFailures)
      • getParallelism

        public int getParallelism()
        Gets the parallelism with which operation are executed by default. Operations can individually override this value to use a specific parallelism.

        Other operations may need to run with a different parallelism - for example calling a reduce operation over the entire data set will involve an operation that runs with a parallelism of one (the final reduce to the single result value).

        Returns:
        The parallelism used by operations, unless they override that value. This method returns PARALLELISM_DEFAULT if the environment's default parallelism should be used.
      • setParallelism

        public ExecutionConfig setParallelism​(int parallelism)
        Sets the parallelism for operations executed through this environment. Setting a parallelism of x here will cause all operators (such as join, map, reduce) to run with x parallel instances.

        This method overrides the default parallelism for this environment. The local execution environment uses by default a value equal to the number of hardware contexts (CPU cores / threads). When executing the program via the command line client from a JAR file, the default parallelism is the one configured for that setup.

        Parameters:
        parallelism - The parallelism to use
      • resetParallelism

        @Internal
        public void resetParallelism()
      • getMaxParallelism

        @PublicEvolving
        public int getMaxParallelism()
        Gets the maximum degree of parallelism defined for the program.

        The maximum degree of parallelism specifies the upper limit for dynamic scaling. It also defines the number of key groups used for partitioned state.

        Returns:
        Maximum degree of parallelism
      • setMaxParallelism

        @PublicEvolving
        public void setMaxParallelism​(int maxParallelism)
        Sets the maximum degree of parallelism defined for the program.

        The maximum degree of parallelism specifies the upper limit for dynamic scaling. It also defines the number of key groups used for partitioned state.

        Parameters:
        maxParallelism - Maximum degree of parallelism to be used for the program.
      • getTaskCancellationInterval

        public long getTaskCancellationInterval()
        Gets the interval (in milliseconds) between consecutive attempts to cancel a running task.
      • setTaskCancellationInterval

        public ExecutionConfig setTaskCancellationInterval​(long interval)
        Sets the configuration parameter specifying the interval (in milliseconds) between consecutive attempts to cancel a running task.
        Parameters:
        interval - the interval (in milliseconds).
      • getTaskCancellationTimeout

        @PublicEvolving
        public long getTaskCancellationTimeout()
        Returns the timeout (in milliseconds) after which an ongoing task cancellation leads to a fatal TaskManager error.

        The value 0 means that the timeout is disabled. In this case a stuck cancellation will not lead to a fatal error.

      • setTaskCancellationTimeout

        @PublicEvolving
        public ExecutionConfig setTaskCancellationTimeout​(long timeout)
        Sets the timeout (in milliseconds) after which an ongoing task cancellation is considered failed, leading to a fatal TaskManager error.

        The cluster default is configured via TaskManagerOptions.TASK_CANCELLATION_TIMEOUT.

        The value 0 disables the timeout. In this case a stuck cancellation will not lead to a fatal error.

        Parameters:
        timeout - The task cancellation timeout (in milliseconds).
      • setRestartStrategy

        @PublicEvolving
        public void setRestartStrategy​(RestartStrategies.RestartStrategyConfiguration restartStrategyConfiguration)
        Sets the restart strategy to be used for recovery.
        
         ExecutionConfig config = env.getConfig();
        
         config.setRestartStrategy(RestartStrategies.fixedDelayRestart(
         	10,  // number of retries
         	1000 // delay between retries));
         
        Parameters:
        restartStrategyConfiguration - Configuration defining the restart strategy to use
      • getNumberOfExecutionRetries

        @Deprecated
        public int getNumberOfExecutionRetries()
        Deprecated.
        Should no longer be used because it is subsumed by RestartStrategyConfiguration
        Gets the number of times the system will try to re-execute failed tasks. A value of -1 indicates that the system default value (as defined in the configuration) should be used.
        Returns:
        The number of times the system will try to re-execute failed tasks.
      • getExecutionRetryDelay

        @Deprecated
        public long getExecutionRetryDelay()
        Deprecated.
        Should no longer be used because it is subsumed by RestartStrategyConfiguration
        Returns the delay between execution retries.
        Returns:
        The delay between successive execution retries in milliseconds.
      • setExecutionMode

        @Deprecated
        public void setExecutionMode​(ExecutionMode executionMode)
        Deprecated.
        The ExecutionMode is deprecated because it's only used in DataSet APIs. All Flink DataSet APIs are deprecated since Flink 1.18 and will be removed in a future Flink major version. You can still build your application in DataSet, but you should move to either the DataStream and/or Table API.
        Sets the execution mode to execute the program. The execution mode defines whether data exchanges are performed in a batch or on a pipelined manner.

        The default execution mode is ExecutionMode.PIPELINED.

        Parameters:
        executionMode - The execution mode to use.
        See Also:
        FLIP-131: Consolidate the user-facing Dataflow SDKs/APIs (and deprecate the DataSet API
      • setDefaultInputDependencyConstraint

        @PublicEvolving
        @Deprecated
        public void setDefaultInputDependencyConstraint​(InputDependencyConstraint ignored)
        Deprecated.
        due to the deprecation of InputDependencyConstraint.
        This method is deprecated. It was used to set the InputDependencyConstraint utilized by the old scheduler implementations which got removed as part of FLINK-20589. The current implementation has no effect.
        Parameters:
        ignored - Ignored parameter.
      • getDefaultInputDependencyConstraint

        @PublicEvolving
        @Deprecated
        public InputDependencyConstraint getDefaultInputDependencyConstraint()
        Deprecated.
        due to the deprecation of InputDependencyConstraint.
        This method is deprecated. It was used to return the InputDependencyConstraint utilized by the old scheduler implementations. These implementations were removed as part of FLINK-20589.
        Returns:
        The previous default constraint InputDependencyConstraint.ANY.
      • enableForceKryo

        public void enableForceKryo()
        Force TypeExtractor to use Kryo serializer for POJOS even though we could analyze as POJO. In some cases this might be preferable. For example, when using interfaces with subclasses that cannot be analyzed as POJO.
      • disableForceKryo

        public void disableForceKryo()
        Disable use of Kryo serializer for all POJOs.
      • isForceKryoEnabled

        public boolean isForceKryoEnabled()
      • enableGenericTypes

        public void enableGenericTypes()
        Enables the use generic types which are serialized via Kryo.

        Generic types are enabled by default.

        See Also:
        disableGenericTypes()
      • disableGenericTypes

        public void disableGenericTypes()
        Disables the use of generic types (types that would be serialized via Kryo). If this option is used, Flink will throw an UnsupportedOperationException whenever it encounters a data type that would go through Kryo for serialization.

        Disabling generic types can be helpful to eagerly find and eliminate the use of types that would go through Kryo serialization during runtime. Rather than checking types individually, using this option will throw exceptions eagerly in the places where generic types are used.

        Important: We recommend to use this option only during development and pre-production phases, not during actual production use. The application program and/or the input data may be such that new, previously unseen, types occur at some point. In that case, setting this option would cause the program to fail.

        See Also:
        enableGenericTypes()
      • hasGenericTypesDisabled

        public boolean hasGenericTypesDisabled()
        Checks whether generic types are supported. Generic types are types that go through Kryo during serialization.

        Generic types are enabled by default.

        See Also:
        enableGenericTypes(), disableGenericTypes()
      • enableAutoGeneratedUIDs

        public void enableAutoGeneratedUIDs()
        Enables the Flink runtime to auto-generate UID's for operators.
        See Also:
        disableAutoGeneratedUIDs()
      • disableAutoGeneratedUIDs

        public void disableAutoGeneratedUIDs()
        Disables auto-generated UIDs. Forces users to manually specify UIDs on DataStream applications.

        It is highly recommended that users specify UIDs before deploying to production since they are used to match state in savepoints to operators in a job. Because auto-generated ID's are likely to change when modifying a job, specifying custom IDs allow an application to evolve overtime without discarding state.

      • enableForceAvro

        public void enableForceAvro()
        Forces Flink to use the Apache Avro serializer for POJOs.

        Important: Make sure to include the flink-avro module.

      • disableForceAvro

        public void disableForceAvro()
        Disables the Apache Avro serializer as the forced serializer for POJOs.
      • isForceAvroEnabled

        public boolean isForceAvroEnabled()
        Returns whether the Apache Avro is the default serializer for POJOs.
      • enableObjectReuse

        public ExecutionConfig enableObjectReuse()
        Enables reusing objects that Flink internally uses for deserialization and passing data to user-code functions. Keep in mind that this can lead to bugs when the user-code function of an operation is not aware of this behaviour.
      • disableObjectReuse

        public ExecutionConfig disableObjectReuse()
        Disables reusing objects that Flink internally uses for deserialization and passing data to user-code functions. @see #enableObjectReuse()
      • isObjectReuseEnabled

        public boolean isObjectReuseEnabled()
        Returns whether object reuse has been enabled or disabled. @see #enableObjectReuse()
      • setGlobalJobParameters

        public void setGlobalJobParameters​(ExecutionConfig.GlobalJobParameters globalJobParameters)
        Register a custom, serializable user configuration object.
        Parameters:
        globalJobParameters - Custom user configuration object
      • addDefaultKryoSerializer

        public <T extends com.esotericsoftware.kryo.Serializer<?> & Serializable> void addDefaultKryoSerializer​(Class<?> type,
                                                                                                                T serializer)
        Adds a new Kryo default serializer to the Runtime.

        Note that the serializer instance must be serializable (as defined by java.io.Serializable), because it may be distributed to the worker nodes by java serialization.

        Parameters:
        type - The class of the types serialized with the given serializer.
        serializer - The serializer to use.
      • addDefaultKryoSerializer

        public void addDefaultKryoSerializer​(Class<?> type,
                                             Class<? extends com.esotericsoftware.kryo.Serializer<?>> serializerClass)
        Adds a new Kryo default serializer to the Runtime.
        Parameters:
        type - The class of the types serialized with the given serializer.
        serializerClass - The class of the serializer to use.
      • registerTypeWithKryoSerializer

        public <T extends com.esotericsoftware.kryo.Serializer<?> & Serializable> void registerTypeWithKryoSerializer​(Class<?> type,
                                                                                                                      T serializer)
        Registers the given type with a Kryo Serializer.

        Note that the serializer instance must be serializable (as defined by java.io.Serializable), because it may be distributed to the worker nodes by java serialization.

        Parameters:
        type - The class of the types serialized with the given serializer.
        serializer - The serializer to use.
      • registerTypeWithKryoSerializer

        public void registerTypeWithKryoSerializer​(Class<?> type,
                                                   Class<? extends com.esotericsoftware.kryo.Serializer> serializerClass)
        Registers the given Serializer via its class as a serializer for the given type at the KryoSerializer
        Parameters:
        type - The class of the types serialized with the given serializer.
        serializerClass - The class of the serializer to use.
      • registerPojoType

        public void registerPojoType​(Class<?> type)
        Registers the given type with the serialization stack. If the type is eventually serialized as a POJO, then the type is registered with the POJO serializer. If the type ends up being serialized with Kryo, then it will be registered at Kryo to make sure that only tags are written.
        Parameters:
        type - The class of the type to register.
      • registerKryoType

        public void registerKryoType​(Class<?> type)
        Registers the given type with the serialization stack. If the type is eventually serialized as a POJO, then the type is registered with the POJO serializer. If the type ends up being serialized with Kryo, then it will be registered at Kryo to make sure that only tags are written.
        Parameters:
        type - The class of the type to register.
      • getRegisteredTypesWithKryoSerializerClasses

        public LinkedHashMap<Class<?>,​Class<? extends com.esotericsoftware.kryo.Serializer<?>>> getRegisteredTypesWithKryoSerializerClasses()
        Returns the registered types with their Kryo Serializer classes.
      • getDefaultKryoSerializerClasses

        public LinkedHashMap<Class<?>,​Class<? extends com.esotericsoftware.kryo.Serializer<?>>> getDefaultKryoSerializerClasses()
        Returns the registered default Kryo Serializer classes.
      • getRegisteredKryoTypes

        public LinkedHashSet<Class<?>> getRegisteredKryoTypes()
        Returns the registered Kryo types.
      • getRegisteredPojoTypes

        public LinkedHashSet<Class<?>> getRegisteredPojoTypes()
        Returns the registered POJO types.
      • isAutoTypeRegistrationDisabled

        @Deprecated
        public boolean isAutoTypeRegistrationDisabled()
        Deprecated.
        The method is deprecated because it's only used in DataSet API. All Flink DataSet APIs are deprecated since Flink 1.18 and will be removed in a future Flink major version. You can still build your application in DataSet, but you should move to either the DataStream and/or Table API.
        Get if the auto type registration is disabled.
        Returns:
        if the auto type registration is disabled.
        See Also:
        FLIP-131: Consolidate the user-facing Dataflow SDKs/APIs (and deprecate the DataSet API
      • disableAutoTypeRegistration

        @Deprecated
        public void disableAutoTypeRegistration()
        Deprecated.
        The method is deprecated because it's only used in DataSet API. All Flink DataSet APIs are deprecated since Flink 1.18 and will be removed in a future Flink major version. You can still build your application in DataSet, but you should move to either the DataStream and/or Table API.
        Control whether Flink is automatically registering all types in the user programs with Kryo.
        See Also:
        FLIP-131: Consolidate the user-facing Dataflow SDKs/APIs (and deprecate the DataSet API
      • isUseSnapshotCompression

        public boolean isUseSnapshotCompression()
      • setUseSnapshotCompression

        public void setUseSnapshotCompression​(boolean useSnapshotCompression)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • canEqual

        @Deprecated
        public boolean canEqual​(Object obj)
        Deprecated.
        It is not intended to be used by users.
        This method simply checks whether the object is an ExecutionConfig instance.
      • configure

        public void configure​(ReadableConfig configuration,
                              ClassLoader classLoader)
        Sets all relevant options contained in the ReadableConfig such as e.g. PipelineOptions.CLOSURE_CLEANER_LEVEL.

        It will change the value of a setting only if a corresponding option was set in the configuration. If a key is not present, the current value of a field will remain untouched.

        Parameters:
        configuration - a configuration to read the values from
        classLoader - a class loader to use when loading classes
      • toConfiguration

        @Internal
        public Configuration toConfiguration()
        Returns:
        A copy of internal configuration. Note it is missing all options that are stored as plain java fields in ExecutionConfig, for example registeredKryoTypes or globalJobParameters.