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, getPartitionIdequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitinitializeLogging, initializeLogIfNecessary, initializeLogIfNecessary, isTraceEnabled, log_, log, logDebug, logDebug, logError, logError, logInfo, logInfo, logName, logTrace, logTrace, logWarning, logWarningpublic 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()
TaskContextisCompleted in class TaskContextpublic boolean isInterrupted()
TaskContextisInterrupted in class TaskContextpublic boolean isRunningLocally()
TaskContextisRunningLocally in class TaskContextpublic BarrierTaskContext addTaskCompletionListener(TaskCompletionListener listener)
TaskContextAn 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 TaskContextlistener - (undocumented)public BarrierTaskContext addTaskFailureListener(TaskFailureListener listener)
TaskContextaddTaskFailureListener in class TaskContextlistener - (undocumented)public int stageId()
TaskContextstageId in class TaskContextpublic int stageAttemptNumber()
TaskContextstageAttemptNumber in class TaskContextpublic int partitionId()
TaskContextpartitionId in class TaskContextpublic int attemptNumber()
TaskContextattemptNumber in class TaskContextpublic long taskAttemptId()
TaskContexttaskAttemptId in class TaskContextpublic String getLocalProperty(String key)
TaskContextorg.apache.spark.SparkContext.setLocalProperty.getLocalProperty in class TaskContextkey - (undocumented)public org.apache.spark.executor.TaskMetrics taskMetrics()
taskMetrics in class TaskContextpublic scala.collection.Seq<org.apache.spark.metrics.source.Source> getMetricsSources(String sourceName)
TaskContextorg.apache.spark.metrics.MetricsSystem.getMetricsSources in class TaskContextsourceName - (undocumented)