OUT
- OP
- @Internal public abstract class StreamTask<OUT,OP extends StreamOperator<OUT>> extends org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable implements AsyncExceptionHandler
StreamOperator
s which form
the Task's operator chain. Operators that are chained together execute synchronously in the
same thread and hence on the same stream partition. A common case for these chains
are successive map/flatmap/filter tasks.
The task chain contains one "head" operator and multiple chained operators. The StreamTask is specialized for the type of the head operator: one-input and two-input tasks, as well as for sources, iteration heads and iteration tails.
The Task class deals with the setup of the streams read by the head operator, and the streams produced by the operators at the ends of the operator chain. Note that the chain may fork and thus have multiple ends.
The life cycle of the task is set up as follows:
-- setInitialState -> provides state of all operators in the chain
-- invoke()
|
+----> Create basic utils (config, etc) and load the chain of operators
+----> operators.setup()
+----> task specific init()
+----> initialize-operator-states()
+----> open-operators()
+----> run()
+----> close-operators()
+----> dispose-operators()
+----> common cleanup
+----> task specific cleanup()
The StreamTask
has a lock object called lock
. All calls to methods on a
StreamOperator
must be synchronized on this lock object to ensure that no methods
are called concurrently.
Modifier and Type | Class and Description |
---|---|
class |
StreamTask.ActionContext
The action context is passed as parameter into the default action method and holds control methods for feedback
of from the default action to the mailbox.
|
protected static class |
StreamTask.AsyncCheckpointRunnable
This runnable executes the asynchronous parts of all involved backend snapshots for the subtask.
|
Modifier and Type | Field and Description |
---|---|
protected StreamConfig |
configuration
The configuration of this streaming task.
|
protected OP |
headOperator
the head operator that consumes the input streams of this task.
|
protected StreamInputProcessor |
inputProcessor
The input processor.
|
protected Mailbox |
mailbox |
protected OperatorChain<OUT,OP> |
operatorChain
The chain of operators executed by this task.
|
protected org.apache.flink.runtime.state.StateBackend |
stateBackend
Our state backend.
|
protected ProcessingTimeService |
timerService
The internal
ProcessingTimeService used to define the current
processing time (default = System.currentTimeMillis() ) and
register timers for tasks to be executed in the future. |
static ThreadGroup |
TRIGGER_THREAD_GROUP
The thread group that holds all trigger timer threads.
|
Modifier | Constructor and Description |
---|---|
protected |
StreamTask(org.apache.flink.runtime.execution.Environment env)
Constructor for initialization, possibly with initial state (recovery / savepoint / etc).
|
protected |
StreamTask(org.apache.flink.runtime.execution.Environment env,
ProcessingTimeService timeProvider)
Constructor for initialization, possibly with initial state (recovery / savepoint / etc).
|
protected |
StreamTask(org.apache.flink.runtime.execution.Environment environment,
ProcessingTimeService timeProvider,
Thread.UncaughtExceptionHandler uncaughtExceptionHandler)
Constructor for initialization, possibly with initial state (recovery / savepoint / etc).
|
Modifier and Type | Method and Description |
---|---|
void |
abortCheckpointOnBarrier(long checkpointId,
Throwable cause) |
protected void |
advanceToEndOfEventTime()
Emits the
MAX_WATERMARK
so that all registered timers are fired. |
void |
cancel() |
protected void |
cancelTask() |
protected void |
cleanup() |
protected CheckpointExceptionHandlerFactory |
createCheckpointExceptionHandlerFactory() |
static <OUT> List<org.apache.flink.runtime.io.network.api.writer.RecordWriter<org.apache.flink.runtime.plugable.SerializationDelegate<StreamRecord<OUT>>>> |
createRecordWriters(StreamConfig configuration,
org.apache.flink.runtime.execution.Environment environment) |
StreamTaskStateInitializer |
createStreamTaskStateInitializer() |
protected void |
finalize()
The finalize method shuts down the timer.
|
protected void |
finishTask()
Instructs the task to go through its normal termination routine, i.e.
|
Map<String,org.apache.flink.api.common.accumulators.Accumulator<?,?>> |
getAccumulatorMap() |
ExecutorService |
getAsyncOperationsThreadPool() |
org.apache.flink.core.fs.CloseableRegistry |
getCancelables() |
Object |
getCheckpointLock()
Gets the lock object on which all operations that involve data and state mutation have to lock.
|
org.apache.flink.runtime.state.CheckpointStorageWorkerView |
getCheckpointStorage() |
StreamConfig |
getConfiguration() |
String |
getName()
Gets the name of the task, in the form "taskname (2/5)".
|
ProcessingTimeService |
getProcessingTimeService()
Returns the
ProcessingTimeService responsible for telling the current
processing time and registering timers. |
StreamStatusMaintainer |
getStreamStatusMaintainer() |
void |
handleAsyncException(String message,
Throwable exception)
Handles an exception thrown by another thread (e.g.
|
protected abstract void |
init() |
void |
invoke() |
boolean |
isCanceled() |
boolean |
isRunning() |
void |
notifyCheckpointComplete(long checkpointId) |
protected void |
processInput(StreamTask.ActionContext context)
This method implements the default action of the task (e.g.
|
String |
toString() |
boolean |
triggerCheckpoint(org.apache.flink.runtime.checkpoint.CheckpointMetaData checkpointMetaData,
org.apache.flink.runtime.checkpoint.CheckpointOptions checkpointOptions,
boolean advanceToEndOfEventTime) |
void |
triggerCheckpointOnBarrier(org.apache.flink.runtime.checkpoint.CheckpointMetaData checkpointMetaData,
org.apache.flink.runtime.checkpoint.CheckpointOptions checkpointOptions,
org.apache.flink.runtime.checkpoint.CheckpointMetrics checkpointMetrics) |
getCurrentNumberOfSubtasks, getEnvironment, getExecutingThread, getExecutionConfig, getIndexInSubtaskGroup, getJobConfiguration, getTaskConfiguration, getUserCodeClassLoader, setShouldInterruptOnCancel, shouldInterruptOnCancel
public static final ThreadGroup TRIGGER_THREAD_GROUP
@Nullable protected StreamInputProcessor inputProcessor
init()
method.protected OP extends StreamOperator<OUT> headOperator
protected OperatorChain<OUT,OP extends StreamOperator<OUT>> operatorChain
protected final StreamConfig configuration
protected org.apache.flink.runtime.state.StateBackend stateBackend
protected ProcessingTimeService timerService
ProcessingTimeService
used to define the current
processing time (default = System.currentTimeMillis()
) and
register timers for tasks to be executed in the future.protected final Mailbox mailbox
protected StreamTask(org.apache.flink.runtime.execution.Environment env)
env
- The task environment for this task.protected StreamTask(org.apache.flink.runtime.execution.Environment env, @Nullable ProcessingTimeService timeProvider)
env
- The task environment for this task.timeProvider
- Optionally, a specific time provider to use.protected StreamTask(org.apache.flink.runtime.execution.Environment environment, @Nullable ProcessingTimeService timeProvider, Thread.UncaughtExceptionHandler uncaughtExceptionHandler)
This constructor accepts a special ProcessingTimeService
. By default (and if
null is passes for the time provider) a DefaultTimerService
will be used.
environment
- The task environment for this task.timeProvider
- Optionally, a specific time provider to use.uncaughtExceptionHandler
- to handle uncaught exceptions in the async operations thread poolprotected void processInput(StreamTask.ActionContext context) throws Exception
context
- context object for collaborative interaction between the action and the stream task.Exception
- on any problems in the action.protected void advanceToEndOfEventTime() throws Exception
MAX_WATERMARK
so that all registered timers are fired.
This is used by the source task when the job is TERMINATED
. In the case,
we want all the timers registered throughout the pipeline to fire and the related
state (e.g. windows) to be flushed.
For tasks other than the source task, this method does nothing.
Exception
protected void finishTask() throws Exception
StreamOperator.close()
and StreamOperator.dispose()
on its operators.
This is used by the source task to get out of the run-loop when the job is stoppped with a savepoint.
For tasks other than the source task, this method does nothing.
Exception
public StreamTaskStateInitializer createStreamTaskStateInitializer()
public final void invoke() throws Exception
invoke
in class org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable
Exception
public final void cancel() throws Exception
cancel
in class org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable
Exception
public final boolean isRunning()
public final boolean isCanceled()
protected void finalize() throws Throwable
This should not be relied upon! It will cause shutdown to happen much later than if manual shutdown is attempted, and cause threads to linger for longer than needed.
public String getName()
public Object getCheckpointLock()
public org.apache.flink.runtime.state.CheckpointStorageWorkerView getCheckpointStorage()
public StreamConfig getConfiguration()
public Map<String,org.apache.flink.api.common.accumulators.Accumulator<?,?>> getAccumulatorMap()
public StreamStatusMaintainer getStreamStatusMaintainer()
public boolean triggerCheckpoint(org.apache.flink.runtime.checkpoint.CheckpointMetaData checkpointMetaData, org.apache.flink.runtime.checkpoint.CheckpointOptions checkpointOptions, boolean advanceToEndOfEventTime) throws Exception
triggerCheckpoint
in class org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable
Exception
public void triggerCheckpointOnBarrier(org.apache.flink.runtime.checkpoint.CheckpointMetaData checkpointMetaData, org.apache.flink.runtime.checkpoint.CheckpointOptions checkpointOptions, org.apache.flink.runtime.checkpoint.CheckpointMetrics checkpointMetrics) throws Exception
triggerCheckpointOnBarrier
in class org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable
Exception
public void abortCheckpointOnBarrier(long checkpointId, Throwable cause) throws Exception
abortCheckpointOnBarrier
in class org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable
Exception
public ExecutorService getAsyncOperationsThreadPool()
public void notifyCheckpointComplete(long checkpointId) throws Exception
notifyCheckpointComplete
in class org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable
Exception
protected CheckpointExceptionHandlerFactory createCheckpointExceptionHandlerFactory()
public ProcessingTimeService getProcessingTimeService()
ProcessingTimeService
responsible for telling the current
processing time and registering timers.public void handleAsyncException(String message, Throwable exception)
In more detail, it marks task execution failed for an external reason (a reason other than the task code itself throwing an exception). If the task is already in a terminal state (such as FINISHED, CANCELED, FAILED), or if the task is already canceling this does nothing. Otherwise it sets the state to FAILED, and, if the invokable code is running, starts an asynchronous thread that aborts that code.
This method never blocks.
handleAsyncException
in interface AsyncExceptionHandler
public org.apache.flink.core.fs.CloseableRegistry getCancelables()
@VisibleForTesting public static <OUT> List<org.apache.flink.runtime.io.network.api.writer.RecordWriter<org.apache.flink.runtime.plugable.SerializationDelegate<StreamRecord<OUT>>>> createRecordWriters(StreamConfig configuration, org.apache.flink.runtime.execution.Environment environment)
Copyright © 2014–2019 The Apache Software Foundation. All rights reserved.