public class BarrierTaskContext extends TaskContext implements Logging
TaskContext
with extra contextual info and tooling for tasks in a barrier stage.
Use get()
to obtain the barrier context for a running barrier task.Modifier and Type | Method and Description |
---|---|
BarrierTaskContext |
addTaskCompletionListener(TaskCompletionListener listener)
Adds a (Java friendly) listener to be executed on task completion.
|
BarrierTaskContext |
addTaskFailureListener(TaskFailureListener listener)
Adds a listener to be executed on task failure.
|
int |
attemptNumber()
How many times this task has been attempted.
|
void |
barrier()
:: Experimental ::
Sets a global barrier and waits until all tasks in this stage hit this barrier.
|
static BarrierTaskContext |
get()
:: Experimental ::
Returns the currently active BarrierTaskContext.
|
String |
getLocalProperty(String key)
Get a local property set upstream in the driver, or null if it is missing.
|
scala.collection.Seq<org.apache.spark.metrics.source.Source> |
getMetricsSources(String sourceName)
::DeveloperApi::
Returns all metrics sources with the given name which are associated with the instance
which runs the task.
|
BarrierTaskInfo[] |
getTaskInfos()
:: Experimental ::
Returns
BarrierTaskInfo for all tasks in this barrier stage, ordered by partition ID. |
boolean |
isCompleted()
Returns true if the task has completed.
|
boolean |
isInterrupted()
Returns true if the task has been killed.
|
boolean |
isRunningLocally()
Returns true if the task is running locally in the driver program.
|
int |
partitionId()
The ID of the RDD partition that is computed by this task.
|
int |
stageAttemptNumber()
How many times the stage that this task belongs to has been attempted.
|
int |
stageId()
The ID of the stage that this task belong to.
|
long |
taskAttemptId()
An ID that is unique to this task attempt (within the same SparkContext, no two task attempts
will share the same attempt ID).
|
org.apache.spark.executor.TaskMetrics |
taskMetrics() |
addTaskCompletionListener, addTaskFailureListener, getPartitionId
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
initializeLogging, initializeLogIfNecessary, initializeLogIfNecessary, isTraceEnabled, log_, log, logDebug, logDebug, logError, logError, logInfo, logInfo, logName, logTrace, logTrace, logWarning, logWarning
public static BarrierTaskContext get()
public void barrier()
CAUTION! In a barrier stage, each task must have the same number of barrier() calls, in all possible code branches. Otherwise, you may get the job hanging or a SparkException after timeout. Some examples of '''misuses''' are listed below: 1. Only call barrier() function on a subset of all the tasks in the same barrier stage, it shall lead to timeout of the function call.
rdd.barrier().mapPartitions { iter =>
val context = BarrierTaskContext.get()
if (context.partitionId() == 0) {
// Do nothing.
} else {
context.barrier()
}
iter
}
2. Include barrier() function in a try-catch code block, this may lead to timeout of the second function call.
rdd.barrier().mapPartitions { iter =>
val context = BarrierTaskContext.get()
try {
// Do something that might throw an Exception.
doSomething()
context.barrier()
} catch {
case e: Exception => logWarning("...", e)
}
context.barrier()
iter
}
public BarrierTaskInfo[] getTaskInfos()
BarrierTaskInfo
for all tasks in this barrier stage, ordered by partition ID.public boolean isCompleted()
TaskContext
isCompleted
in class TaskContext
public boolean isInterrupted()
TaskContext
isInterrupted
in class TaskContext
public boolean isRunningLocally()
TaskContext
isRunningLocally
in class TaskContext
public BarrierTaskContext addTaskCompletionListener(TaskCompletionListener listener)
TaskContext
An example use is for HadoopRDD to register a callback to close the input stream.
Exceptions thrown by the listener will result in failure of the task.
addTaskCompletionListener
in class TaskContext
listener
- (undocumented)public BarrierTaskContext addTaskFailureListener(TaskFailureListener listener)
TaskContext
addTaskFailureListener
in class TaskContext
listener
- (undocumented)public int stageId()
TaskContext
stageId
in class TaskContext
public int stageAttemptNumber()
TaskContext
stageAttemptNumber
in class TaskContext
public int partitionId()
TaskContext
partitionId
in class TaskContext
public int attemptNumber()
TaskContext
attemptNumber
in class TaskContext
public long taskAttemptId()
TaskContext
taskAttemptId
in class TaskContext
public String getLocalProperty(String key)
TaskContext
org.apache.spark.SparkContext.setLocalProperty
.getLocalProperty
in class TaskContext
key
- (undocumented)public org.apache.spark.executor.TaskMetrics taskMetrics()
taskMetrics
in class TaskContext
public scala.collection.Seq<org.apache.spark.metrics.source.Source> getMetricsSources(String sourceName)
TaskContext
org.apache.spark.metrics.MetricsSystem
.getMetricsSources
in class TaskContext
sourceName
- (undocumented)