Class TaskStateSnapshot
- java.lang.Object
-
- org.apache.flink.runtime.checkpoint.TaskStateSnapshot
-
- All Implemented Interfaces:
Serializable,CompositeStateHandle,StateObject
public class TaskStateSnapshot extends Object implements CompositeStateHandle
This class encapsulates state handles to the snapshots of all operator instances executed within one task. A task can run multiple operator instances as a result of operator chaining, and all operator instances from the chain can register their state under their operator id. Each operator instance is a physical execution responsible for processing a partition of the data that goes through a logical operator. This partitioning happens to parallelize execution of logical operators, e.g. distributing a map function.One instance of this class contains the information that one task will send to acknowledge a checkpoint request by the checkpoint coordinator. Tasks run operator instances in parallel, so the union of all
TaskStateSnapshotthat are collected by the checkpoint coordinator from all tasks represent the whole state of a job at the time of the checkpoint.This class should be called TaskState once the old class with this name that we keep for backwards compatibility goes away.
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.flink.runtime.state.StateObject
StateObject.StateObjectLocation, StateObject.StateObjectSizeStatsCollector
-
-
Field Summary
Fields Modifier and Type Field Description static TaskStateSnapshotFINISHED_ON_RESTORE
-
Constructor Summary
Constructors Constructor Description TaskStateSnapshot()TaskStateSnapshot(int size, boolean isTaskFinished)TaskStateSnapshot(Map<OperatorID,OperatorSubtaskState> subtaskStatesByOperatorID)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcollectSizeStats(StateObject.StateObjectSizeStatsCollector collector)Collects statistics about state size and location from the state object.static TaskStateSnapshotdeserializeTaskStateSnapshot(org.apache.flink.util.SerializedValue<TaskStateSnapshot> subtaskState, ClassLoader classLoader)voiddiscardState()Discards the state referred to and solemnly owned by this handle, to free up resources in the persistent storage.booleanequals(Object o)longgetCheckpointedSize()Returns the persisted data size during checkpoint execution in bytes.InflightDataRescalingDescriptorgetInputRescalingDescriptor()Returns the input channel mapping for rescaling with in-flight data orInflightDataRescalingDescriptor.NO_RESCALE.InflightDataRescalingDescriptorgetOutputRescalingDescriptor()Returns the output channel mapping for rescaling with in-flight data orInflightDataRescalingDescriptor.NO_RESCALE.longgetStateSize()Returns the size of the state in bytes.OperatorSubtaskStategetSubtaskStateByOperatorID(OperatorID operatorID)Returns the subtask state for the given operator id (or null if not contained).Set<Map.Entry<OperatorID,OperatorSubtaskState>>getSubtaskStateMappings()Returns the set of all mappings from operator id to the corresponding subtask state.inthashCode()booleanhasState()Returns true if at least oneOperatorSubtaskStatein subtaskStatesByOperatorID has state.booleanisTaskDeployedAsFinished()Returns whether all the operators of the task are already finished on restoring.booleanisTaskFinished()Returns whether all the operators of the task have called finished methods.OperatorSubtaskStateputSubtaskStateByOperatorID(OperatorID operatorID, OperatorSubtaskState state)Maps the given operator id to the given subtask state.voidregisterSharedStates(SharedStateRegistry stateRegistry, long checkpointID)Register both newly created and already referenced shared states in the givenSharedStateRegistry.static org.apache.flink.util.SerializedValue<TaskStateSnapshot>serializeTaskStateSnapshot(TaskStateSnapshot subtaskState)StringtoString()
-
-
-
Field Detail
-
FINISHED_ON_RESTORE
public static final TaskStateSnapshot FINISHED_ON_RESTORE
-
-
Constructor Detail
-
TaskStateSnapshot
public TaskStateSnapshot()
-
TaskStateSnapshot
public TaskStateSnapshot(int size, boolean isTaskFinished)
-
TaskStateSnapshot
public TaskStateSnapshot(Map<OperatorID,OperatorSubtaskState> subtaskStatesByOperatorID)
-
-
Method Detail
-
isTaskDeployedAsFinished
public boolean isTaskDeployedAsFinished()
Returns whether all the operators of the task are already finished on restoring.
-
isTaskFinished
public boolean isTaskFinished()
Returns whether all the operators of the task have called finished methods.
-
getSubtaskStateByOperatorID
@Nullable public OperatorSubtaskState getSubtaskStateByOperatorID(OperatorID operatorID)
Returns the subtask state for the given operator id (or null if not contained).
-
putSubtaskStateByOperatorID
public OperatorSubtaskState putSubtaskStateByOperatorID(@Nonnull OperatorID operatorID, @Nonnull OperatorSubtaskState state)
Maps the given operator id to the given subtask state. Returns the subtask state of a previous mapping, if such a mapping existed or null otherwise.
-
getSubtaskStateMappings
public Set<Map.Entry<OperatorID,OperatorSubtaskState>> getSubtaskStateMappings()
Returns the set of all mappings from operator id to the corresponding subtask state.
-
hasState
public boolean hasState()
Returns true if at least oneOperatorSubtaskStatein subtaskStatesByOperatorID has state.
-
getInputRescalingDescriptor
public InflightDataRescalingDescriptor getInputRescalingDescriptor()
Returns the input channel mapping for rescaling with in-flight data orInflightDataRescalingDescriptor.NO_RESCALE.
-
getOutputRescalingDescriptor
public InflightDataRescalingDescriptor getOutputRescalingDescriptor()
Returns the output channel mapping for rescaling with in-flight data orInflightDataRescalingDescriptor.NO_RESCALE.
-
discardState
public void discardState() throws ExceptionDescription copied from interface:StateObjectDiscards the state referred to and solemnly owned by this handle, to free up resources in the persistent storage. This method is called when the state represented by this object will not be used anymore.- Specified by:
discardStatein interfaceStateObject- Throws:
Exception
-
getStateSize
public long getStateSize()
Description copied from interface:StateObjectReturns the size of the state in bytes. If the size is not known, this method should return0.The values produced by this method are only used for informational purposes and for metrics/monitoring. If this method returns wrong values, the checkpoints and recovery will still behave correctly. However, efficiency may be impacted (wrong space pre-allocation) and functionality that depends on metrics (like monitoring) will be impacted.
Note for implementors: This method should not perform any I/O operations while obtaining the state size (hence it does not declare throwing an
IOException). Instead, the state size should be stored in the state object, or should be computable from the state stored in this object. The reason is that this method is called frequently by several parts of the checkpointing and issuing I/O requests from this method accumulates a heavy I/O load on the storage system at higher scale.- Specified by:
getStateSizein interfaceStateObject- Returns:
- Size of the state in bytes.
-
collectSizeStats
public void collectSizeStats(StateObject.StateObjectSizeStatsCollector collector)
Description copied from interface:StateObjectCollects statistics about state size and location from the state object.- Specified by:
collectSizeStatsin interfaceStateObject- Parameters:
collector- the statistics collector.
-
getCheckpointedSize
public long getCheckpointedSize()
Description copied from interface:CompositeStateHandleReturns the persisted data size during checkpoint execution in bytes. If incremental checkpoint is enabled, this value represents the incremental persisted data size, and usually smaller thanStateObject.getStateSize(). If the size is unknown, this method would return same result asStateObject.getStateSize().- Specified by:
getCheckpointedSizein interfaceCompositeStateHandle- Returns:
- The persisted data size during checkpoint execution in bytes.
-
registerSharedStates
public void registerSharedStates(SharedStateRegistry stateRegistry, long checkpointID)
Description copied from interface:CompositeStateHandleRegister both newly created and already referenced shared states in the givenSharedStateRegistry. This method is called when the checkpoint successfully completes or is recovered from failures.After this is completed, newly created shared state is considered as published is no longer owned by this handle. This means that it should no longer be deleted as part of calls to
StateObject.discardState(). Instead,StateObject.discardState()will trigger an unregistration from the registry.- Specified by:
registerSharedStatesin interfaceCompositeStateHandle- Parameters:
stateRegistry- The registry where shared states are registered.
-
serializeTaskStateSnapshot
@Nullable public static org.apache.flink.util.SerializedValue<TaskStateSnapshot> serializeTaskStateSnapshot(TaskStateSnapshot subtaskState)
-
deserializeTaskStateSnapshot
@Nullable public static TaskStateSnapshot deserializeTaskStateSnapshot(org.apache.flink.util.SerializedValue<TaskStateSnapshot> subtaskState, ClassLoader classLoader)
-
-